summary refs log tree commit diff stats
path: root/lib/pure/strutils.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/strutils.nim')
-rw-r--r--lib/pure/strutils.nim20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index b63224cec..bd6814dcc 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -264,6 +264,19 @@ iterator split*(s: string, sep: char): string =
       yield substr(s, first, last-1)
       inc(last)
 
+iterator split*(s: string, sep: string): string =
+  ## Splits the string `s` into substrings using a string separator.
+  ##
+  ## Substrings are separated by the string `sep`.
+  var last = 0
+  if len(s) > 0:
+    while last <= len(s):
+      var first = last
+      while last < len(s) and s.substr(last, last + <sep.len) != sep:
+        inc(last)
+      yield substr(s, first, last-1)
+      inc(last, sep.len)
+
 iterator splitLines*(s: string): string =
   ## Splits the string `s` into its containing lines. Every newline
   ## combination (CR, LF, CR-LF) is supported. The result strings contain
@@ -329,6 +342,13 @@ proc split*(s: string, sep: char): seq[string] {.noSideEffect,
   ## of substrings.
   accumulateResult(split(s, sep))
 
+proc split*(s: string, sep: string): seq[string] {.noSideEffect,
+  rtl, extern: "nsuSplitString".} =
+  ## Splits the string `s` into substrings using a string separator.
+  ##
+  ## Substrings are separated by the string `sep`.
+  accumulateResult(split(s, sep))
+
 proc toHex*(x: BiggestInt, len: int): string {.noSideEffect,
   rtl, extern: "nsuToHex".} =
   ## Converts `x` to its hexadecimal representation. The resulting string