diff --git a/CMakeLists.txt b/CMakeLists.txt index 352959b8e..6bc580df8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -575,6 +575,7 @@ target_include_directories(notcurses-tester ) target_link_libraries(notcurses-tester PRIVATE + unistring notcurses++ "${TERMINFO_LIBRARIES}" ) diff --git a/src/lib/internal.h b/src/lib/internal.h index ef51dcbee..2f058aa8d 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -33,6 +33,7 @@ const char* oiio_version(void); #include #include #include +#include #include #include "notcurses/notcurses.h" #include "egcpool.h" @@ -921,6 +922,23 @@ pool_load(egcpool* pool, cell* c, const char* gcluster){ // increment y by 1 and rotate the framebuffer up one line. x moves to 0. void scroll_down(ncplane* n); +static inline bool +islinebreak(wchar_t wchar){ + // UC_LINE_SEPARATOR + UC_PARAGRAPH_SEPARATOR + if(wchar == L'\n' || wchar == L'\v' || wchar == L'\f'){ + return true; + } + const uint32_t mask = UC_CATEGORY_MASK_Zl | UC_CATEGORY_MASK_Zp; + return uc_is_general_category_withtable(wchar, mask); +} + +static inline bool +iswordbreak(wchar_t wchar){ + const uint32_t mask = UC_CATEGORY_MASK_Z | + UC_CATEGORY_MASK_Zs; + return uc_is_general_category_withtable(wchar, mask); +} + #ifdef __cplusplus } #endif diff --git a/src/lib/layout.c b/src/lib/layout.c index 1f0213f27..796943fbe 100644 --- a/src/lib/layout.c +++ b/src/lib/layout.c @@ -1,22 +1,4 @@ #include "internal.h" -#include - -static bool -islinebreak(wchar_t wchar){ - // UC_LINE_SEPARATOR + UC_PARAGRAPH_SEPARATOR - if(wchar == '\n'){ - return true; - } - const uint32_t mask = UC_CATEGORY_MASK_Zl | UC_CATEGORY_MASK_Zp; - return uc_is_general_category_withtable(wchar, mask); -} - -static bool -iswordbreak(wchar_t wchar){ - const uint32_t mask = UC_CATEGORY_MASK_Z | - UC_CATEGORY_MASK_Zs; - return uc_is_general_category_withtable(wchar, mask); -} // print the first 'bytes' bytes of 'text' to 'n', using alignment 'align' // and requiring 'cols' columns, relative to the current cursor position. diff --git a/tests/libunistring.cpp b/tests/libunistring.cpp new file mode 100644 index 000000000..d85c414db --- /dev/null +++ b/tests/libunistring.cpp @@ -0,0 +1,44 @@ +#include "main.h" +#include "internal.h" + +// some simple tests to ensure the libunistring we've compiled/linked against +// behaves as expected. + +TEST_CASE("Libunistring") { + auto nc_ = testing_notcurses(); + if(!nc_){ + return; + } + ncplane* ncp_ = notcurses_stdplane(nc_); + REQUIRE(ncp_); + + SUBCASE("WordbreakChars") { + const wchar_t breakers[] = { + L'\u0020', // space + L'\u2000', // en quad + L'\u2001', // em quad + L'\u2002', // en quad + L'\u2003', // em quad + L'\u2004', // three-per-em space + 0 + }, *b; + for(b = breakers ; *b ; ++b){ + CHECK(iswordbreak(*b)); + } + } + + SUBCASE("LinebreakChars") { + const wchar_t breakers[] = { + L'\u000a', // linefeed + L'\u000b', // vertical tab + L'\u000c', // formfeed + 0 + }, *b; + for(b = breakers ; *b ; ++b){ + CHECK(islinebreak(*b)); + } + } + + CHECK(0 == notcurses_stop(nc_)); + +}