Fossil SCM

Add docs and tests for the TH1 'string index' command added by check-in [0c57ba3eb4]. Also, fix issue with handling of the special 'end' index.

mistachkin 2017-10-02 15:23 trunk
Commit e9845e590456d23b168ec24ecdacf4e00bf071fecff65197f16f99af6d4fed5b
+1 -1
--- src/th_lang.c
+++ src/th_lang.c
@@ -731,11 +731,11 @@
731731
if( argc!=4 ){
732732
return Th_WrongNumArgs(interp, "string index string index");
733733
}
734734
735735
if( argl[3]==3 && 0==memcmp("end", argv[3], 3) ){
736
- iIndex = argl[2];
736
+ iIndex = argl[2]-1;
737737
}else if( Th_ToInt(interp, argv[3], argl[3], &iIndex) ){
738738
Th_ErrorMessage(
739739
interp, "Expected \"end\" or integer, got:", argv[3], argl[3]);
740740
return TH_ERROR;
741741
}
742742
--- src/th_lang.c
+++ src/th_lang.c
@@ -731,11 +731,11 @@
731 if( argc!=4 ){
732 return Th_WrongNumArgs(interp, "string index string index");
733 }
734
735 if( argl[3]==3 && 0==memcmp("end", argv[3], 3) ){
736 iIndex = argl[2];
737 }else if( Th_ToInt(interp, argv[3], argl[3], &iIndex) ){
738 Th_ErrorMessage(
739 interp, "Expected \"end\" or integer, got:", argv[3], argl[3]);
740 return TH_ERROR;
741 }
742
--- src/th_lang.c
+++ src/th_lang.c
@@ -731,11 +731,11 @@
731 if( argc!=4 ){
732 return Th_WrongNumArgs(interp, "string index string index");
733 }
734
735 if( argl[3]==3 && 0==memcmp("end", argv[3], 3) ){
736 iIndex = argl[2]-1;
737 }else if( Th_ToInt(interp, argv[3], argl[3], &iIndex) ){
738 Th_ErrorMessage(
739 interp, "Expected \"end\" or integer, got:", argv[3], argl[3]);
740 return TH_ERROR;
741 }
742
--- test/th1.test
+++ test/th1.test
@@ -1433,10 +1433,85 @@
14331433
14341434
###############################################################################
14351435
14361436
fossil test-th-eval {string is integer 0xC0DEF00Z}
14371437
test th1-string-is-31 {$RESULT eq "0"}
1438
+
1439
+###############################################################################
1440
+
1441
+fossil test-th-eval {string index "" -1}
1442
+test th1-string-index-1 {$RESULT eq ""}
1443
+
1444
+###############################################################################
1445
+
1446
+fossil test-th-eval {string index "" 0}
1447
+test th1-string-index-2 {$RESULT eq ""}
1448
+
1449
+###############################################################################
1450
+
1451
+fossil test-th-eval {string index "" 1}
1452
+test th1-string-index-3 {$RESULT eq ""}
1453
+
1454
+###############################################################################
1455
+
1456
+fossil test-th-eval {string index "" 2}
1457
+test th1-string-index-4 {$RESULT eq ""}
1458
+
1459
+###############################################################################
1460
+
1461
+fossil test-th-eval {string index "" end}
1462
+test th1-string-index-5 {$RESULT eq ""}
1463
+
1464
+###############################################################################
1465
+
1466
+fossil test-th-eval {string index A -1}
1467
+test th1-string-index-6 {$RESULT eq ""}
1468
+
1469
+###############################################################################
1470
+
1471
+fossil test-th-eval {string index A 0}
1472
+test th1-string-index-7 {$RESULT eq "A"}
1473
+
1474
+###############################################################################
1475
+
1476
+fossil test-th-eval {string index A 1}
1477
+test th1-string-index-8 {$RESULT eq ""}
1478
+
1479
+###############################################################################
1480
+
1481
+fossil test-th-eval {string index A 2}
1482
+test th1-string-index-9 {$RESULT eq ""}
1483
+
1484
+###############################################################################
1485
+
1486
+fossil test-th-eval {string index A end}
1487
+test th1-string-index-10 {$RESULT eq "A"}
1488
+
1489
+###############################################################################
1490
+
1491
+fossil test-th-eval {string index ABC -1}
1492
+test th1-string-index-11 {$RESULT eq ""}
1493
+
1494
+###############################################################################
1495
+
1496
+fossil test-th-eval {string index ABC 0}
1497
+test th1-string-index-12 {$RESULT eq "A"}
1498
+
1499
+###############################################################################
1500
+
1501
+fossil test-th-eval {string index ABC 1}
1502
+test th1-string-index-13 {$RESULT eq "B"}
1503
+
1504
+###############################################################################
1505
+
1506
+fossil test-th-eval {string index ABC 2}
1507
+test th1-string-index-14 {$RESULT eq "C"}
1508
+
1509
+###############################################################################
1510
+
1511
+fossil test-th-eval {string index ABC end}
1512
+test th1-string-index-15 {$RESULT eq "C"}
14381513
14391514
###############################################################################
14401515
14411516
fossil test-th-eval {markdown}
14421517
test th1-markdown-1 {$RESULT eq \
14431518
--- test/th1.test
+++ test/th1.test
@@ -1433,10 +1433,85 @@
1433
1434 ###############################################################################
1435
1436 fossil test-th-eval {string is integer 0xC0DEF00Z}
1437 test th1-string-is-31 {$RESULT eq "0"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1438
1439 ###############################################################################
1440
1441 fossil test-th-eval {markdown}
1442 test th1-markdown-1 {$RESULT eq \
1443
--- test/th1.test
+++ test/th1.test
@@ -1433,10 +1433,85 @@
1433
1434 ###############################################################################
1435
1436 fossil test-th-eval {string is integer 0xC0DEF00Z}
1437 test th1-string-is-31 {$RESULT eq "0"}
1438
1439 ###############################################################################
1440
1441 fossil test-th-eval {string index "" -1}
1442 test th1-string-index-1 {$RESULT eq ""}
1443
1444 ###############################################################################
1445
1446 fossil test-th-eval {string index "" 0}
1447 test th1-string-index-2 {$RESULT eq ""}
1448
1449 ###############################################################################
1450
1451 fossil test-th-eval {string index "" 1}
1452 test th1-string-index-3 {$RESULT eq ""}
1453
1454 ###############################################################################
1455
1456 fossil test-th-eval {string index "" 2}
1457 test th1-string-index-4 {$RESULT eq ""}
1458
1459 ###############################################################################
1460
1461 fossil test-th-eval {string index "" end}
1462 test th1-string-index-5 {$RESULT eq ""}
1463
1464 ###############################################################################
1465
1466 fossil test-th-eval {string index A -1}
1467 test th1-string-index-6 {$RESULT eq ""}
1468
1469 ###############################################################################
1470
1471 fossil test-th-eval {string index A 0}
1472 test th1-string-index-7 {$RESULT eq "A"}
1473
1474 ###############################################################################
1475
1476 fossil test-th-eval {string index A 1}
1477 test th1-string-index-8 {$RESULT eq ""}
1478
1479 ###############################################################################
1480
1481 fossil test-th-eval {string index A 2}
1482 test th1-string-index-9 {$RESULT eq ""}
1483
1484 ###############################################################################
1485
1486 fossil test-th-eval {string index A end}
1487 test th1-string-index-10 {$RESULT eq "A"}
1488
1489 ###############################################################################
1490
1491 fossil test-th-eval {string index ABC -1}
1492 test th1-string-index-11 {$RESULT eq ""}
1493
1494 ###############################################################################
1495
1496 fossil test-th-eval {string index ABC 0}
1497 test th1-string-index-12 {$RESULT eq "A"}
1498
1499 ###############################################################################
1500
1501 fossil test-th-eval {string index ABC 1}
1502 test th1-string-index-13 {$RESULT eq "B"}
1503
1504 ###############################################################################
1505
1506 fossil test-th-eval {string index ABC 2}
1507 test th1-string-index-14 {$RESULT eq "C"}
1508
1509 ###############################################################################
1510
1511 fossil test-th-eval {string index ABC end}
1512 test th1-string-index-15 {$RESULT eq "C"}
1513
1514 ###############################################################################
1515
1516 fossil test-th-eval {markdown}
1517 test th1-markdown-1 {$RESULT eq \
1518
+1
--- www/th1.md
+++ www/th1.md
@@ -105,10 +105,11 @@
105105
* rename OLD NEW
106106
* return ?-code CODE? ?VALUE?
107107
* set VARNAME VALUE
108108
* string compare STR1 STR2
109109
* string first NEEDLE HAYSTACK ?START-INDEX?
110
+ * string index STRING INDEX
110111
* string is CLASS STRING
111112
* string last NEEDLE HAYSTACK ?START-INDEX?
112113
* string length STRING
113114
* string range STRING FIRST LAST
114115
* string repeat STRING COUNT
115116
--- www/th1.md
+++ www/th1.md
@@ -105,10 +105,11 @@
105 * rename OLD NEW
106 * return ?-code CODE? ?VALUE?
107 * set VARNAME VALUE
108 * string compare STR1 STR2
109 * string first NEEDLE HAYSTACK ?START-INDEX?
 
110 * string is CLASS STRING
111 * string last NEEDLE HAYSTACK ?START-INDEX?
112 * string length STRING
113 * string range STRING FIRST LAST
114 * string repeat STRING COUNT
115
--- www/th1.md
+++ www/th1.md
@@ -105,10 +105,11 @@
105 * rename OLD NEW
106 * return ?-code CODE? ?VALUE?
107 * set VARNAME VALUE
108 * string compare STR1 STR2
109 * string first NEEDLE HAYSTACK ?START-INDEX?
110 * string index STRING INDEX
111 * string is CLASS STRING
112 * string last NEEDLE HAYSTACK ?START-INDEX?
113 * string length STRING
114 * string range STRING FIRST LAST
115 * string repeat STRING COUNT
116

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button