6#include "TTauri/Foundation/algorithm.hpp"
7#include "TTauri/Foundation/numeric_cast.hpp"
8#include "TTauri/Foundation/required.hpp"
9#include "TTauri/Foundation/assert.hpp"
10#include "TTauri/Foundation/os_detect.hpp"
11#include "TTauri/Foundation/Unicode.hpp"
20[[nodiscard]]
constexpr bool isUpper(
char c)
noexcept {
21 return c >=
'A' && c <=
'Z';
24[[nodiscard]]
constexpr bool isLower(
char c)
noexcept {
25 return c >=
'a' && c <=
'z';
28[[nodiscard]]
constexpr bool isAlpha(
char c)
noexcept {
29 return isUpper(c) || isLower(c);
32[[nodiscard]]
constexpr bool isDigit(
char c)
noexcept {
33 return c >=
'0' && c <=
'9';
36[[nodiscard]]
constexpr bool isAlphaNum(
char c)
noexcept {
37 return isAlpha(c) || isDigit(c);
40[[nodiscard]]
constexpr bool isLinefeed(
char c)
noexcept {
41 return c ==
'\r' || c ==
'\n' || c ==
'\f' || c ==
'\v';
44[[nodiscard]]
constexpr bool isWhitespace(
char c)
noexcept {
45 return c ==
' ' || c ==
'\t' || isLinefeed(c);
48[[nodiscard]]
constexpr bool isNumberFirst(
char c)
noexcept {
49 return isDigit(c) || c ==
'+' || c ==
'-';
52[[nodiscard]]
constexpr bool isNameFirst(
char c)
noexcept {
53 return isAlpha(c) || c ==
'_' || c ==
'$';
56[[nodiscard]]
constexpr bool isNameNext(
char c)
noexcept {
57 return isAlphaNum(c) || c ==
'_' || c ==
'$';
60[[nodiscard]]
constexpr bool isQuote(
char c)
noexcept {
61 return c ==
'"' || c ==
'\'' || c ==
'`';
64[[nodiscard]]
constexpr bool isOpenBracket(
char c)
noexcept {
65 return c ==
'(' || c ==
'{' || c ==
'[';
68[[nodiscard]]
constexpr bool isCloseBracket(
char c)
noexcept {
69 return c ==
')' || c ==
'}' || c ==
']';
72[[nodiscard]]
constexpr bool isOperator(
char c)
noexcept {
74 !isAlphaNum(c) && c !=
'_' &&
81[[nodiscard]]
inline std::string to_lower(std::string_view str)
noexcept
87 r += (c >=
'A' && c <=
'Z') ? (c -
'A') +
'a': c;
93[[nodiscard]]
inline std::string to_upper(std::string_view str)
noexcept
99 r += (c >=
'a' && c <=
'z') ? (c -
'a') +
'A': c;
107[[nodiscard]]
inline std::string normalize_lf(std::string_view str)
noexcept
112 auto found_cr =
false;
114 if (tt_unlikely(found_cr)) {
118 if (c !=
'\r' && c !=
'\n') {
122 }
else if (tt_likely(c !=
'\r')) {
127 found_cr = c ==
'\r';
139[[nodiscard]]
inline std::string id_encode(std::string_view str)
noexcept
144 r += isNameFirst(str.front()) ? str.front() :
'_';
145 for (ttlet c: str.substr(1)) {
146 r += isNameNext(c) ? c :
'_';
152gsl_suppress3(f.23,bounds.1,bounds.3)
153[[nodiscard]]
constexpr uint32_t fourcc(
char const txt[5])
noexcept
156 (
static_cast<uint32_t
>(txt[0]) << 24) |
157 (
static_cast<uint32_t
>(txt[1]) << 16) |
158 (
static_cast<uint32_t
>(txt[2]) << 8) |
159 static_cast<uint32_t
>(txt[3])
163[[nodiscard]]
constexpr uint32_t fourcc(uint8_t
const *txt)
noexcept
166 (
static_cast<uint32_t
>(txt[0]) << 24) |
167 (
static_cast<uint32_t
>(txt[1]) << 16) |
168 (
static_cast<uint32_t
>(txt[2]) << 8) |
169 static_cast<uint32_t
>(txt[3])
173gsl_suppress(bounds.3)
174[[nodiscard]]
inline std::string fourcc_to_string(uint32_t x)
noexcept
177 c_str[0] = numeric_cast<char>((x >> 24) & 0xff);
178 c_str[1] = numeric_cast<char>((x >> 16) & 0xff);
179 c_str[2] = numeric_cast<char>((x >> 8) & 0xff);
180 c_str[3] = numeric_cast<char>(x & 0xff);
186[[nodiscard]]
constexpr char nibble_to_char(uint8_t nibble)
noexcept
190 }
else if (nibble <= 15) {
191 return 'a' + nibble - 10;
200[[nodiscard]]
inline int8_t char_to_nibble(
char c)
noexcept
202 if (c >=
'0' && c <=
'9') {
204 }
else if (c >=
'a' && c <=
'f') {
205 return (c -
'a') + 10;
206 }
else if (c >=
'A' && c <=
'F') {
207 return (c -
'A') + 10;
213[[nodiscard]]
inline std::string_view make_string_view(
214 typename std::string::const_iterator b,
215 typename std::string::const_iterator e
219 std::string_view{&(*b), numeric_cast<size_t>(
std::distance(b, e))} :
223template<
typename Needle>
224[[nodiscard]]
size_t split_needle_size(Needle
const &needle)
noexcept
230[[nodiscard]]
inline size_t split_needle_size(
char const &needle)
noexcept
236[[nodiscard]]
inline size_t split_needle_size(
char const (&needle)[N])
noexcept
242template<
typename Haystack,
typename... Needles>
243[[nodiscard]]
auto split_find_needle(
size_t offset, Haystack
const &haystack, Needles
const &... needles)
noexcept
246 {
std::pair{haystack.find(needles, offset), split_needle_size(needles)}...},
247 [](ttlet &a, ttlet &b) {
248 return a.first < b.first;
253template<
typename Haystack,
typename... Needles>
254[[nodiscard]]
auto split(Haystack
const &haystack, Needles
const &... needles)
noexcept
262 std::tie(needle_pos, needle_size) = split_find_needle(offset, haystack, needles...);
263 while (needle_pos != haystack.npos) {
264 r.
push_back(haystack.substr(offset, needle_pos - offset));
266 offset = needle_pos + needle_size;
267 std::tie(needle_pos, needle_size) = split_find_needle(offset, haystack, needles...);
278 if (list.
size() > 1) {
279 size_t final_size = (list.
size() - 1) * joiner.
size();
280 for (ttlet &
item: list) {
281 final_size +=
item.size();
287 for (ttlet &
item: list) {
300 if (list.
size() > 1) {
301 size_t final_size = (list.
size() - 1) * joiner.
size();
302 for (ttlet &
item: list) {
303 final_size +=
item.size();
309 for (ttlet &
item: list) {
330 case '\n': line++; [[fallthrough]];
331 case '\r': column = 1;
334 column = ((((column-1) / 8) + 1) * 8) + 1;
340 return { line, column };
Definition range_map.hpp:119