Skip to content

Commit 551eac8

Browse files
author
Christian Parpart
committed
wip from windows
1 parent 6a79c31 commit 551eac8

9 files changed

+52
-16
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/_ucd/
55
/.clangd/
66
/compile_commands.json
7+
/.vs/
78
/.vscode/
89
/sandbox/
910
/target/

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MAT
3232
endif()
3333
elseif(DEFINED MSVC)
3434
add_definitions(-DNOMINMAX)
35-
add_compile_options(/utf-8)
35+
add_compile_options(/nologo)
36+
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /nologo")
3637
endif()
3738

3839
include(EnableCcache)

cmake/presets/os-windows.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"cacheVariables": {
1717
"VCPKG_TARGET_TRIPLET": "x64-windows",
1818
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
19-
"CMAKE_VERBOSE_MAKEFILE": "ON",
20-
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/../vcpkg/scripts/buildsystems/vcpkg.cmake"
19+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
20+
"CMAKE_VERBOSE_MAKEFILE": "ON"
2121
}
2222
},
2323
{ "name": "windows-cl-debug", "inherits": ["windows-common", "debug"], "displayName": "Windows (MSVC) Debug", "description": "Using MSVC compiler (64-bit)" },

src/libunicode/CMakeLists.txt

+8-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ add_custom_command(
8686

8787
add_library(unicode_loader ${LIBUNICODE_LIB_MODE} codepoint_properties_loader.h codepoint_properties_loader.cpp)
8888
add_library(unicode::loader ALIAS unicode_loader)
89+
if(DEFINED MSVC)
90+
target_compile_options(unicode_loader PUBLIC /EHsc) # We currently `throw` in the loader, so we need this.
91+
endif()
8992
if(LIBUNICODE_TABLEGEN_FASTBUILD)
9093
target_compile_definitions(unicode_loader PRIVATE LIBUNICODE_TABLEGEN_FASTBUILD)
9194
endif()
@@ -229,24 +232,26 @@ if(LIBUNICODE_TESTING)
229232
run_segmenter_test.cpp
230233
script_segmenter_test.cpp
231234
test_main.cpp
232-
unicode_test.cpp
233235
utf8_grapheme_segmenter_test.cpp
234236
utf8_test.cpp
235237
width_test.cpp
236238
word_segmenter_test.cpp
237239
)
238240

241+
if(DEFINED MSVC)
242+
target_compile_options(unicode_test PRIVATE /utf-8)
243+
endif()
244+
239245
if(NOT Catch2_FOUND)
240246
# supress conversion warnings for Catch2
241247
# https://github.com/catchorg/Catch2/issues/2583
242248
# https://github.com/SFML/SFML/blob/e45628e2ebc5843baa3739781276fa85a54d4653/test/CMakeLists.txt#L18-L22
243249
set_target_properties(Catch2 PROPERTIES COMPILE_OPTIONS "" EXPORT_COMPILE_COMMANDS OFF)
244-
set_target_properties(Catch2WithMain PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
245250
get_target_property(CATCH2_INCLUDE_DIRS Catch2 INTERFACE_INCLUDE_DIRECTORIES)
246251
target_include_directories(Catch2 SYSTEM INTERFACE ${CATCH2_INCLUDE_DIRS})
247252
endif()
248253

249-
target_link_libraries(unicode_test unicode Catch2::Catch2WithMain fmt::fmt-header-only)
254+
target_link_libraries(unicode_test unicode Catch2::Catch2 fmt::fmt-header-only)
250255
add_test(unicode_test unicode_test)
251256
endif()
252257
# }}}

src/libunicode/grapheme_line_segmenter.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,16 @@ class grapheme_line_segmenter<OptionalEventListener>
696696
assert(processedTotalWidth + consumedWidth <= maxWidth);
697697
auto const asciiTextChunk = std::string_view(next(), consumedWidth);
698698
_eventHandler.on_ascii(asciiTextChunk);
699+
assert(!asciiTextChunk.empty());
700+
// We do not store the last ASCII character as last codepoint, because
701+
// we only need to remember the last codepoint to distinguish
702+
// breakability in the grapheme cluster segmentation algorithm.
703+
// We've already reported all ASCII and start fresh after that again.
704+
_complexUnicodeState.lastCodepointHint = 0;
705+
_complexUnicodeState.currentClusterWidth = 0;
699706
_complexUnicodeState.utf8DecodeNext = consumedEnd;
700707
_complexUnicodeState.currentClusterStart = consumedEnd;
701708
_complexUnicodeState.currentCodepointStart = consumedEnd;
702-
assert(!asciiTextChunk.empty());
703-
_complexUnicodeState.lastCodepointHint = asciiTextChunk.back();
704709
processedTotalWidth += consumedWidth;
705710
assert(processedTotalWidth <= maxWidth);
706711
break;

src/libunicode/grapheme_line_segmenter_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ TEST_CASE("grapheme_line_segmenter.invalid_char.1")
492492
// {{{ mixed primitive ASCII and complex unicode
493493
TEST_CASE("grapheme_line_segmenter.mixed.1")
494494
{
495-
auto const text = "0123456789{\xE2\x94\x80}ABCDEF"sv;
495+
auto const text = "0123456789{\xE2\x94\x80}ABCDEF"sv; // \xE2 \x94 \x80 == U+2500
496496
auto recorder = event_recorder { text };
497497
auto segmenter = grapheme_line_segmenter { recorder, text };
498498
auto const result = segmenter.process(80);

src/libunicode/test_main.cpp

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* This file is part of the "libunicode" project
3-
* Copyright (c) 2020 Christian Parpart <[email protected]>
3+
* Copyright (c) 2024 Christian Parpart <[email protected]>
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -11,15 +11,39 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
#define CATCH_CONFIG_RUNNER
1514
#include <catch2/catch_session.hpp>
1615

17-
int main(int argc, char const* argv[])
16+
#if defined(_WIN32)
17+
#include <Windows.h>
18+
#endif
19+
20+
namespace
21+
{
22+
23+
struct SetupTeardown
24+
{
25+
SetupTeardown()
26+
{
27+
#if defined(_WIN32)
28+
const auto stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
29+
const auto stdoutCP = GetConsoleOutputCP();
30+
DWORD stdoutMode;
31+
GetConsoleMode(stdoutHandle, &stdoutMode);
32+
SetConsoleMode(stdoutHandle, ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
33+
SetConsoleOutputCP(CP_UTF8);
34+
#endif
35+
}
36+
37+
~SetupTeardown() = default;
38+
};
39+
40+
} // namespace
41+
42+
int main(int argc, char* argv[])
1843
{
19-
int const result = Catch::Session().run(argc, argv);
44+
auto const _ = SetupTeardown {};
2045

21-
// avoid closing extern console to close on VScode/windows
22-
// system("pause");
46+
int result = Catch::Session().run(argc, argv);
2347

2448
return result;
2549
}

src/libunicode/unicode_test.cpp

Whitespace-only changes.

src/libunicode/utf8_grapheme_segmenter_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ std::string escape(std::string const& s)
2929
{
3030
std::string t;
3131
for (char ch: s)
32-
if (std::isprint(ch))
32+
if (ch >= 0x20 && ch <= 0x7E) // printable ASCII (We don't use isprint() due to MSVC)
3333
t += ch;
3434
else
3535
t += fmt::format("\\x{:02X}", ((unsigned) ch) & 0xFF);

0 commit comments

Comments
 (0)