summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-06-08 12:38:56 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-06-08 12:38:56 (GMT)
commit74d42f2fe9fc80e12aa490ffea731ac8114183b5 (patch)
treea27339ac3118a7718eb23d23b75ffbd9380bbe9a /generic
parent061893f84e1d06c45531c7a4d7a7384e144dc69b (diff)
parent4276e234955e8ecdc91fd5d2ebee1acbb35753ad (diff)
downloadtcl-74d42f2fe9fc80e12aa490ffea731ac8114183b5.zip
tcl-74d42f2fe9fc80e12aa490ffea731ac8114183b5.tar.gz
tcl-74d42f2fe9fc80e12aa490ffea731ac8114183b5.tar.bz2
merge core-8-6-branch
Diffstat (limited to 'generic')
-rw-r--r--generic/tclTest.c2
-rw-r--r--generic/tclUtf.c27
-rw-r--r--generic/tclUtil.c47
3 files changed, 27 insertions, 49 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 547dc9a..ebd90ae 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -6836,7 +6836,7 @@ TestNumUtfCharsCmd(
int len = -1;
if (objc > 2) {
- (void) Tcl_GetStringFromObj(objv[1], &len);
+ (void) Tcl_GetIntFromObj(interp, objv[2], &len);
}
len = Tcl_NumUtfChars(Tcl_GetString(objv[1]), len);
Tcl_SetObjResult(interp, Tcl_NewIntObj(len));
diff --git a/generic/tclUtf.c b/generic/tclUtf.c
index c46d250..161a4bd 100644
--- a/generic/tclUtf.c
+++ b/generic/tclUtf.c
@@ -459,7 +459,6 @@ Tcl_NumUtfChars(
* for strlen(string). */
{
Tcl_UniChar ch;
- register Tcl_UniChar *chPtr = &ch;
register int i;
/*
@@ -472,23 +471,25 @@ Tcl_NumUtfChars(
i = 0;
if (length < 0) {
while (*src != '\0') {
- src += TclUtfToUniChar(src, chPtr);
+ src += TclUtfToUniChar(src, &ch);
i++;
}
+ if (i < 0) i = INT_MAX; /* Bug [2738427] */
} else {
- register int n;
-
- while (length > 0) {
- if (UCHAR(*src) < 0xC0) {
- length--;
- src++;
- } else {
- n = Tcl_UtfToUniChar(src, chPtr);
- length -= n;
- src += n;
- }
+ register const char *endPtr = src + length - TCL_UTF_MAX;
+
+ while (src < endPtr) {
+ src += TclUtfToUniChar(src, &ch);
i++;
}
+ endPtr += TCL_UTF_MAX;
+ while ((src < endPtr) && Tcl_UtfCharComplete(src, endPtr - src)) {
+ src += TclUtfToUniChar(src, &ch);
+ i++;
+ }
+ if (src < endPtr) {
+ i += endPtr - src;
+ }
}
return i;
}
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 91cc3b4..b30a1d0 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -2162,14 +2162,9 @@ Tcl_StringCaseMatch(
* This is a special case optimization for single-byte utf.
*/
- if (UCHAR(*pattern) < 0x80) {
- ch2 = (Tcl_UniChar)
- (nocase ? tolower(UCHAR(*pattern)) : UCHAR(*pattern));
- } else {
- Tcl_UtfToUniChar(pattern, &ch2);
- if (nocase) {
- ch2 = Tcl_UniCharToLower(ch2);
- }
+ TclUtfToUniChar(pattern, &ch2);
+ if (nocase) {
+ ch2 = Tcl_UniCharToLower(ch2);
}
while (1) {
@@ -2235,44 +2230,26 @@ Tcl_StringCaseMatch(
Tcl_UniChar startChar, endChar;
pattern++;
- if (UCHAR(*str) < 0x80) {
- ch1 = (Tcl_UniChar)
- (nocase ? tolower(UCHAR(*str)) : UCHAR(*str));
- str++;
- } else {
- str += Tcl_UtfToUniChar(str, &ch1);
- if (nocase) {
- ch1 = Tcl_UniCharToLower(ch1);
- }
+ str += TclUtfToUniChar(str, &ch1);
+ if (nocase) {
+ ch1 = Tcl_UniCharToLower(ch1);
}
while (1) {
if ((*pattern == ']') || (*pattern == '\0')) {
return 0;
}
- if (UCHAR(*pattern) < 0x80) {
- startChar = (Tcl_UniChar) (nocase
- ? tolower(UCHAR(*pattern)) : UCHAR(*pattern));
- pattern++;
- } else {
- pattern += Tcl_UtfToUniChar(pattern, &startChar);
- if (nocase) {
- startChar = Tcl_UniCharToLower(startChar);
- }
+ pattern += TclUtfToUniChar(pattern, &startChar);
+ if (nocase) {
+ startChar = Tcl_UniCharToLower(startChar);
}
if (*pattern == '-') {
pattern++;
if (*pattern == '\0') {
return 0;
}
- if (UCHAR(*pattern) < 0x80) {
- endChar = (Tcl_UniChar) (nocase
- ? tolower(UCHAR(*pattern)) : UCHAR(*pattern));
- pattern++;
- } else {
- pattern += Tcl_UtfToUniChar(pattern, &endChar);
- if (nocase) {
- endChar = Tcl_UniCharToLower(endChar);
- }
+ pattern += TclUtfToUniChar(pattern, &endChar);
+ if (nocase) {
+ endChar = Tcl_UniCharToLower(endChar);
}
if (((startChar <= ch1) && (ch1 <= endChar))
|| ((endChar <= ch1) && (ch1 <= startChar))) {