File: _fixed-string.cpp

package info (click to toggle)
ctre 3.9.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,084 kB
  • sloc: cpp: 80,452; makefile: 135; javascript: 69; python: 31
file content (36 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <ctll/fixed_string.hpp>

void empty_symbol() { }

static constexpr auto Pattern = ctll::fixed_string{ LR"(^\s*(\d+)\s+:(\S):$(\S+?)$(\S+?)$(\S+))" };

static_assert(Pattern.size() == 38);

// ordinary string is taken as array of bytes
#ifdef CTRE_STRING_IS_UTF8
static_assert(ctll::fixed_string("ฤ›ลกฤ").size() == 3);
static_assert(ctll::fixed_string("๐Ÿ˜").size() == 1);
static_assert(ctll::fixed_string("๐Ÿ˜")[0] == L'๐Ÿ˜');
#else
static_assert(ctll::fixed_string("ฤ›ลกฤ").size() == 6); // it's just a bunch of bytes
static_assert(ctll::fixed_string("๐Ÿ˜").size() == 4); // it's just a bunch of bytes
#endif

#if __cpp_char8_t
// u8"" is utf-8 encoded
static_assert(ctll::fixed_string(u8"ฤ›ลกฤ").size() == 3);
static_assert(ctll::fixed_string(u8"๐Ÿ˜").size() == 1);
static_assert(ctll::fixed_string(u8"๐Ÿ˜")[0] == U'๐Ÿ˜');
#endif

// u"" is utf-16
static_assert(ctll::fixed_string(u"ฤ›ลกฤ").size() == 3);
static_assert(ctll::fixed_string(u"๐Ÿ˜").size() == 1);
static_assert(ctll::fixed_string(u"๐Ÿ˜").is_same_as(ctll::fixed_string(U"๐Ÿ˜")));

// U"" is utf-32
static_assert(ctll::fixed_string(U"ฤ›ลกฤ").size() == 3);
static_assert(ctll::fixed_string(U"๐Ÿ˜").size() == 1);

// everything is converted into utf-32