23 namespace qx::string_traits
28 template<
class value_t>
31 using value_type = value_t;
32 using pointer = value_t*;
33 using const_pointer =
const value_t*;
34 using reference = value_t&;
35 using const_reference =
const value_t&;
36 using difference_type = std::ptrdiff_t;
37 using size_type = size_t;
38 using string_view_type = basic_string_view<value_t>;
45 template<
class value_t,
class usings_
char_traits_t>
48 static constexpr
typename usings_char_traits_t::size_type hash_function(
49 typename usings_char_traits_t::const_pointer pszStr,
51 typename usings_char_traits_t::size_type nLen) noexcept
56 static constexpr
u32 hash_seed() noexcept
66 template<
class value_t,
class usings_
char_traits_t>
69 template<
class usings_
char_traits_t>
72 static constexpr
typename usings_char_traits_t::size_type align() noexcept
77 static constexpr
typename usings_char_traits_t::size_type small_string_size() noexcept
82 static constexpr
bool shrink_to_fit_when_small() noexcept
88 template<
class usings_
char_traits_t>
91 static constexpr
typename usings_char_traits_t::size_type align() noexcept
96 static constexpr
typename usings_char_traits_t::size_type small_string_size() noexcept
107 static constexpr
bool shrink_to_fit_when_small() noexcept
113 template<
class value_t,
class usings_
char_traits_t>
116 template<
class usings_
char_traits_t>
119 static constexpr
typename usings_char_traits_t::size_type small_string_size() noexcept
125 template<
class usings_
char_traits_t>
129 static constexpr
typename usings_char_traits_t::size_type small_string_size() noexcept
141 template<
class value_t,
class usings_
char_traits_t>
144 template<
class usings_
char_traits_t>
147 static constexpr
typename usings_char_traits_t::size_type align() noexcept
152 static constexpr
typename usings_char_traits_t::size_type small_string_size() noexcept
158 template<
class usings_
char_traits_t>
162 static constexpr
typename usings_char_traits_t::size_type align() noexcept
167 static constexpr
typename usings_char_traits_t::size_type small_string_size() noexcept
183 template<
class value_t,
class usings_
char_traits_t>
186 template<
class usings_
char_traits_t>
189 static bool is_space(
typename usings_char_traits_t::value_type ch) noexcept
191 return std::isspace(
static_cast<int>(ch)) != 0;
194 static bool is_digit(
typename usings_char_traits_t::value_type ch) noexcept
196 return std::isdigit(ch) != 0;
200 template<
class usings_
char_traits_t>
203 static bool is_space(
typename usings_char_traits_t::value_type ch) noexcept
205 return std::iswspace(
static_cast<wint_t
>(ch)) != 0;
208 static bool is_digit(
typename usings_char_traits_t::value_type ch) noexcept
210 return std::iswdigit(ch) != 0;
218 template<
class value_t,
class usings_
char_traits_t>
221 template<
class usings_
char_traits_t>
224 static typename usings_char_traits_t::value_type to_lower(
typename usings_char_traits_t::value_type ch) noexcept
226 return static_cast<char>(std::tolower(ch));
229 static typename usings_char_traits_t::value_type to_upper(
typename usings_char_traits_t::value_type ch) noexcept
231 return static_cast<char>(std::toupper(ch));
235 template<
class usings_
char_traits_t>
238 static typename usings_char_traits_t::value_type to_lower(
typename usings_char_traits_t::value_type ch) noexcept
240 return std::towlower(ch);
243 static typename usings_char_traits_t::value_type to_upper(
typename usings_char_traits_t::value_type ch) noexcept
245 return std::towupper(ch);
253 template<
class value_t,
class usings_
char_traits_t>
256 template<
class usings_
char_traits_t>
259 static constexpr
typename usings_char_traits_t::size_type length(
260 typename usings_char_traits_t::const_pointer pszStr) noexcept
262 if (std::is_constant_evaluated())
263 return static_cast<typename usings_char_traits_t::size_type
>(
qx::strlen(pszStr));
265 return static_cast<typename usings_char_traits_t::size_type
>(std::strlen(pszStr));
269 template<
class usings_
char_traits_t>
272 static constexpr
typename usings_char_traits_t::size_type length(
273 typename usings_char_traits_t::const_pointer pszStr) noexcept
275 if (std::is_constant_evaluated())
276 return static_cast<typename usings_char_traits_t::size_type
>(
qx::strlen(pszStr));
278 return static_cast<typename usings_char_traits_t::size_type
>(std::wcslen(pszStr));
286 template<
class value_t,
class usings_
char_traits_t>
289 template<
class usings_
char_traits_t>
293 typename usings_char_traits_t::const_pointer pszFirst,
294 typename usings_char_traits_t::const_pointer pszSecond) noexcept
296 return std::strcmp(pszFirst, pszSecond);
299 static int compare_n(
300 typename usings_char_traits_t::const_pointer pszFirst,
301 typename usings_char_traits_t::const_pointer pszSecond,
302 typename usings_char_traits_t::size_type nCount) noexcept
304 return std::strncmp(pszFirst, pszSecond, nCount);
308 template<
class usings_
char_traits_t>
312 typename usings_char_traits_t::const_pointer pszFirst,
313 typename usings_char_traits_t::const_pointer pszSecond) noexcept
315 return std::wcscmp(pszFirst, pszSecond);
318 static int compare_n(
319 typename usings_char_traits_t::const_pointer pszFirst,
320 typename usings_char_traits_t::const_pointer pszSecond,
321 typename usings_char_traits_t::size_type nCount) noexcept
323 return std::wcsncmp(pszFirst, pszSecond, nCount);
331 template<
class value_t,
class usings_
char_traits_t>
334 template<
class... args_t>
335 using format_string = std::basic_format_string<value_t, args_t...>;
342 template<
class value_t,
class usings_
char_traits_t>
345 template<
class usings_
char_traits_t>
348 template<
class... args_t>
350 typename usings_char_traits_t::const_pointer pszString,
351 typename usings_char_traits_t::const_pointer pszFormat,
352 args_t... args) noexcept
354 QX_PUSH_SUPPRESS_ALL_WARNINGS();
355 return std::sscanf(pszString, pszFormat, args...);
356 QX_POP_SUPPRESS_WARNINGS();
359 template<
class output_it_t,
class... args_t>
360 static void format_to(
361 output_it_t itOutput,
362 typename usings_char_traits_t::string_view_type svFormat,
363 const args_t&... args)
365 std::vformat_to(itOutput, svFormat, std::make_format_args(args...));
369 template<
class usings_
char_traits_t>
372 template<
class... args_t>
374 typename usings_char_traits_t::const_pointer pszString,
375 typename usings_char_traits_t::const_pointer pszFormat,
376 args_t... args) noexcept
378 QX_PUSH_SUPPRESS_ALL_WARNINGS();
379 return std::swscanf(pszString, pszFormat, args...);
380 QX_POP_SUPPRESS_WARNINGS();
383 template<
class output_it_t,
class... args_t>
384 static void format_to(
385 output_it_t itOutput,
386 typename usings_char_traits_t::string_view_type svFormat,
387 const args_t&... args)
389 std::vformat_to(itOutput, svFormat, std::make_wformat_args(args...));
393 template<
class... args_t>
402 template<
class value_t>
constexpr size_t djb2a_hash(const value_t *pszStr, size_t nSeed, size_t nLen)
djb2a hash
constexpr std::size_t strlen(const value_t *psz)
Naive but constexpr string length algorithm, for runtime prefer std::strlen as there are may be a lot...
uint32_t u32
0 .. 18 446 744 073 709 551 615