| 33 | } |
| 34 | |
| 35 | libmexclass::proxy::MakeResult StringArray::make( |
| 36 | const libmexclass::proxy::FunctionArguments& constructor_arguments) { |
| 37 | namespace mda = ::matlab::data; |
| 38 | |
| 39 | mda::StructArray opts = constructor_arguments[0]; |
| 40 | const mda::StringArray array_mda = opts[0]["MatlabArray"]; |
| 41 | const mda::TypedArray<bool> unpacked_validity_bitmap_mda = opts[0]["Valid"]; |
| 42 | |
| 43 | // Convert UTF-16 encoded MATLAB string values to UTF-8 encoded Arrow string values. |
| 44 | const auto array_length = array_mda.getNumberOfElements(); |
| 45 | std::vector<std::string> strings; |
| 46 | strings.reserve(array_length); |
| 47 | for (const auto& str : array_mda) { |
| 48 | if (!str) { |
| 49 | // Substitute MATLAB string(missing) values with the empty string value ("") |
| 50 | strings.emplace_back(""); |
| 51 | } else { |
| 52 | MATLAB_ASSIGN_OR_ERROR(auto str_utf8, arrow::util::UTF16StringToUTF8(*str), |
| 53 | error::UNICODE_CONVERSION_ERROR_ID); |
| 54 | strings.push_back(std::move(str_utf8)); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | auto unpacked_validity_bitmap_ptr = bit::extract_ptr(unpacked_validity_bitmap_mda); |
| 59 | |
| 60 | // Build up an Arrow StringArray from a vector of UTF-8 encoded strings. |
| 61 | arrow::StringBuilder builder; |
| 62 | MATLAB_ERROR_IF_NOT_OK(builder.AppendValues(strings, unpacked_validity_bitmap_ptr), |
| 63 | error::STRING_BUILDER_APPEND_FAILED); |
| 64 | MATLAB_ASSIGN_OR_ERROR(auto array, builder.Finish(), |
| 65 | error::STRING_BUILDER_FINISH_FAILED); |
| 66 | auto typed_array = std::static_pointer_cast<arrow::StringArray>(array); |
| 67 | return std::make_shared<arrow::matlab::array::proxy::StringArray>( |
| 68 | std::move(typed_array)); |
| 69 | } |
| 70 | |
| 71 | void StringArray::toMATLAB(libmexclass::proxy::method::Context& context) { |
| 72 | namespace mda = ::matlab::data; |
nothing calls this directly
no test coverage detected