Skip to content

Commit 9511147

Browse files
fix: Zinc unicode literal fixes.
Readers also use Data buffers
1 parent f08a3a6 commit 9511147

File tree

7 files changed

+123
-88
lines changed

7 files changed

+123
-88
lines changed

Sources/Haystack/IO/ZincReader.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ public class ZincReader {
1010
var peekVal: any Val = null
1111
var peekLine: Int = 0
1212

13-
14-
public init(_ zinc: String) throws {
15-
tokenizer = ZincTokenizer(zinc)
13+
public init(_ data: Data) throws {
14+
tokenizer = try ZincTokenizer(data)
1615
try consume()
1716
try consume()
1817
}
1918

19+
public convenience init(_ string: String) throws {
20+
guard let data = string.data(using: .ascii) else {
21+
throw ZincReaderError.InputIsNotUtf8
22+
}
23+
try self.init(data)
24+
}
25+
2026
public func readVal() throws -> any Val {
2127
var val: any Val = null
2228
if cur == .id, curVal.equals("ver") {
@@ -298,6 +304,7 @@ enum ZincReaderError: Error {
298304
case GridDoesNotBeginWithVersion(any Val)
299305
case GridHasNoColumns
300306
case IdValueIsNotString(any Val)
307+
case InputIsNotUtf8
301308
case InvalidCoord
302309
case InvalidRef
303310
case InvalidTagName

0 commit comments

Comments
 (0)