diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-03-15 09:21:10 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-03-15 09:21:10 (GMT) |
commit | 4d40a829a939527fa2bcdb95edcc339d6419ff44 (patch) | |
tree | ca82a225b0bcc8d3ab1c1f82ad18106b070d2696 /generic | |
parent | 288aa9fdecd7cd656cdb77ee0a61b4f88f3ec56c (diff) | |
download | tk-4d40a829a939527fa2bcdb95edcc339d6419ff44.zip tk-4d40a829a939527fa2bcdb95edcc339d6419ff44.tar.gz tk-4d40a829a939527fa2bcdb95edcc339d6419ff44.tar.bz2 |
Get rid of hackery function TkUtfPrev(): No longer necessary due to TIP #575
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tkInt.h | 5 | ||||
-rw-r--r-- | generic/tkTextIndex.c | 6 | ||||
-rw-r--r-- | generic/tkUtil.c | 54 |
3 files changed, 11 insertions, 54 deletions
diff --git a/generic/tkInt.h b/generic/tkInt.h index ee453ea..5ef38ab 100644 --- a/generic/tkInt.h +++ b/generic/tkInt.h @@ -1417,14 +1417,13 @@ MODULE_SCOPE void TkUnixSetXftClipRegion(Region clipRegion); # define c_class class #endif -#if TCL_UTF_MAX > 4 +/* Tcl 8.6 has a different definition of Tcl_UniChar than other Tcl versions for TCL_UTF_MAX > 3 */ +#if TCL_UTF_MAX > (3 + (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 6)) # define TkUtfToUniChar(src, ch) (size_t)(((int (*)(const char *, int *))Tcl_UtfToUniChar)(src, ch)) # define TkUniCharToUtf(ch, src) (size_t)(((int (*)(int, char *))Tcl_UniCharToUtf)(ch, src)) -# define TkUtfPrev Tcl_UtfPrev #else MODULE_SCOPE size_t TkUtfToUniChar(const char *, int *); MODULE_SCOPE size_t TkUniCharToUtf(int, char *); - MODULE_SCOPE const char *TkUtfPrev(const char *, const char *); #endif #if defined(_WIN32) && !defined(STATIC_BUILD) && TCL_MAJOR_VERSION < 9 diff --git a/generic/tkTextIndex.c b/generic/tkTextIndex.c index eea8f50..7d55331 100644 --- a/generic/tkTextIndex.c +++ b/generic/tkTextIndex.c @@ -436,7 +436,7 @@ TkTextMakeByteIndex( */ start = segPtr->body.chars + (byteIndex - index); - p = TkUtfPrev(start, segPtr->body.chars); + p = Tcl_UtfPrev(start, segPtr->body.chars); p += TkUtfToUniChar(p, &ch); indexPtr->byteIndex += p - start; } @@ -2126,7 +2126,7 @@ TkTextIndexBackChars( if (segPtr->typePtr == &tkTextCharType) { start = segPtr->body.chars; end = segPtr->body.chars + segSize; - for (p = end; ; p = TkUtfPrev(p, start)) { + for (p = end; ; p = Tcl_UtfPrev(p, start)) { if (charCount == 0) { dstPtr->byteIndex -= (end - p); goto backwardCharDone; @@ -2367,7 +2367,7 @@ StartEnd( } if (offset + 1 > 1) { chSize = (segPtr->body.chars + offset - - TkUtfPrev(segPtr->body.chars + offset, + - Tcl_UtfPrev(segPtr->body.chars + offset, segPtr->body.chars)); } firstChar = 0; diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 1e9c334..da2ce95 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -1196,7 +1196,8 @@ Tk_SendVirtualEvent( Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL); } -#if TCL_UTF_MAX <= 4 +/* Tcl 8.6 has a different definition of Tcl_UniChar than other Tcl versions for TCL_UTF_MAX > 3 */ +#if TCL_UTF_MAX <= (3 + (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 6)) /* *--------------------------------------------------------------------------- * @@ -1225,15 +1226,10 @@ TkUtfToUniChar( Tcl_UniChar uniChar = 0; size_t len = Tcl_UtfToUniChar(src, &uniChar); - if ((sizeof(Tcl_UniChar) == 2) - && ((uniChar & 0xFC00) == 0xD800) -#if TCL_MAJOR_VERSION > 8 - && (len == 1) -#endif - ) { + if ((uniChar & 0xFC00) == 0xD800) { Tcl_UniChar low = uniChar; - /* This can only happen if Tcl is compiled with TCL_UTF_MAX=4, - * or when a high surrogate character is detected in UTF-8 form */ + /* This can only happen if sizeof(Tcl_UniChar)== 2 and src points + * to a character > U+FFFF */ size_t len2 = Tcl_UtfToUniChar(src+len, &low); if ((low & 0xFC00) == 0xDC00) { *chPtr = (((uniChar & 0x3FF) << 10) | (low & 0x3FF)) + 0x10000; @@ -1265,7 +1261,7 @@ TkUtfToUniChar( size_t TkUniCharToUtf(int ch, char *buf) { - if ((sizeof(Tcl_UniChar) == 2) && (((unsigned)(ch - 0x10000) <= 0xFFFFF))) { + if ((unsigned)(ch - 0x10000) <= 0xFFFFF) { /* Spit out a 4-byte UTF-8 character or 2 x 3-byte UTF-8 characters, depending on Tcl * version and/or TCL_UTF_MAX build value */ int len = Tcl_UniCharToUtf(0xD800 | ((ch - 0x10000) >> 10), buf); @@ -1273,44 +1269,6 @@ size_t TkUniCharToUtf(int ch, char *buf) } return Tcl_UniCharToUtf(ch, buf); } -/* - *--------------------------------------------------------------------------- - * - * TkUtfPrev -- - * - * Almost the same as Tcl_UtfPrev. - * This function is capable of jumping over a upper/lower surrogate pair. - * So, might jump back up to 6 bytes. - * - * Results: - * pointer to the first byte of the current UTF-8 character. A surrogate - * pair is also handled as being a single entity. - * - * Side effects: - * None. - * - *--------------------------------------------------------------------------- - */ - -const char * -TkUtfPrev( - const char *src, /* The UTF-8 string. */ - const char *start) /* Start position of string */ -{ - const char *p = Tcl_UtfPrev(src, start); - const char *first = Tcl_UtfPrev(p, start); - int ch; - -#if TCL_UTF_MAX == 3 - if ((src - start > 3) && ((src[-1] & 0xC0) == 0x80) && ((src[-2] & 0xC0) == 0x80) - && ((src[-3] & 0xC0) == 0x80) && (UCHAR(src[-4]) >= 0xF0)) { - return src - 4; - } -#endif - - return (first + TkUtfToUniChar(first, &ch) >= src) ? first : p ; -} - #endif /* * Local Variables: |