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

Function AppendUTF32

python/pyarrow/src/arrow/python/numpy_to_arrow.cc:681–705  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

679
680template <typename T>
681Status AppendUTF32(const char* data, int64_t itemsize, int byteorder, T* builder) {
682 // The binary \x00\x00\x00\x00 indicates a nul terminator in NumPy unicode,
683 // so we need to detect that here to truncate if necessary. Yep.
684 Py_ssize_t actual_length = 0;
685 for (; actual_length < itemsize / kNumPyUnicodeSize; ++actual_length) {
686 const char* code_point = data + actual_length * kNumPyUnicodeSize;
687 if ((*code_point == '\0') && (*(code_point + 1) == '\0') &&
688 (*(code_point + 2) == '\0') && (*(code_point + 3) == '\0')) {
689 break;
690 }
691 }
692
693 OwnedRef unicode_obj(PyUnicode_DecodeUTF32(data, actual_length * kNumPyUnicodeSize,
694 nullptr, &byteorder));
695 RETURN_IF_PYERROR();
696 OwnedRef utf8_obj(PyUnicode_AsUTF8String(unicode_obj.obj()));
697 if (utf8_obj.obj() == NULL) {
698 PyErr_Clear();
699 return Status::Invalid("failed converting UTF32 to UTF8");
700 }
701
702 const int32_t length = static_cast<int32_t>(PyBytes_GET_SIZE(utf8_obj.obj()));
703 return builder->Append(
704 reinterpret_cast<const uint8_t*>(PyBytes_AS_STRING(utf8_obj.obj())), length);
705}
706
707} // namespace
708

Callers 1

VisitStringMethod · 0.85

Calls 2

InvalidFunction · 0.50
AppendMethod · 0.45

Tested by

no test coverage detected