diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2025-12-02 13:02:35 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2025-12-02 13:02:35 (GMT) |
| commit | 5f719b0c9af9a340ce150cccf299c8f3464d6b85 (patch) | |
| tree | def9bd3026f3c3db9291adf44bd624bea9092369 | |
| parent | cb4270cb000ccc68d8b9642a05254697f835b206 (diff) | |
| download | tk-core-bug-095db8b350.zip tk-core-bug-095db8b350.tar.gz tk-core-bug-095db8b350.tar.bz2 | |
Fix [095db8b350]: ::tk::startOfCluster (and friends) only understand ICU locale syntaxcore-bug-095db8b350
| -rw-r--r-- | generic/tkIcu.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/generic/tkIcu.c b/generic/tkIcu.c index d0a528f..a833aff 100644 --- a/generic/tkIcu.c +++ b/generic/tkIcu.c @@ -32,6 +32,7 @@ typedef int32_t (*fn_icu_following)(void *, int32_t); typedef int32_t (*fn_icu_previous)(void *); typedef int32_t (*fn_icu_next)(void *); typedef void (*fn_icu_setText)(void *, const void *, int32_t, UErrorCodex *); +typedef int32_t (*fn_icu_canonicalize)(const char *, char *, int32_t, UErrorCodex *); static struct { size_t nopen; @@ -43,8 +44,9 @@ static struct { fn_icu_previous previous; fn_icu_next next; fn_icu_setText setText; + fn_icu_canonicalize canonicalize; } icu_fns = { - 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL + 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; #define FLAG_WORD 1 @@ -58,6 +60,7 @@ static struct { #define icu_previous icu_fns.previous #define icu_next icu_fns.next #define icu_setText icu_fns.setText +#define icu_canonicalize icu_fns.canonicalize TCL_DECLARE_MUTEX(icu_mutex); @@ -76,17 +79,22 @@ startEndOfCmd( Tcl_Size idx; int flags = PTR2INT(clientData); const uint16_t *ustr; - const char *locale = NULL; + char locale[128]; if ((unsigned)(objc - 3) > 1) { Tcl_WrongNumArgs(interp, 1 , objv, "str start ?locale?"); return TCL_ERROR; } if (objc > 3) { - locale = Tcl_GetString(objv[3]); - if (!*locale) { - locale = NULL; + locale[0] = '\0'; + if (!TkObjIsEmpty(objv[3]) && icu_canonicalize) { + icu_canonicalize(Tcl_GetString(objv[3]), locale, sizeof(locale), &errorCode); + } else { + strncpy(locale, Tcl_GetString(objv[3]), sizeof(locale)); } + locale[sizeof(locale) - 1] = '\0'; + } else { + locale[0] = '\0'; } Tcl_DStringInit(&ds); str = Tcl_GetStringFromObj(objv[1], &len); @@ -99,7 +107,7 @@ startEndOfCmd( Tcl_SetErrorCode(interp, "TK", "ICU", "INDEX", (char *)NULL); return TCL_ERROR; } - it = icu_open((UBreakIteratorTypex)(flags&3), locale, + it = icu_open((UBreakIteratorTypex)(flags&3), locale[0] ? locale : NULL, NULL, -1, &errorCode); if (it != NULL) { errorCode = U_ZERO_ERRORZ; @@ -298,6 +306,10 @@ Icu_Init( ICU_SYM(previous); ICU_SYM(next); ICU_SYM(setText); + strcpy(symbol, "uloc_canonicalize"); + strcat(symbol, icuversion); + icu_fns.canonicalize = (fn_icu_canonicalize) + Tcl_FindSymbol(NULL, icu_fns.lib, symbol); #undef ICU_SYM } } |
