Adds split proc for strings with a string separator.
This commit is contained in:
parent
96c97d4103
commit
7cddb39969
1 changed files with 20 additions and 0 deletions
|
|
@ -264,6 +264,19 @@ iterator split*(s: string, sep: char): string =
|
||||||
yield substr(s, first, last-1)
|
yield substr(s, first, last-1)
|
||||||
inc(last)
|
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 =
|
iterator splitLines*(s: string): string =
|
||||||
## Splits the string `s` into its containing lines. Every newline
|
## Splits the string `s` into its containing lines. Every newline
|
||||||
## combination (CR, LF, CR-LF) is supported. The result strings contain
|
## 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.
|
## of substrings.
|
||||||
accumulateResult(split(s, sep))
|
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,
|
proc toHex*(x: BiggestInt, len: int): string {.noSideEffect,
|
||||||
rtl, extern: "nsuToHex".} =
|
rtl, extern: "nsuToHex".} =
|
||||||
## Converts `x` to its hexadecimal representation. The resulting string
|
## Converts `x` to its hexadecimal representation. The resulting string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue