-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
63 lines (54 loc) · 1.89 KB
/
CMakeLists.txt
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
cmake_minimum_required(VERSION 3.15)
project(test_simdutf_install VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(simdutf CONFIG REQUIRED)
file(WRITE main.cpp "
#include <memory>
#include \"simdutf.h\"
int main(int, char *[]) {
const char *source = \"1234\";
// 4 == strlen(source)
bool validutf8 = simdutf::validate_utf8(source, 4);
if (validutf8) {
puts(\"valid UTF-8\");
} else {
puts(\"invalid UTF-8\");
return EXIT_FAILURE;
}
// We need a buffer of size where to write the UTF-16LE words.
size_t expected_utf16words = simdutf::utf16_length_from_utf8(source, 4);
std::unique_ptr<char16_t[]> utf16_output{new char16_t[expected_utf16words]};
// convert to UTF-16LE
size_t utf16words =
simdutf::convert_utf8_to_utf16le(source, 4, utf16_output.get());
printf(\"wrote %zu UTF-16LE words.\", utf16words);
// It wrote utf16words * sizeof(char16_t) bytes.
bool validutf16 = simdutf::validate_utf16le(utf16_output.get(), utf16words);
if (validutf16) {
puts(\"valid UTF-16LE\");
} else {
puts(\"invalid UTF-16LE\");
return EXIT_FAILURE;
}
// convert it back:
// We need a buffer of size where to write the UTF-8 words.
size_t expected_utf8words =
simdutf::utf8_length_from_utf16le(utf16_output.get(), utf16words);
std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
// convert to UTF-8
size_t utf8words = simdutf::convert_utf16le_to_utf8(
utf16_output.get(), utf16words, utf8_output.get());
printf(\"wrote %zu UTF-8 words.\", utf8words);
std::string final_string(utf8_output.get(), utf8words);
puts(final_string.c_str());
if (final_string != source) {
puts(\"bad conversion\");
return EXIT_FAILURE;
} else {
puts(\"perfect round trip\");
}
return EXIT_SUCCESS;
}")
add_executable(repro main.cpp)
target_link_libraries(repro PUBLIC simdutf::simdutf)