@@ -70,9 +70,9 @@ limitations under the License.
70
70
local lower_a_code = std.codepoint ('a' );
71
71
local addDigit(aggregate, char) =
72
72
local code = std.codepoint (char);
73
- local digit = if code > lower_a_code then
73
+ local digit = if code >= lower_a_code then
74
74
code - lower_a_code + 10
75
- else if code > upper_a_code then
75
+ else if code >= upper_a_code then
76
76
code - upper_a_code + 10
77
77
else
78
78
code - zero_code;
@@ -81,6 +81,8 @@ limitations under the License.
81
81
std.foldl (addDigit, std.stringChars (str), 0 ),
82
82
83
83
parseInt(str)::
84
+ assert std.isString (str): 'Expected string, got ' + std.type (str);
85
+ assert std.length (str) > 0 && str != "-" : 'Not an integer: "%s"' % [str];
84
86
if str[0 ] == '-' then
85
87
-parse_nat(str[1 :], 10 )
86
88
else
@@ -147,9 +149,9 @@ limitations under the License.
147
149
acc + str[start_index: curr_index]
148
150
else if found_at(curr_index) then
149
151
local new_index = curr_index + std.length (from);
150
- replace_after(new_index, new_index, acc + str[start_index: curr_index] + to)
152
+ replace_after(new_index, new_index, acc + str[start_index: curr_index] + to) tailstrict
151
153
else
152
- replace_after(start_index, curr_index + 1 , acc);
154
+ replace_after(start_index, curr_index + 1 , acc) tailstrict ;
153
155
154
156
// if from_len==1, then we replace by splitting and rejoining the
155
157
// string which is much faster than recursing on replace_after
@@ -853,7 +855,7 @@ limitations under the License.
853
855
'\\ t'
854
856
else
855
857
local cp = std.codepoint (ch);
856
- if cp < 32 || (cp >= 126 && cp <= 159 ) then
858
+ if cp < 32 || (cp >= 127 && cp <= 159 ) then
857
859
'\\ u%04x' % [cp]
858
860
else
859
861
ch;
@@ -1245,4 +1247,23 @@ limitations under the License.
1245
1247
if isContent(std.prune (a[x]))
1246
1248
} else
1247
1249
a,
1250
+
1251
+ findSubstr(pat, str)::
1252
+ if std.type (pat) != 'string' then
1253
+ error 'findSubstr first parameter should be a string, got ' + std.type (pat)
1254
+ else if std.type (str) != 'string' then
1255
+ error 'findSubstr second parameter should be a string, got ' + std.type (str)
1256
+ else
1257
+ local pat_len = std.length (pat);
1258
+ local str_len = std.length (str);
1259
+ if pat_len == 0 || str_len == 0 || pat_len > str_len then
1260
+ []
1261
+ else
1262
+ std.filter (function (i) str[i: i+pat_len] == pat, std.range (0 , str_len - pat_len)),
1263
+
1264
+ find(value, arr)::
1265
+ if std.type (arr) != 'array' then
1266
+ error 'find second parameter should be an array, got ' + std.type (arr)
1267
+ else
1268
+ std.filter (function (i) arr[i] == value, std.range (0 , std.length (arr) - 1 )),
1248
1269
}
0 commit comments