summary refs log tree commit diff stats
path: root/lib/pure/parseutils.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/parseutils.nim')
-rwxr-xr-xlib/pure/parseutils.nim7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/pure/parseutils.nim b/lib/pure/parseutils.nim
index 8660eec2e..ad8a4ddcd 100755
--- a/lib/pure/parseutils.nim
+++ b/lib/pure/parseutils.nim
@@ -164,6 +164,13 @@ proc parseWhile*(s: string, token: var string, validChars: set[char],
   result = i-start
   token = substr(s, start, i-1)
 
+proc captureBetween*(s: string, first: char, second = '\0', i = 0): string =
+  ## Finds the first occurence of ``first``, then returns everything from there
+  ## up to ``second``(if ``second`` is '\0', then ``first`` is used).
+  var i = skipUntil(s, first, i)+1
+  result = ""
+  discard s.parseUntil(result, if second == '\0': first else: second, i)
+
 {.push overflowChecks: on.}
 # this must be compiled with overflow checking turned on:
 proc rawParseInt(s: string, b: var biggestInt, start = 0): int =