File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -1109,19 +1109,26 @@ proc defineLibrary*() =
1109
1109
description = "check if string starts with given prefix",
1110
1110
args = {
1111
1111
"string": {String},
1112
- "prefix": {String, Regex}
1112
+ "prefix": {String, Regex, Char }
1113
1113
},
1114
1114
attrs = NoAttrs,
1115
1115
returns = {Logical},
1116
1116
example = """
1117
1117
prefix? "hello" "he" ; => true
1118
1118
prefix? "boom" "he" ; => false
1119
+ ..........
1120
+ prefix? "hello" {/\w+/} ; => true
1121
+ prefix? "world" {/\d+/} ; => false
1122
+ ..........
1123
+ prefix? "hello" 'h' ; => true
1119
1124
""":
1120
1125
#=======================================================
1121
- if yKind==Regex:
1126
+ if likely(yKind==String):
1127
+ push(newLogical(x.s.startsWith(y.s)))
1128
+ elif yKind==Regex:
1122
1129
push(newLogical(x.s.startsWith(y.rx)))
1123
1130
else:
1124
- push(newLogical(x.s.startsWith(y.s) ))
1131
+ push(newLogical(x.s.len > 0 and x.s.runeAtPos(0)==y.c ))
1125
1132
1126
1133
builtin "suffix?",
1127
1134
alias = unaliased,
Original file line number Diff line number Diff line change 1
- 3341
1
+ 3342
You can’t perform that action at this time.
0 commit comments