Fossil SCM

Add 'list' class to the 'string is' command in TH1.

mistachkin 2015-07-15 00:31 trunk
Commit c3ffd0e3960934e337f2c87ec3ab62515fb59d50
+18 -12
--- src/th_lang.c
+++ src/th_lang.c
@@ -722,27 +722,33 @@
722722
** string is CLASS STRING
723723
*/
724724
static int string_is_command(
725725
Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
726726
){
727
- int i;
728
- int iRes = 1;
729727
if( argc!=4 ){
730728
return Th_WrongNumArgs(interp, "string is class string");
731729
}
732
- if( argl[2]!=5 || 0!=memcmp(argv[2], "alnum", 5) ){
733
- Th_ErrorMessage(interp, "Expected alnum, got: ", argv[2], argl[2]);
730
+ if( argl[2]==5 && 0==memcmp(argv[2], "alnum", 5) ){
731
+ int i;
732
+ int iRes = 1;
733
+
734
+ for(i=0; i<argl[3]; i++){
735
+ if( !th_isalnum(argv[3][i]) ){
736
+ iRes = 0;
737
+ }
738
+ }
739
+
740
+ return Th_SetResultInt(interp, iRes);
741
+ }else if( argl[2]==4 && 0==memcmp(argv[2], "list", 4) ){
742
+ if( Th_SplitList(interp, argv[3], argl[3], 0, 0, 0)==TH_OK ){
743
+ return Th_SetResultInt(interp, 1);
744
+ }
745
+ return Th_SetResultInt(interp, 0);
746
+ }else{
747
+ Th_ErrorMessage(interp, "Expected alnum or list, got:", argv[2], argl[2]);
734748
return TH_ERROR;
735749
}
736
-
737
- for(i=0; i<argl[3]; i++){
738
- if( !th_isalnum(argv[3][i]) ){
739
- iRes = 0;
740
- }
741
- }
742
-
743
- return Th_SetResultInt(interp, iRes);
744750
}
745751
746752
/*
747753
** TH Syntax:
748754
**
749755
--- src/th_lang.c
+++ src/th_lang.c
@@ -722,27 +722,33 @@
722 ** string is CLASS STRING
723 */
724 static int string_is_command(
725 Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
726 ){
727 int i;
728 int iRes = 1;
729 if( argc!=4 ){
730 return Th_WrongNumArgs(interp, "string is class string");
731 }
732 if( argl[2]!=5 || 0!=memcmp(argv[2], "alnum", 5) ){
733 Th_ErrorMessage(interp, "Expected alnum, got: ", argv[2], argl[2]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734 return TH_ERROR;
735 }
736
737 for(i=0; i<argl[3]; i++){
738 if( !th_isalnum(argv[3][i]) ){
739 iRes = 0;
740 }
741 }
742
743 return Th_SetResultInt(interp, iRes);
744 }
745
746 /*
747 ** TH Syntax:
748 **
749
--- src/th_lang.c
+++ src/th_lang.c
@@ -722,27 +722,33 @@
722 ** string is CLASS STRING
723 */
724 static int string_is_command(
725 Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
726 ){
 
 
727 if( argc!=4 ){
728 return Th_WrongNumArgs(interp, "string is class string");
729 }
730 if( argl[2]==5 && 0==memcmp(argv[2], "alnum", 5) ){
731 int i;
732 int iRes = 1;
733
734 for(i=0; i<argl[3]; i++){
735 if( !th_isalnum(argv[3][i]) ){
736 iRes = 0;
737 }
738 }
739
740 return Th_SetResultInt(interp, iRes);
741 }else if( argl[2]==4 && 0==memcmp(argv[2], "list", 4) ){
742 if( Th_SplitList(interp, argv[3], argl[3], 0, 0, 0)==TH_OK ){
743 return Th_SetResultInt(interp, 1);
744 }
745 return Th_SetResultInt(interp, 0);
746 }else{
747 Th_ErrorMessage(interp, "Expected alnum or list, got:", argv[2], argl[2]);
748 return TH_ERROR;
749 }
 
 
 
 
 
 
 
 
750 }
751
752 /*
753 ** TH Syntax:
754 **
755
--- test/th1.test
+++ test/th1.test
@@ -1012,5 +1012,99 @@
10121012
10131013
###############################################################################
10141014
10151015
fossil test-th-eval {list [glob_match {a[bd]c} abc] [glob_match abc {a[bd]c}]}
10161016
test th1-glob-match-13 {$RESULT eq "1 0"}
1017
+
1018
+###############################################################################
1019
+
1020
+fossil test-th-eval {string is}
1021
+test th1-string-is-1 {$RESULT eq \
1022
+{TH_ERROR: wrong # args: should be "string is class string"}}
1023
+
1024
+###############################################################################
1025
+
1026
+fossil test-th-eval {string is something}
1027
+test th1-string-is-2 {$RESULT eq \
1028
+{TH_ERROR: wrong # args: should be "string is class string"}}
1029
+
1030
+###############################################################################
1031
+
1032
+fossil test-th-eval {string is not something else}
1033
+test th1-string-is-3 {$RESULT eq \
1034
+{TH_ERROR: wrong # args: should be "string is class string"}}
1035
+
1036
+###############################################################################
1037
+
1038
+fossil test-th-eval {string is other 123}
1039
+test th1-string-is-4 {$RESULT eq \
1040
+"TH_ERROR: Expected alnum or list, got: other"}
1041
+
1042
+###############################################################################
1043
+
1044
+fossil test-th-eval {string is alnum 123}
1045
+test th1-string-is-5 {$RESULT eq "1"}
1046
+
1047
+###############################################################################
1048
+
1049
+fossil test-th-eval {string is alnum abc}
1050
+test th1-string-is-6 {$RESULT eq "1"}
1051
+
1052
+###############################################################################
1053
+
1054
+fossil test-th-eval {string is alnum 123abc}
1055
+test th1-string-is-7 {$RESULT eq "1"}
1056
+
1057
+###############################################################################
1058
+
1059
+fossil test-th-eval {string is alnum abc123}
1060
+test th1-string-is-8 {$RESULT eq "1"}
1061
+
1062
+###############################################################################
1063
+
1064
+fossil test-th-eval {string is alnum _abc123}
1065
+test th1-string-is-9 {$RESULT eq "0"}
1066
+
1067
+###############################################################################
1068
+
1069
+fossil test-th-eval {string is alnum abc.123}
1070
+test th1-string-is-10 {$RESULT eq "0"}
1071
+
1072
+###############################################################################
1073
+
1074
+fossil test-th-eval {string is alnum abc123_}
1075
+test th1-string-is-11 {$RESULT eq "0"}
1076
+
1077
+###############################################################################
1078
+
1079
+fossil test-th-eval {string is list ""}
1080
+test th1-string-is-12 {$RESULT eq "1"}
1081
+
1082
+###############################################################################
1083
+
1084
+fossil test-th-eval {string is list 1}
1085
+test th1-string-is-13 {$RESULT eq "1"}
1086
+
1087
+###############################################################################
1088
+
1089
+fossil test-th-eval {string is list "1 2 3"}
1090
+test th1-string-is-14 {$RESULT eq "1"}
1091
+
1092
+###############################################################################
1093
+
1094
+fossil test-th-eval {string is list "\{"}
1095
+test th1-string-is-15 {$RESULT eq "0"}
1096
+
1097
+###############################################################################
1098
+
1099
+fossil test-th-eval {string is list "1 2 3 \{"}
1100
+test th1-string-is-16 {$RESULT eq "0"}
1101
+
1102
+###############################################################################
1103
+
1104
+fossil test-th-eval {string is list "1 2 3 \{\}"}
1105
+test th1-string-is-17 {$RESULT eq "1"}
1106
+
1107
+###############################################################################
1108
+
1109
+fossil test-th-eval {string is list "1 2 3 \{\{\}"}
1110
+test th1-string-is-18 {$RESULT eq "0"}
10171111
--- test/th1.test
+++ test/th1.test
@@ -1012,5 +1012,99 @@
1012
1013 ###############################################################################
1014
1015 fossil test-th-eval {list [glob_match {a[bd]c} abc] [glob_match abc {a[bd]c}]}
1016 test th1-glob-match-13 {$RESULT eq "1 0"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
--- test/th1.test
+++ test/th1.test
@@ -1012,5 +1012,99 @@
1012
1013 ###############################################################################
1014
1015 fossil test-th-eval {list [glob_match {a[bd]c} abc] [glob_match abc {a[bd]c}]}
1016 test th1-glob-match-13 {$RESULT eq "1 0"}
1017
1018 ###############################################################################
1019
1020 fossil test-th-eval {string is}
1021 test th1-string-is-1 {$RESULT eq \
1022 {TH_ERROR: wrong # args: should be "string is class string"}}
1023
1024 ###############################################################################
1025
1026 fossil test-th-eval {string is something}
1027 test th1-string-is-2 {$RESULT eq \
1028 {TH_ERROR: wrong # args: should be "string is class string"}}
1029
1030 ###############################################################################
1031
1032 fossil test-th-eval {string is not something else}
1033 test th1-string-is-3 {$RESULT eq \
1034 {TH_ERROR: wrong # args: should be "string is class string"}}
1035
1036 ###############################################################################
1037
1038 fossil test-th-eval {string is other 123}
1039 test th1-string-is-4 {$RESULT eq \
1040 "TH_ERROR: Expected alnum or list, got: other"}
1041
1042 ###############################################################################
1043
1044 fossil test-th-eval {string is alnum 123}
1045 test th1-string-is-5 {$RESULT eq "1"}
1046
1047 ###############################################################################
1048
1049 fossil test-th-eval {string is alnum abc}
1050 test th1-string-is-6 {$RESULT eq "1"}
1051
1052 ###############################################################################
1053
1054 fossil test-th-eval {string is alnum 123abc}
1055 test th1-string-is-7 {$RESULT eq "1"}
1056
1057 ###############################################################################
1058
1059 fossil test-th-eval {string is alnum abc123}
1060 test th1-string-is-8 {$RESULT eq "1"}
1061
1062 ###############################################################################
1063
1064 fossil test-th-eval {string is alnum _abc123}
1065 test th1-string-is-9 {$RESULT eq "0"}
1066
1067 ###############################################################################
1068
1069 fossil test-th-eval {string is alnum abc.123}
1070 test th1-string-is-10 {$RESULT eq "0"}
1071
1072 ###############################################################################
1073
1074 fossil test-th-eval {string is alnum abc123_}
1075 test th1-string-is-11 {$RESULT eq "0"}
1076
1077 ###############################################################################
1078
1079 fossil test-th-eval {string is list ""}
1080 test th1-string-is-12 {$RESULT eq "1"}
1081
1082 ###############################################################################
1083
1084 fossil test-th-eval {string is list 1}
1085 test th1-string-is-13 {$RESULT eq "1"}
1086
1087 ###############################################################################
1088
1089 fossil test-th-eval {string is list "1 2 3"}
1090 test th1-string-is-14 {$RESULT eq "1"}
1091
1092 ###############################################################################
1093
1094 fossil test-th-eval {string is list "\{"}
1095 test th1-string-is-15 {$RESULT eq "0"}
1096
1097 ###############################################################################
1098
1099 fossil test-th-eval {string is list "1 2 3 \{"}
1100 test th1-string-is-16 {$RESULT eq "0"}
1101
1102 ###############################################################################
1103
1104 fossil test-th-eval {string is list "1 2 3 \{\}"}
1105 test th1-string-is-17 {$RESULT eq "1"}
1106
1107 ###############################################################################
1108
1109 fossil test-th-eval {string is list "1 2 3 \{\{\}"}
1110 test th1-string-is-18 {$RESULT eq "0"}
1111
--- www/changes.wiki
+++ www/changes.wiki
@@ -7,10 +7,11 @@
77
* Add minimal <nowiki>[lsearch]</nowiki> command to TH1. Only exact
88
case-sensitive matching is supported.
99
* Add the <nowiki>[glob_match]</nowiki> command to TH1.
1010
* Add the <nowiki>[tclIsSafe] and [tclMakeSafe]</nowiki> TH1 commands to
1111
the Tcl integration subsystem.
12
+ * Add 'list' class to the <nowiki>[string is]</nowiki> command in TH1.
1213
* Update internal Unicode character tables, used in regular expression
1314
handling, from version 7.0 to 8.0.
1415
1516
<h2>Changes for Version 1.33 (2015-05-23)</h2>
1617
* Improved fork detection on [/help?cmd=update|fossil update],
1718
--- www/changes.wiki
+++ www/changes.wiki
@@ -7,10 +7,11 @@
7 * Add minimal <nowiki>[lsearch]</nowiki> command to TH1. Only exact
8 case-sensitive matching is supported.
9 * Add the <nowiki>[glob_match]</nowiki> command to TH1.
10 * Add the <nowiki>[tclIsSafe] and [tclMakeSafe]</nowiki> TH1 commands to
11 the Tcl integration subsystem.
 
12 * Update internal Unicode character tables, used in regular expression
13 handling, from version 7.0 to 8.0.
14
15 <h2>Changes for Version 1.33 (2015-05-23)</h2>
16 * Improved fork detection on [/help?cmd=update|fossil update],
17
--- www/changes.wiki
+++ www/changes.wiki
@@ -7,10 +7,11 @@
7 * Add minimal <nowiki>[lsearch]</nowiki> command to TH1. Only exact
8 case-sensitive matching is supported.
9 * Add the <nowiki>[glob_match]</nowiki> command to TH1.
10 * Add the <nowiki>[tclIsSafe] and [tclMakeSafe]</nowiki> TH1 commands to
11 the Tcl integration subsystem.
12 * Add 'list' class to the <nowiki>[string is]</nowiki> command in TH1.
13 * Update internal Unicode character tables, used in regular expression
14 handling, from version 7.0 to 8.0.
15
16 <h2>Changes for Version 1.33 (2015-05-23)</h2>
17 * Improved fork detection on [/help?cmd=update|fossil update],
18

Keyboard Shortcuts

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