| 147 | } |
| 148 | |
| 149 | void StructArray::getFieldNames(libmexclass::proxy::method::Context& context) { |
| 150 | namespace mda = ::matlab::data; |
| 151 | |
| 152 | const auto& fields = array->type()->fields(); |
| 153 | const auto num_fields = fields.size(); |
| 154 | std::vector<mda::MATLABString> names; |
| 155 | names.reserve(num_fields); |
| 156 | |
| 157 | for (size_t i = 0; i < num_fields; ++i) { |
| 158 | auto str_utf8 = fields[i]->name(); |
| 159 | |
| 160 | // MATLAB strings are UTF-16 encoded. Must convert UTF-8 |
| 161 | // encoded field names before returning to MATLAB. |
| 162 | MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto str_utf16, |
| 163 | arrow::util::UTF8StringToUTF16(str_utf8), context, |
| 164 | error::UNICODE_CONVERSION_ERROR_ID); |
| 165 | const mda::MATLABString matlab_string = mda::MATLABString(std::move(str_utf16)); |
| 166 | names.push_back(matlab_string); |
| 167 | } |
| 168 | |
| 169 | mda::ArrayFactory factory; |
| 170 | context.outputs[0] = factory.createArray({1, num_fields}, names.begin(), names.end()); |
| 171 | } |
| 172 | } // namespace arrow::matlab::array::proxy |