Fix jsre (#19917)
* Fixes for jsre to make it more safe at runtime on some edge cases * https://github.com/nim-lang/Nim/pull/19917#issuecomment-1162692893
This commit is contained in:
parent
0189122d4f
commit
7c31b6a47b
1 changed files with 5 additions and 3 deletions
|
|
@ -33,13 +33,13 @@ func compile*(self: RegExp; pattern: cstring; flags: cstring) {.importjs: "#.com
|
||||||
func replace*(pattern: cstring; self: RegExp; replacement: cstring): cstring {.importjs: "#.replace(#, #)".}
|
func replace*(pattern: cstring; self: RegExp; replacement: cstring): cstring {.importjs: "#.replace(#, #)".}
|
||||||
## Returns a new string with some or all matches of a pattern replaced by given replacement
|
## Returns a new string with some or all matches of a pattern replaced by given replacement
|
||||||
|
|
||||||
func split*(pattern: cstring; self: RegExp): seq[cstring] {.importjs: "#.split(#)".}
|
func split*(pattern: cstring; self: RegExp): seq[cstring] {.importjs: "(#.split(#) || [])".}
|
||||||
## Divides a string into an ordered list of substrings and returns the array
|
## Divides a string into an ordered list of substrings and returns the array
|
||||||
|
|
||||||
func match*(pattern: cstring; self: RegExp): seq[cstring] {.importjs: "#.match(#)".}
|
func match*(pattern: cstring; self: RegExp): seq[cstring] {.importjs: "(#.match(#) || [])".}
|
||||||
## Returns an array of matches of a RegExp against given string
|
## Returns an array of matches of a RegExp against given string
|
||||||
|
|
||||||
func exec*(self: RegExp; pattern: cstring): seq[cstring] {.importjs: "#.exec(#)".}
|
func exec*(self: RegExp; pattern: cstring): seq[cstring] {.importjs: "(#.exec(#) || [])".}
|
||||||
## Executes a search for a match in its string parameter.
|
## Executes a search for a match in its string parameter.
|
||||||
|
|
||||||
func toCstring*(self: RegExp): cstring {.importjs: "#.toString()".}
|
func toCstring*(self: RegExp): cstring {.importjs: "#.toString()".}
|
||||||
|
|
@ -87,3 +87,5 @@ runnableExamples:
|
||||||
assert "do1ne".split(jsregex) == @["do".cstring, "ne".cstring]
|
assert "do1ne".split(jsregex) == @["do".cstring, "ne".cstring]
|
||||||
jsregex.compile(r"[lw]", r"i")
|
jsregex.compile(r"[lw]", r"i")
|
||||||
assert "hello world".replace(jsregex,"X") == "heXlo world"
|
assert "hello world".replace(jsregex,"X") == "heXlo world"
|
||||||
|
let digitsRegex: RegExp = newRegExp(r"\d")
|
||||||
|
assert "foo".match(digitsRegex) == @[]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue