Skip to content

Commit 3c89e1b

Browse files
committed
regexp, regsub: sort -- after all other options
This matches Tcl 9.0 Signed-off-by: Steve Bennett <[email protected]>
1 parent 20b1ff5 commit 3c89e1b

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

jim.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,11 +3142,21 @@ int Jim_CompareStringImmediate(Jim_Interp *interp, Jim_Obj *objPtr, const char *
31423142
}
31433143
}
31443144

3145+
/* Note that we explicitly sort -- after other options */
31453146
static int qsortCompareStringPointers(const void *a, const void *b)
31463147
{
31473148
char *const *sa = (char *const *)a;
31483149
char *const *sb = (char *const *)b;
31493150

3151+
/* Always sort "--" to the end to match Tcl 9.0 */
3152+
if (strcmp(*sa, "--") == 0) {
3153+
return 1;
3154+
}
3155+
if (strcmp(*sb, "--") == 0) {
3156+
/* Always sort "--" to the end */
3157+
return -1;
3158+
}
3159+
31503160
return strcmp(*sa, *sb);
31513161
}
31523162

tests/regexp.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ test regexp-6.2 {regexp errors} -body {
203203

204204
test regexp-6.3 {regexp errors} -constraints jim -body {
205205
list [catch {regexp -gorp a} msg] $msg
206-
} -result {1 {bad option "-gorp": must be --, -all, -expanded, -indices, -inline, -line, -nocase, or -start}}
206+
} -result {1 {bad option "-gorp": must be -all, -expanded, -indices, -inline, -line, -nocase, -start, or --}}
207+
207208
test regexp-6.4 {regexp errors} {
208209
catch {regexp a( b} msg
209210
} 1
@@ -368,9 +369,10 @@ test regexp-11.3 {regsub errors} {
368369
test regexp-11.4 {regsub errors} {
369370
list [catch {regsub a b c d e f} msg] $msg
370371
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
372+
371373
test regexp-11.5 {regsub errors} -constraints jim -body {
372374
list [catch {regsub -gorp a b c} msg] $msg
373-
} -result {1 {bad option "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
375+
} -result {1 {bad option "-gorp": must be -all, -command, -expanded, -line, -nocase, -start, or --}}
374376

375377
test regexp-11.5 {regsub errors} -constraints tcl -body {
376378
list [catch {regsub -gorp a b c} msg] $msg

tests/regexp2.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,13 @@ test regexpComp-11.4 {regsub errors} {
523523
list [catch {regsub a b c d e f} msg] $msg
524524
}
525525
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
526-
test regexpComp-11.5 {regsub errors} {
526+
527+
test regexpComp-11.5 {regsub errors} -body {
527528
evalInProc {
528529
list [catch {regsub -gorp a b c} msg] $msg
529530
}
530-
} {1 {bad option "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
531+
} -result {1 {bad option "-gorp": must be -all, -command, -expanded, -line, -nocase, -start, or --}}
532+
531533
test regexpComp-11.6 {regsub errors} {
532534
evalInProc {
533535
list [catch {regsub -nocase a( b c d} msg] $msg

0 commit comments

Comments
 (0)