2022-01-04 14:23:45 +00:00
|
|
|
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
|
|
|
|
//# Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
|
|
|
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
//# {{
|
2023-08-26 14:25:35 +00:00
|
|
|
#include "preprocessor.hpp"
|
2022-01-04 14:23:45 +00:00
|
|
|
#if !TOML_IMPLEMENTATION
|
|
|
|
#error This is an implementation-only header.
|
|
|
|
#endif
|
|
|
|
//# }}
|
|
|
|
|
2023-08-26 14:25:35 +00:00
|
|
|
#include "unicode.hpp"
|
|
|
|
#include "simd.hpp"
|
|
|
|
#include "header_start.hpp"
|
2022-01-04 14:23:45 +00:00
|
|
|
|
|
|
|
TOML_IMPL_NAMESPACE_START
|
|
|
|
{
|
2022-07-31 12:47:42 +00:00
|
|
|
TOML_PURE_GETTER
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_EXTERNAL_LINKAGE
|
|
|
|
bool is_ascii(const char* str, size_t len) noexcept
|
|
|
|
{
|
|
|
|
const char* const end = str + len;
|
|
|
|
|
|
|
|
#if TOML_HAS_SSE2 && (128 % CHAR_BIT) == 0
|
|
|
|
{
|
|
|
|
constexpr size_t chars_per_vector = 128u / CHAR_BIT;
|
|
|
|
|
|
|
|
if (const size_t simdable = len - (len % chars_per_vector))
|
|
|
|
{
|
|
|
|
__m128i mask = _mm_setzero_si128();
|
|
|
|
for (const char* const e = str + simdable; str < e; str += chars_per_vector)
|
|
|
|
{
|
|
|
|
const __m128i current_bytes = _mm_loadu_si128(reinterpret_cast<const __m128i*>(str));
|
|
|
|
mask = _mm_or_si128(mask, current_bytes);
|
|
|
|
}
|
|
|
|
const __m128i has_error = _mm_cmpgt_epi8(_mm_setzero_si128(), mask);
|
|
|
|
|
|
|
|
#if TOML_HAS_SSE4_1
|
|
|
|
if (!_mm_testz_si128(has_error, has_error))
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
if (_mm_movemask_epi8(_mm_cmpeq_epi8(has_error, _mm_setzero_si128())) != 0xFFFF)
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (; str < end; str++)
|
|
|
|
if (static_cast<unsigned char>(*str) > 127u)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TOML_IMPL_NAMESPACE_END;
|
|
|
|
|
2023-08-26 14:25:35 +00:00
|
|
|
#include "header_end.hpp"
|