NeBuild dev
Loading...
Searching...
No Matches
unicode.inl
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
7// # {{
8#include "preprocessor.hpp"
9#if !TOML_IMPLEMENTATION
10#error This is an implementation-only header.
11#endif
12// # }}
13
14#include "header_start.hpp"
15#include "simd.hpp"
16#include "unicode.hpp"
17
21 bool is_ascii(const char* str, size_t len) noexcept {
22 const char* const end = str + len;
23
24#if TOML_HAS_SSE2 && (128 % CHAR_BIT) == 0
25 {
26 constexpr size_t chars_per_vector = 128u / CHAR_BIT;
27
28 if (const size_t simdable = len - (len % chars_per_vector)) {
29 __m128i mask = _mm_setzero_si128();
30 for (const char* const e = str + simdable; str < e; str += chars_per_vector) {
31 const __m128i current_bytes = _mm_loadu_si128(reinterpret_cast<const __m128i*>(str));
32 mask = _mm_or_si128(mask, current_bytes);
33 }
34 const __m128i has_error = _mm_cmpgt_epi8(_mm_setzero_si128(), mask);
35
36#if TOML_HAS_SSE4_1
37 if (!_mm_testz_si128(has_error, has_error)) return false;
38#else
39 if (_mm_movemask_epi8(_mm_cmpeq_epi8(has_error, _mm_setzero_si128())) != 0xFFFF)
40 return false;
41#endif
42 }
43 }
44#endif
45
46 for (; str < end; str++)
47 if (static_cast<unsigned char>(*str) > 127u) return false;
48
49 return true;
50 }
51}
53
54#include "header_end.hpp"
#define TOML_EXTERNAL_LINKAGE
Definition preprocessor.hpp:1339
#define TOML_PURE_GETTER
Definition preprocessor.hpp:474
#define TOML_IMPL_NAMESPACE_END
Definition preprocessor.hpp:1334
TOML_IMPL_NAMESPACE_START
Definition unicode.inl:18