Tcl Source Code

Check-in [de104ef5ab]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add string-14.18 to test that [string replace] with last<first does not insert a string, even though we might wish that it did, to be in compliance with the documented behavior. Correct non-bytecoded [string replace] accordingly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | amg-string-insert
Files: files | file ages | folders
SHA1: de104ef5aba3706ed72f22c76c3398f8367458b7
User & Date: andy 2017-08-20 03:45:19
References
2017-08-30
15:29
Cherrypick string.test [de104ef5ab] check-in: c649c52458 user: andy tags: trunk
Context
2017-08-30
15:29
Cherrypick string.test [de104ef5ab] check-in: c649c52458 user: andy tags: trunk
2017-08-20
18:13
Add non-bytecoded [string replace] tests to exercise new TclStringReplace() function check-in: 9af4defa79 user: andy tags: amg-string-insert
03:45
Add string-14.18 to test that [string replace] with last<first does not insert a string, even though... check-in: de104ef5ab user: andy tags: amg-string-insert
03:21
Reimplement NON-BYTECODED [string replace] in terms of new TclStringReplace() function check-in: c0036938dd user: andy tags: amg-string-insert
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclCmdMZ.c.

2369
2370
2371
2372
2373
2374
2375






2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396

    strObj = objv[1];
    length = Tcl_GetCharLength(strObj) - 1;
    if (TclGetIntForIndexM(interp, objv[2], length, &first) != TCL_OK
     || TclGetIntForIndexM(interp, objv[3], length, &last) != TCL_OK) {
	return TCL_ERROR;
    }







    if (first < 0) {
	first = 0;
    }

    if (last >= first) {
	del = last - first + 1;
    } else {
	del = 0;
    }

    if (objc == 5) {
	insObj = objv[4];
    } else {
	insObj = NULL;
    }

    if (!(outObj = TclStringReplace(interp, strObj, first, del, insObj))) {
	return TCL_ERROR;
    }








>
>
>
>
>
>









<
<
<
<
<







2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390





2391
2392
2393
2394
2395
2396
2397

    strObj = objv[1];
    length = Tcl_GetCharLength(strObj) - 1;
    if (TclGetIntForIndexM(interp, objv[2], length, &first) != TCL_OK
     || TclGetIntForIndexM(interp, objv[3], length, &last) != TCL_OK) {
	return TCL_ERROR;
    }

    if (objc == 5) {
	insObj = objv[4];
    } else {
	insObj = NULL;
    }

    if (first < 0) {
	first = 0;
    }

    if (last >= first) {
	del = last - first + 1;
    } else {
	del = 0;





	insObj = NULL;
    }

    if (!(outObj = TclStringReplace(interp, strObj, first, del, insObj))) {
	return TCL_ERROR;
    }

Changes to tests/string.test.

1367
1368
1369
1370
1371
1372
1373



1374
1375
1376
1377
1378
1379
1380
} {abcdeNEWop}
test string-14.16 {string replace} {
    string replace abcdefghijklmnop 0 end foo
} {foo}
test string-14.17 {string replace} {
    string replace abcdefghijklmnop end end-1
} {abcdefghijklmnop}




test string-15.1 {string tolower too few args} {
    list [catch {string tolower} msg] $msg
} {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
test string-15.2 {string tolower bad args} {
    list [catch {string tolower a b} msg] $msg
} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}







>
>
>







1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
} {abcdeNEWop}
test string-14.16 {string replace} {
    string replace abcdefghijklmnop 0 end foo
} {foo}
test string-14.17 {string replace} {
    string replace abcdefghijklmnop end end-1
} {abcdefghijklmnop}
test string-14.18 {string replace} {
    string replace abcdefghijklmnop 10 9 XXX
} {abcdefghijklmnop}

test string-15.1 {string tolower too few args} {
    list [catch {string tolower} msg] $msg
} {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
test string-15.2 {string tolower bad args} {
    list [catch {string tolower a b} msg] $msg
} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}