diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-06 13:22:05 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-06 13:22:05 (GMT) |
commit | c5e55206a201b155a055c3b6ebeb1bf592cc7f21 (patch) | |
tree | d00dd2bafc0ca8c0db2d5689457cfd7ba17963f8 /generic/tclUtf.c | |
parent | 7adecdbf4a328b9f39774d0323a64886c1f160b3 (diff) | |
parent | 391948de408337582c0f29f4f897e1d0d5d96fcc (diff) | |
download | tcl-c5e55206a201b155a055c3b6ebeb1bf592cc7f21.zip tcl-c5e55206a201b155a055c3b6ebeb1bf592cc7f21.tar.gz tcl-c5e55206a201b155a055c3b6ebeb1bf592cc7f21.tar.bz2 |
Merge 8.6
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r-- | generic/tclUtf.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 7b6ec63..ac6f0d8 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -95,7 +95,7 @@ static const unsigned char complete[256] = { * Functions used only in this module. */ -static int Invalid(unsigned char *src); +static int Invalid(const char *src); /* *--------------------------------------------------------------------------- @@ -161,9 +161,9 @@ static const unsigned char bounds[28] = { static int Invalid( - unsigned char *src) /* Points to lead byte of a UTF-8 byte sequence */ + const char *src) /* Points to lead byte of a UTF-8 byte sequence */ { - unsigned char byte = *src; + unsigned char byte = UCHAR(*src); int index; if ((byte & 0xC3) != 0xC0) { @@ -171,7 +171,7 @@ Invalid( return 0; } index = (byte - 0xC0) >> 1; - if (src[1] < bounds[index] || src[1] > bounds[index+1]) { + if (UCHAR(src[1]) < bounds[index] || UCHAR(src[1]) > bounds[index+1]) { /* Out of bounds - report invalid. */ return 1; } @@ -935,8 +935,8 @@ const char * Tcl_UtfNext( const char *src) /* The current location in the string. */ { - int left = totalBytes[UCHAR(*src)]; - const char *next = src + 1; + int left; + const char *next; if (((*src) & 0xC0) == 0x80) { if ((((*++src) & 0xC0) == 0x80) && (((*++src) & 0xC0) == 0x80)) { @@ -945,6 +945,11 @@ Tcl_UtfNext( return src; } + if (Invalid(src)) { + return src + 1; + } + left = totalBytes[UCHAR(*src)]; + next = src + 1; while (--left) { if ((*next & 0xC0) != 0x80) { /* @@ -956,9 +961,6 @@ Tcl_UtfNext( } next++; } - if (Invalid((unsigned char *)src)) { - return src + 1; - } return next; } @@ -993,7 +995,7 @@ Tcl_UtfPrev( /* If we cannot find a lead byte that might * start a prefix of a valid UTF byte sequence, * we will fallback to a one-byte back step */ - unsigned char *look = (unsigned char *)fallback; + const char *look = fallback; /* Start search at the fallback position */ /* Quick boundary case exit. */ @@ -1002,7 +1004,7 @@ Tcl_UtfPrev( } do { - unsigned char byte = look[0]; + unsigned char byte = UCHAR(look[0]); if (byte < 0x80) { /* |