From aeab67f4dc7ec7bfe262c90b947ca38de9c90fba Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 14 Apr 2020 00:09:06 +0000 Subject: Create separate tables to serve Tcl_UtfPrev and Tcl_UtfComplete. --- generic/tclUtf.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 22e26d2..a67e5e7 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -64,6 +64,23 @@ static const unsigned char totalBytes[256] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, +#if TCL_UTF_MAX > 3 + 4,4,4,4,4, +#else + 1,1,1,1,1, +#endif + 1,1,1,1,1,1,1,1,1,1,1 +}; + +static const unsigned char complete[256] = { + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, #if TCL_UTF_MAX > 4 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, @@ -497,7 +514,7 @@ Tcl_UtfCharComplete( * a complete UTF-8 character. */ int length) /* Length of above string in bytes. */ { - return length >= totalBytes[(unsigned char)*src]; + return length >= complete[(unsigned char)*src]; } /* @@ -728,7 +745,7 @@ Tcl_UtfPrev( int i, byte; look = --src; - for (i = 0; i < 4; i++) { + for (i = 0; i < TCL_UTF_MAX; i++) { if (look < start) { if (src < start) { src = start; -- cgit v0.12 From 3aca2a1af19677ddff700f4fbc15b77616f42efe Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 14 Apr 2020 08:44:18 +0000 Subject: Fix unit-test, change expectations according to current 8.6 branch (not handling [1b1f5f0b53] yet, doing that in separate branch) --- generic/tclUtf.c | 10 ++-------- tests/utf.test | 14 +++++++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/generic/tclUtf.c b/generic/tclUtf.c index a67e5e7..3377b70 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -67,13 +67,7 @@ static const unsigned char totalBytes[256] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, -#if TCL_UTF_MAX > 3 - 4,4,4,4,4, -#else - 1,1,1,1,1, -#endif - 1,1,1,1,1,1,1,1,1,1,1 + 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1 }; static const unsigned char complete[256] = { @@ -745,7 +739,7 @@ Tcl_UtfPrev( int i, byte; look = --src; - for (i = 0; i < TCL_UTF_MAX; i++) { + for (i = 0; i < 4; i++) { if (look < start) { if (src < start) { src = start; diff --git a/tests/utf.test b/tests/utf.test index 103e39b..1b7b409 100644 --- a/tests/utf.test +++ b/tests/utf.test @@ -223,13 +223,13 @@ test utf-7.9.2 {Tcl_UtfPrev} testutfprev { } 2 test utf-7.10 {Tcl_UtfPrev} testutfprev { testutfprev A\xF4\xA0 -} 2 +} 1 test utf-7.10.1 {Tcl_UtfPrev} testutfprev { testutfprev A\xF4\xA0\xA0\xA0 3 -} 2 +} 1 test utf-7.10.2 {Tcl_UtfPrev} testutfprev { testutfprev A\xF4\xA0\xF8\xA0 3 -} 2 +} 1 test utf-7.11 {Tcl_UtfPrev} testutfprev { testutfprev A\xE8\xA0 } 1 @@ -268,13 +268,13 @@ test utf-7.14.2 {Tcl_UtfPrev} testutfprev { } 3 test utf-7.15 {Tcl_UtfPrev} testutfprev { testutfprev A\xF4\xA0\xA0 -} 3 +} 1 test utf-7.15.1 {Tcl_UtfPrev} testutfprev { testutfprev A\xF4\xA0\xA0\xA0 4 -} 3 +} 1 test utf-7.15.2 {Tcl_UtfPrev} testutfprev { testutfprev A\xF4\xA0\xA0\xF8 4 -} 3 +} 1 test utf-7.16 {Tcl_UtfPrev} testutfprev { testutfprev A\xE8\xA0\xA0 } 1 @@ -307,7 +307,7 @@ test utf-7.19 {Tcl_UtfPrev} testutfprev { } 4 test utf-7.20 {Tcl_UtfPrev} testutfprev { testutfprev A\xF4\xA0\xA0\xA0 -} 4 +} 1 test utf-7.21 {Tcl_UtfPrev} testutfprev { testutfprev A\xE8\xA0\xA0\xA0 } 4 -- cgit v0.12