1010#include " simdjson/common_defs.h"
1111#include " simdjson/parsedjson.h"
1212
13- #define UTF8VALIDATE
13+ #ifndef SIMDJSON_SKIPUTF8VALIDATION
14+ #define SIMDJSON_UTF8VALIDATE
15+ #endif
16+
1417// It seems that many parsers do UTF-8 validation.
1518// RapidJSON does not do it by default, but a flag
1619// allows it.
17- #ifdef UTF8VALIDATE
20+ #ifdef SIMDJSON_UTF8VALIDATE
1821#include " simdjson/simdutf8check.h"
1922#endif
2023using namespace std ;
@@ -37,7 +40,7 @@ WARN_UNUSED
3740 cerr << " Your ParsedJson object only supports documents up to " << pj.bytecapacity << " bytes but you are trying to process " << len << " bytes\n " ;
3841 return false ;
3942 }
40- #ifdef UTF8VALIDATE
43+ #ifdef SIMDJSON_UTF8VALIDATE
4144 __m256i has_error = _mm256_setzero_si256 ();
4245 struct avx_processed_utf_bytes previous = {
4346 .rawbytes = _mm256_setzero_si256 (),
@@ -78,7 +81,7 @@ WARN_UNUSED
7881#endif
7982 m256 input_lo = _mm256_loadu_si256 ((const m256 *)(buf + idx + 0 ));
8083 m256 input_hi = _mm256_loadu_si256 ((const m256 *)(buf + idx + 32 ));
81- #ifdef UTF8VALIDATE
84+ #ifdef SIMDJSON_UTF8VALIDATE
8285 m256 highbit = _mm256_set1_epi8 (0x80 );
8386 if ((_mm256_testz_si256 (_mm256_or_si256 (input_lo, input_hi),highbit)) == 1 ) {
8487 // it is ascii, we just check continuation
@@ -261,7 +264,7 @@ WARN_UNUSED
261264 memcpy (tmpbuf,buf+idx,len - idx);
262265 m256 input_lo = _mm256_loadu_si256 ((const m256 *)(tmpbuf + 0 ));
263266 m256 input_hi = _mm256_loadu_si256 ((const m256 *)(tmpbuf + 32 ));
264- #ifdef UTF8VALIDATE
267+ #ifdef SIMDJSON_UTF8VALIDATE
265268 m256 highbit = _mm256_set1_epi8 (0x80 );
266269 if ((_mm256_testz_si256 (_mm256_or_si256 (input_lo, input_hi),highbit)) == 1 ) {
267270 // it is ascii, we just check continuation
@@ -402,7 +405,7 @@ WARN_UNUSED
402405 structurals &= ~(quote_bits & ~quote_mask);
403406 *(u64 *)(pj.structurals + idx / 8 ) = structurals;
404407 }
405- #ifdef UTF8VALIDATE
408+ #ifdef SIMDJSON_UTF8VALIDATE
406409 return _mm256_testz_si256 (has_error, has_error);
407410#else
408411 return true ;
0 commit comments