diff options
author | Dmitry Atamanov <data-man@users.noreply.github.com> | 2018-07-07 22:03:22 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-07-07 21:03:22 +0200 |
commit | a6c3bbf01a144ee2d6d3ca5f8032c52877560972 (patch) | |
tree | ba29770b190a571abb5387b1da17aca34d716812 | |
parent | 88714e77d82e65b68da79bbff1b491e56f874a08 (diff) | |
download | Nim-a6c3bbf01a144ee2d6d3ca5f8032c52877560972.tar.gz |
Add proc toOpenArray[byte] for strings (#7820)
-rw-r--r-- | lib/system.nim | 3 | ||||
-rw-r--r-- | tests/system/tsystem_misc.nim | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/system.nim b/lib/system.nim index 32a88de64..d59551d54 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -4164,7 +4164,8 @@ when not defined(js): magic: "Slice".} proc toOpenArray*(x: string; first, last: int): openarray[char] {. magic: "Slice".} - + proc toOpenArrayByte*(x: string; first, last: int): openarray[byte] {. + magic: "Slice".} type ForLoopStmt* {.compilerProc.} = object ## special type that marks a macro diff --git a/tests/system/tsystem_misc.nim b/tests/system/tsystem_misc.nim index 6d14aa68f..ce36bc9ef 100644 --- a/tests/system/tsystem_misc.nim +++ b/tests/system/tsystem_misc.nim @@ -15,6 +15,16 @@ discard """ 1 2 3 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 ''' """ @@ -86,3 +96,9 @@ doAssertRaises(IndexError): foo(toOpenArray(arrNeg, -1, 0)) doAssertRaises(IndexError): foo(toOpenArray(arrNeg, -1, -3)) + +proc foo(a: openArray[byte]) = + for x in a: echo x + +let str = "0123456789" +foo(toOpenArrayByte(str, 0, str.high)) |