MCPcopy Create free account
hub / github.com/apache/arrow / toMATLAB

Method toMATLAB

matlab/src/cpp/arrow/matlab/array/proxy/string_array.cc:71–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71void StringArray::toMATLAB(libmexclass::proxy::method::Context& context) {
72 namespace mda = ::matlab::data;
73
74 // Convert UTF-8 encoded Arrow string values to UTF-16 encoded MATLAB string values.
75 auto array_length = static_cast<size_t>(array->length());
76 std::vector<mda::MATLABString> strings;
77 strings.reserve(array_length);
78 for (size_t i = 0; i < array_length; ++i) {
79 auto string_array = std::static_pointer_cast<arrow::StringArray>(array);
80 auto str_utf8 = string_array->GetView(i);
81 MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto str_utf16,
82 arrow::util::UTF8StringToUTF16(str_utf8), context,
83 error::UNICODE_CONVERSION_ERROR_ID);
84 const mda::MATLABString matlab_string = mda::MATLABString(std::move(str_utf16));
85 strings.push_back(matlab_string);
86 }
87
88 // Create a MATLAB String array from a vector of UTF-16 encoded strings.
89 mda::ArrayFactory factory;
90 auto array_mda = factory.createArray({array_length, 1}, strings.begin(), strings.end());
91 context.outputs[0] = array_mda;
92}
93} // namespace arrow::matlab::array::proxy

Callers

nothing calls this directly

Calls 6

push_backMethod · 0.80
lengthMethod · 0.45
reserveMethod · 0.45
GetViewMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected