Skip to content

Commit eaca3ee

Browse files
committed
Adapt to change in strutils.split
Fixes #15 Related to nim-lang/Nim#4361
1 parent bf21245 commit eaca3ee

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/docopt.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ method fix_repeating_arguments(self: Pattern) {.base.} =
164164
if e.value.kind == vkNone:
165165
e.value = val(@[])
166166
elif e.value.kind != vkList:
167-
e.value = val(($e.value).split())
167+
e.value = val(($e.value).split_whitespace())
168168
if e.class == "Command" or
169169
e.class == "Option" and Option(e).argcount == 0:
170170
e.value = val(0)
@@ -250,7 +250,7 @@ proc option_parse[T](
250250
var (options, p, description) = option_description.strip().partition(" ")
251251
discard p
252252
options = options.replace(",", " ").replace("=", " ")
253-
for s in options.split():
253+
for s in options.split_whitespace():
254254
if s.starts_with "--":
255255
long = s
256256
elif s.starts_with "-":
@@ -338,7 +338,7 @@ proc `@`(tokens: TokenStream): var seq[string] = tokens.tokens
338338
proc token_stream(source: seq[string], error: ref Exception): TokenStream =
339339
TokenStream(tokens: source, error: error)
340340
proc token_stream(source: string, error: ref Exception): TokenStream =
341-
token_stream(source.split(), error)
341+
token_stream(source.split_whitespace(), error)
342342

343343
proc current(self: TokenStream): string =
344344
if @self.len > 0:
@@ -549,7 +549,7 @@ proc printable_usage(doc: string): string =
549549

550550

551551
proc formal_usage(printable_usage: string): string =
552-
var pu = printable_usage.split()
552+
var pu = printable_usage.split_whitespace()
553553
pu.delete(0)
554554
var pu0 = pu[0]
555555
pu.delete(0)

src/private/util.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ macro gen_class*(body: stmt): stmt {.immediate.} =
5757
meth &= "= \"$1\""
5858
body.add(parse_stmt(meth.format(typ[0])))
5959
body
60+
61+
62+
# Backwards compatibility
63+
when not compiles("".split_whitespace()):
64+
proc split_whitespace*(s: string): seq[string] =
65+
s.split()

test/test.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ proc test(doc, args, expected_s: string): bool =
88
var error = ""
99
try:
1010
try:
11-
var output = docopt(doc, args.split(), quit=false)
11+
var output = docopt(doc, args.split_whitespace(), quit=false)
1212
var expected = init_table[string, Value]()
1313
for k, v in expected_json:
1414
expected[k] = case v.kind
@@ -68,4 +68,4 @@ for each_line in (tests & "\n\n").split_lines():
6868
expected = nil
6969
echo()
7070

71-
quit(if passed == total: 0 else: 1)
71+
quit(if passed == total: 0 else: 1)

0 commit comments

Comments
 (0)