force zero-width-joins #2016

This commit is contained in:
nick black 2021-08-02 09:00:01 -04:00
parent cb74709cb0
commit 6f0830c29a
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
4 changed files with 10 additions and 3 deletions

View File

@ -74,7 +74,7 @@ terminal, and will refuse to run in anything smaller than 80x24.
**-V**|**--version**: Print the program name and version, and exit with success.
***demospec***: Select which demos to run, and what order to run them in. The
default is **ixetunchdmbkywgarvlsfjqzo**. See above for a list of demos.
default is **ixetunchmdbkywgarvlsfjqzo**. See above for a list of demos.
Default margins are all 0, and thus the full screen will be rendered. Using
**-m**, margins can be supplied. Provide a single number to set all four margins

View File

@ -21,7 +21,7 @@ static int democount;
static demoresult* results;
static char *datadir = NOTCURSES_SHARE;
static const char DEFAULT_DEMO[] = "ixetunchdmbkywgarvlsfjqzo";
static const char DEFAULT_DEMO[] = "ixetunchmdbkywgarvlsfjqzo";
atomic_bool interrupted = ATOMIC_VAR_INIT(false);
// checked following demos, whether aborted, failed, or otherwise

View File

@ -97,6 +97,7 @@ utf8_egc_len(const char* gcluster, int* colcount){
mbstate_t mbt;
memset(&mbt, 0, sizeof(mbt));
wchar_t wc, prevw = 0;
bool injoin = false;
do{
r = mbrtowc(&wc, gcluster, MB_CUR_MAX, &mbt);
if(r < 0){
@ -104,7 +105,7 @@ utf8_egc_len(const char* gcluster, int* colcount){
logerror("Invalid UTF8: %s\n", gcluster);
return -1;
}
if(prevw && uc_is_grapheme_break(prevw, wc)){
if(prevw && !injoin && uc_is_grapheme_break(prevw, wc)){
break; // starts a new EGC, exit and do not claim
}
int cols = wcwidth(wc);
@ -115,6 +116,7 @@ utf8_egc_len(const char* gcluster, int* colcount){
logerror("Prohibited or invalid Unicode: 0x%x\n", wc);
return -1;
}
injoin = (wc == L'\u200d');
*colcount += cols;
ret += r;
gcluster += r;

View File

@ -41,6 +41,11 @@ TEST_CASE("Cell") {
WARN(1 == nccell_cols(&c));
CHECK(9 == nccell_load(n_, &c, "นี้"));
WARN(1 == nccell_cols(&c));
// type-3 woman playing water polo, 17 bytes (5 characters)
CHECK(17 == nccell_load(n_, &c, "\U0001f93d\U0001f3fc\u200d\u2640\ufe0f"));
WARN(2 == nccell_cols(&c));
nccell_release(n_, &c);
}
SUBCASE("Loadchar") {