diff options
author | dgp <dgp@users.sourceforge.net> | 2020-05-07 21:47:28 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2020-05-07 21:47:28 (GMT) |
commit | 752f99d5762c8c78c12d48f81c36d7f2a4914e37 (patch) | |
tree | f894c2ee9fda48235ef2379adcdf5e99bf78546a /generic/tclUtf.c | |
parent | 6d36267ee03ebbf37b1843d0602220bbc299f8e9 (diff) | |
parent | 236622c790c99057427a8bc4fb83867cfbf4bc04 (diff) | |
download | tcl-752f99d5762c8c78c12d48f81c36d7f2a4914e37.zip tcl-752f99d5762c8c78c12d48f81c36d7f2a4914e37.tar.gz tcl-752f99d5762c8c78c12d48f81c36d7f2a4914e37.tar.bz2 |
Merge changes from parent branch
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r-- | generic/tclUtf.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 8ae4b15..b855844 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, @@ -621,17 +622,18 @@ Tcl_NumUtfChars( i++; } /* Loop over the remaining string where call must happen */ - while ((src < endPtr) && Tcl_UtfCharComplete(src, endPtr - src)) { - src += TclUtfToUniChar(src, &ch); + while (src < endPtr) { + if (Tcl_UtfCharComplete(src, endPtr - src)) { + 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; } |