From d2e39cca85cda58c6ecc5e968e83b53c482ea81b Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 8 Dec 2020 07:34:54 -0500 Subject: [PATCH] rtl--increment *bytes in rtl_egc() #1174 --- src/lib/internal.h | 11 +++++++---- tests/bidi.cpp | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index 4faa69eac..bd5037e5a 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -950,10 +950,13 @@ egc_rtl(const char* egc, int* bytes){ } // insert U+200E, "LEFT-TO-RIGHT MARK". This ought reset the text direction // after emitting a potentially RTL EGC. - const char LTRMARK[] = "\xe2\x80\x8e"; - char* s = (char*)malloc(*bytes + sizeof(LTRMARK)); // cast for C++ callers - memcpy(s, egc, *bytes); - memcpy(s + *bytes, LTRMARK, sizeof(LTRMARK)); + const char LTRMARK[] = "\xe2\x80\xad"; + char* s = (char*)malloc(*bytes + strlen(LTRMARK) + 1); // cast for C++ callers + memcpy(s, LTRMARK, strlen(LTRMARK)); + memcpy(s + strlen(LTRMARK), egc, *bytes); + s[strlen(LTRMARK) + *bytes] = '\0'; +//fprintf(stderr, "\nLTR: [%s] (\xe2\x80\xad%s) (%zu) (%d)\n", s, egc, strlen(s), *bytes); + *bytes += strlen(LTRMARK); return s; } diff --git a/tests/bidi.cpp b/tests/bidi.cpp index e2671b47c..6caae4d47 100644 --- a/tests/bidi.cpp +++ b/tests/bidi.cpp @@ -20,11 +20,11 @@ TEST_CASE("Bidi") { uint64_t channels; auto egc = ncplane_at_yx(n_, 0, 0, &stylemask, &channels); REQUIRE(nullptr != egc); - CHECK(0 == strcmp(egc, "ה")); + CHECK(0 == strcmp(egc, "\xe2\x80\xadה")); free(egc); egc = ncplane_at_yx(n_, 0, 4, &stylemask, &channels); REQUIRE(nullptr != egc); - CHECK(0 == strcmp(egc, "ך")); + CHECK(0 == strcmp(egc, "\xe2\x80\xadך")); free(egc); // FIXME yes, we place this at 0,0 in our internal view...and yet it // is actually placed at the rightmost cell :/