aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2025-08-09 13:56:38 +1000
committerSteve Bennett <steveb@workware.net.au>2025-08-13 08:05:25 +1000
commit3c89e1bffa6fa0d7e66657a0ab7a29a1066dc536 (patch)
tree1cca894fd6ae502ec929e7a0bb02bc4b3d357fef
parent20b1ff593a51237d3a477c869815839d6ac526ae (diff)
downloadjimtcl-3c89e1bffa6fa0d7e66657a0ab7a29a1066dc536.zip
jimtcl-3c89e1bffa6fa0d7e66657a0ab7a29a1066dc536.tar.gz
jimtcl-3c89e1bffa6fa0d7e66657a0ab7a29a1066dc536.tar.bz2
regexp, regsub: sort -- after all other options
This matches Tcl 9.0 Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim.c10
-rw-r--r--tests/regexp.test6
-rw-r--r--tests/regexp2.test6
3 files changed, 18 insertions, 4 deletions
diff --git a/jim.c b/jim.c
index fd38080..0e78f1c 100644
--- a/jim.c
+++ b/jim.c
@@ -3142,11 +3142,21 @@ int Jim_CompareStringImmediate(Jim_Interp *interp, Jim_Obj *objPtr, const char *
}
}
+/* Note that we explicitly sort -- after other options */
static int qsortCompareStringPointers(const void *a, const void *b)
{
char *const *sa = (char *const *)a;
char *const *sb = (char *const *)b;
+ /* Always sort "--" to the end to match Tcl 9.0 */
+ if (strcmp(*sa, "--") == 0) {
+ return 1;
+ }
+ if (strcmp(*sb, "--") == 0) {
+ /* Always sort "--" to the end */
+ return -1;
+ }
+
return strcmp(*sa, *sb);
}
diff --git a/tests/regexp.test b/tests/regexp.test
index 5adcaf3..681b793 100644
--- a/tests/regexp.test
+++ b/tests/regexp.test
@@ -203,7 +203,8 @@ test regexp-6.2 {regexp errors} -body {
test regexp-6.3 {regexp errors} -constraints jim -body {
list [catch {regexp -gorp a} msg] $msg
-} -result {1 {bad option "-gorp": must be --, -all, -expanded, -indices, -inline, -line, -nocase, or -start}}
+} -result {1 {bad option "-gorp": must be -all, -expanded, -indices, -inline, -line, -nocase, -start, or --}}
+
test regexp-6.4 {regexp errors} {
catch {regexp a( b} msg
} 1
@@ -368,9 +369,10 @@ test regexp-11.3 {regsub errors} {
test regexp-11.4 {regsub errors} {
list [catch {regsub a b c d e f} msg] $msg
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
+
test regexp-11.5 {regsub errors} -constraints jim -body {
list [catch {regsub -gorp a b c} msg] $msg
-} -result {1 {bad option "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
+} -result {1 {bad option "-gorp": must be -all, -command, -expanded, -line, -nocase, -start, or --}}
test regexp-11.5 {regsub errors} -constraints tcl -body {
list [catch {regsub -gorp a b c} msg] $msg
diff --git a/tests/regexp2.test b/tests/regexp2.test
index b61d768..2b8e2bc 100644
--- a/tests/regexp2.test
+++ b/tests/regexp2.test
@@ -523,11 +523,13 @@ test regexpComp-11.4 {regsub errors} {
list [catch {regsub a b c d e f} msg] $msg
}
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
-test regexpComp-11.5 {regsub errors} {
+
+test regexpComp-11.5 {regsub errors} -body {
evalInProc {
list [catch {regsub -gorp a b c} msg] $msg
}
-} {1 {bad option "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
+} -result {1 {bad option "-gorp": must be -all, -command, -expanded, -line, -nocase, -start, or --}}
+
test regexpComp-11.6 {regsub errors} {
evalInProc {
list [catch {regsub -nocase a( b c d} msg] $msg