diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-19 06:52:23 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-19 06:52:23 (GMT) |
commit | 5bc888a2708e5cff38dabdbe95bbb965d59bb648 (patch) | |
tree | b10ebaa2834b3e647eccc1441265d5c0395b692c /generic/tkUtil.c | |
parent | d71a648c788bdbe6f17db19dcb90cafb174abc83 (diff) | |
parent | 5204a77ccd7306b8ed7c3c264c88171f68180efd (diff) | |
download | tk-5bc888a2708e5cff38dabdbe95bbb965d59bb648.zip tk-5bc888a2708e5cff38dabdbe95bbb965d59bb648.tar.gz tk-5bc888a2708e5cff38dabdbe95bbb965d59bb648.tar.bz2 |
Add TkUtfCharComplete(), and use it in TkNumUtfChars()
Diffstat (limited to 'generic/tkUtil.c')
-rw-r--r-- | generic/tkUtil.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 5d9d966..8150706 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -1353,8 +1353,9 @@ TkNumUtfChars( int length) /* The length of the string in bytes, or -1 * for strlen(string). */ { - int ch = 0; + int ch; int i = 0; + Tcl_UniChar ch2 = 0; if (length < 0) { /* string is NUL-terminated, so TclUtfToUniChar calls are safe. */ @@ -1363,12 +1364,24 @@ TkNumUtfChars( i++; } } else { - /* Pointer to the end of string. Never read endPtr[0] */ - const char *endPtr = src + length; + /* No need to call TkUtfCharComplete() up to endPtr */ + const char *endPtr = src + length - 6; while (src < endPtr) { src += TkUtfToUniChar(src, &ch); i++; } + /* Pointer to the end of string. Never read endPtr[0] */ + endPtr += 6; + while (src < endPtr) { + if (TkUtfCharComplete(src, endPtr - src)) { + src += TkUtfToUniChar(src, &ch); + } else if (Tcl_UtfCharComplete(src, endPtr - src)) { + src += Tcl_UtfToUniChar(src, &ch2); + } else { + src++; + } + i++; + } } return i; } |