Add replace(proc(string): string)

This commit is contained in:
Flaviu Tamas
2015-01-19 16:02:35 -05:00
parent f34a7dc1f5
commit 78afa73e01
2 changed files with 7 additions and 0 deletions

View File

@@ -74,6 +74,9 @@ Replaces each match of Regex in the string with `sub`.
If `sub` is a `proc (RegexMatch): string`, then it is executed with each match
and the return value is the replacement value.
If `sub` is a `proc (string): string`, then it is executed with the full text
of the match and and the return value is the replacement value.
If `sub` is a string, the syntax is as follows:
- `$$` - literal `$`

View File

@@ -445,6 +445,10 @@ proc replace*(str: string, pattern: Regex,
subproc: proc (match: RegexMatch): string): string =
replaceImpl(str, pattern, subproc(match))
proc replace*(str: string, pattern: Regex,
subproc: proc (match: string): string): string =
replaceImpl(str, pattern, subproc(match.match))
proc replace*(str: string, pattern: Regex, sub: string): string =
# - 1 because the string numbers are 0-indexed
replaceImpl(str, pattern,