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

Function StopAtStructuralChar

cpp/src/arrow/csv/writer.cc:182–206  ·  view source on GitHub ↗

Return the index of the first structural char in the input. A structural char is a character that needs quoting and/or escaping.

Source from the content-addressed store, hash-verified

180// Return the index of the first structural char in the input. A structural char
181// is a character that needs quoting and/or escaping.
182int64_t StopAtStructuralChar(const uint8_t* data, const int64_t buffer_size,
183 const char delimiter) {
184 int64_t offset = 0;
185#if defined(ARROW_HAVE_SSE4_2) || defined(ARROW_HAVE_NEON)
186 // _mm_cmpistrc gives slightly better performance than the naive approach,
187 // probably doesn't deserve the effort
188 using simd_batch = xsimd::make_sized_batch_t<uint8_t, 16>;
189 while ((offset + 16) <= buffer_size) {
190 const auto v = simd_batch::load_unaligned(data + offset);
191 if (xsimd::any((v == '\n') | (v == '\r') | (v == '"') | (v == delimiter))) {
192 break;
193 }
194 offset += 16;
195 }
196#endif
197 while (offset < buffer_size) {
198 // error happened or remaining bytes to check
199 const char c = static_cast<char>(data[offset]);
200 if (c == '\n' || c == '\r' || c == '"' || c == delimiter) {
201 break;
202 }
203 ++offset;
204 }
205 return offset;
206}
207
208// Populator used for non-string/binary types, or when unquoted strings/binary types are
209// desired. It assumes the strings in the casted array do not require quoting or escaping.

Callers 2

WriteHeaderMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected