File: __utf8.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 (43 lines) | stat: -rw-r--r-- 800 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
37
38
39
40
41
42
43
#include <ctre/utf8.hpp>
#include <algorithm>

#ifdef CTRE_ENABLE_UTF8_RANGE

#define UNICODE_TEST(a) static_assert(call_test(u8 ##a, U ##a))

constexpr bool call_test(std::u8string_view a, std::u32string_view b) {
	auto utf = ctre::utf8_range(a);
	
	auto a_it = utf.begin();
	auto a_end = utf.end();
	
	auto b_it = b.begin();
	auto b_end = b.end();
	
	while (a_it != a_end && b_it != b_end) {
		if (*a_it != *b_it) return false;
		++a_it;
		++b_it;
	}
	
	if (a_it != a_end) return false;
	if (b_it != b_end) return false;
	
	return true;
}

#else

#define UNICODE_TEST(a) do { } while (false)

#endif

int main() {
	UNICODE_TEST("test");
	UNICODE_TEST("ěščř");
	UNICODE_TEST("Г");
	UNICODE_TEST("Гa");
	UNICODE_TEST("Гa😀");
	UNICODE_TEST("Гa😀ᦉ");
	UNICODE_TEST("Гa😀ᦉ🜇aa");
}