summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2021-03-25 23:29:23 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2021-03-25 23:29:23 (GMT)
commitd7b2522f64fd46754b3d322db0eab3794a55672c (patch)
tree8961fa92af7488fdfff7c36bf2ec9e727267dcb2
parentf51ff2529c6dc3248a62625d4fa3e68b558edab2 (diff)
downloadtk-d7b2522f64fd46754b3d322db0eab3794a55672c.zip
tk-d7b2522f64fd46754b3d322db0eab3794a55672c.tar.gz
tk-d7b2522f64fd46754b3d322db0eab3794a55672c.tar.bz2
Add optional argument ?locale?. Only used for the ICU implementation
-rw-r--r--generic/tkIcu.c15
-rw-r--r--library/tk.tcl10
-rw-r--r--macosx/tkMacOSXFont.c12
-rw-r--r--tests/cluster.test15
4 files changed, 37 insertions, 15 deletions
diff --git a/generic/tkIcu.c b/generic/tkIcu.c
index 7c8e066..4e37193 100644
--- a/generic/tkIcu.c
+++ b/generic/tkIcu.c
@@ -83,11 +83,18 @@ startEndOfCmd(
TkSizeT idx;
int flags = PTR2INT(clientData);
const uint16_t *ustr;
+ const char *locale = NULL;
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1 , objv, "str start");
+ 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;
+ }
+ }
Tcl_DStringInit(&ds);
str = Tcl_GetStringFromObj(objv[1], &len);
Tcl_UtfToUniCharDString(str, len, &ds);
@@ -99,7 +106,7 @@ startEndOfCmd(
return TCL_ERROR;
}
- it = icu_open((UBreakIteratorTypex)(flags&3), NULL,
+ it = icu_open((UBreakIteratorTypex)(flags&3), locale,
NULL, -1, &errorCode);
if (it != NULL) {
errorCode = U_ZERO_ERRORZ;
@@ -108,7 +115,7 @@ startEndOfCmd(
}
if (it == NULL || errorCode != U_ZERO_ERRORZ) {
Tcl_DStringFree(&ds);
- Tcl_SetObjResult(interp, Tcl_ObjPrintf("cannot open ICU iterator, errocode: %d", (int)errorCode));
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf("cannot open ICU iterator, errorcode: %d", (int)errorCode));
Tcl_SetErrorCode(interp, "TK", "ICU", "CANNOTOPEN", NULL);
return TCL_ERROR;
}
diff --git a/library/tk.tcl b/library/tk.tcl
index 6571b0d..da388bd 100644
--- a/library/tk.tcl
+++ b/library/tk.tcl
@@ -702,22 +702,22 @@ if {[tk windowingsystem] eq "aqua"} {
}
if {[info commands ::tk::endOfWord] eq ""} {
- proc ::tk::endOfWord {str start} {
+ proc ::tk::endOfWord {str start {locale {}}} {
return [tcl_endOfWord $str $start]
}
}
if {[info commands ::tk::startOfNextWord] eq ""} {
- proc ::tk::startOfNextWord {str start} {
+ proc ::tk::startOfNextWord {str start {locale {}}} {
return [tcl_startOfNextWord $str $start]
}
}
if {[info commands ::tk::startOfPreviousWord] eq ""} {
- proc ::tk::startOfPreviousWord {str start} {
+ proc ::tk::startOfPreviousWord {str start {locale {}}} {
return [tcl_startOfPreviousWord $str $start]
}
}
if {[info commands ::tk::endOfCluster] eq ""} {
- proc ::tk::endOfCluster {str start} {
+ proc ::tk::endOfCluster {str start {locale {}}} {
if {$start eq "end"} {
return [string length $str]
} elseif {$start >= [string length $str]} {
@@ -731,7 +731,7 @@ if {[info commands ::tk::endOfCluster] eq ""} {
}
}
if {[info commands ::tk::startOfCluster] eq ""} {
- proc ::tk::startOfCluster {str start} {
+ proc ::tk::startOfCluster {str start {locale {}}} {
if {$start eq "end"} {
set start [expr {[string length $str]-1}]
} elseif {$start >= [string length $str]} {
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index e775091..79eae2c 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -464,9 +464,9 @@ startOfClusterObjCmd(
int numBytes;
TkSizeT indexArg;
TkSizeT result;
- if ((objc != 3)) {
- Tcl_WrongNumArgs(interp, 1, objv, "string index");
- return TCL_ERROR;
+ if ((unsigned)(objc - 3) > 1) {
+ Tcl_WrongNumArgs(interp, 1 , objv, "str start ?locale?");
+ return TCL_ERROR;
}
stringArg = Tcl_GetStringFromObj(objv[1], &numBytes);
if (stringArg == NULL) {
@@ -505,9 +505,9 @@ endOfClusterObjCmd(
TkSizeT indexArg;
TkSizeT result;
- if ((objc != 3)) {
- Tcl_WrongNumArgs(interp, 1, objv, "string index");
- return TCL_ERROR;
+ if ((unsigned)(objc - 3) > 1) {
+ Tcl_WrongNumArgs(interp, 1 , objv, "str start ?locale?");
+ return TCL_ERROR;
}
stringArg = Tcl_GetStringFromObj(objv[1], &numBytes);
if (stringArg == NULL) {
diff --git a/tests/cluster.test b/tests/cluster.test
index 14e8677..b4403bf 100644
--- a/tests/cluster.test
+++ b/tests/cluster.test
@@ -124,6 +124,21 @@ test cluster-5.7 {::tk::startOfNextWord} -body {
::tk::startOfNextWord "ab cd" end
} -result -1
+test cluster-6.0 {::tk::startOfCluster} -body {
+ ::tk::startOfCluster a b c d
+} -returnCodes 1 -result {wrong # args: should be "::tk::startOfCluster str start ?locale?"}
+test cluster-6.1 {::tk::endOfCluster} -body {
+ ::tk::endOfCluster a b c d
+} -returnCodes 1 -result {wrong # args: should be "::tk::endOfCluster str start ?locale?"}
+test cluster-6.0 {::tk::startOfPreviousWord} -body {
+ ::tk::startOfPreviousWord a b c d
+} -returnCodes 1 -result {wrong # args: should be "::tk::startOfPreviousWord str start ?locale?"}
+test cluster-6.0 {::tk::startOfNextWord} -body {
+ ::tk::startOfNextWord a b c d
+} -returnCodes 1 -result {wrong # args: should be "::tk::startOfNextWord str start ?locale?"}
+test cluster-6.1 {::tk::endOfWord} -body {
+ ::tk::endOfWord a b c d
+} -returnCodes 1 -result {wrong # args: should be "::tk::endOfWord str start ?locale?"}
cleanupTests
return