mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 12:07:51 +00:00
Add proc toOpenArray[byte] for strings (#7820)
This commit is contained in:
committed by
Andreas Rumpf
parent
88714e77d8
commit
a6c3bbf01a
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user