diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-07 21:28:19 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-07 21:28:19 (GMT) |
commit | 236622c790c99057427a8bc4fb83867cfbf4bc04 (patch) | |
tree | 9758e113efae58dd4e72550f099abc73f807b27f /generic/tclUtf.c | |
parent | a905663fb19b096859fa15ee42a2793745189767 (diff) | |
parent | 098e262372efb9e7d7ac9e3f58bf30febfbaf8bd (diff) | |
download | tcl-236622c790c99057427a8bc4fb83867cfbf4bc04.zip tcl-236622c790c99057427a8bc4fb83867cfbf4bc04.tar.gz tcl-236622c790c99057427a8bc4fb83867cfbf4bc04.tar.bz2 |
Merge 8.6
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r-- | generic/tclUtf.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 12eb637..8e58b74 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -525,12 +525,13 @@ Tcl_UtfToUniCharDString( p += TclUtfToUniChar(p, &ch); *w++ = ch; } - while ((p < endPtr) && Tcl_UtfCharComplete(p, endPtr-p)) { - p += TclUtfToUniChar(p, &ch); - *w++ = ch; - } while (p < endPtr) { - *w++ = UCHAR(*p++); + if (Tcl_UtfCharComplete(p, endPtr-p)) { + p += TclUtfToUniChar(p, &ch); + *w++ = ch; + } else { + *w++ = UCHAR(*p++); + } } *w = '\0'; Tcl_DStringSetLength(dsPtr, @@ -628,24 +629,25 @@ Tcl_NumUtfChars( i++; } /* Loop over the remaining string where call must happen */ - while ((src < endPtr) && Tcl_UtfCharComplete(src, endPtr - src)) { + while (src < endPtr) { + if (Tcl_UtfCharComplete(src, endPtr - src)) { #if TCL_UTF_MAX < 4 - if (((unsigned)UCHAR(*src) - 0xF0) < 5) { - /* treat F0 - F4 as single character */ - ch = 0; - src++; - } else + if (((unsigned)UCHAR(*src) - 0xF0) < 5) { + /* treat F0 - F4 as single character */ + ch = 0; + src++; + } else #endif - src += TclUtfToUniChar(src, &ch); + src += TclUtfToUniChar(src, &ch); + } else { + /* + * src points to incomplete UTF-8 sequence + * Treat first byte as character and count it + */ + src++; + } i++; } - if (src < endPtr) { - /* - * String ends in an incomplete UTF-8 sequence. - * Count every byte in it. - */ - i += endPtr - src; - } } return i; } |