forked from rarestype/swift-json
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSON.Array (ext).swift
More file actions
31 lines (30 loc) · 1.07 KB
/
JSON.Array (ext).swift
File metadata and controls
31 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Grammar
import JSONAST
extension JSON.Array {
/// Attempts to parse a JSON array from raw UTF-8 JSON data.
public init(parsing json: JSON) throws {
self.init(try JSON.NodeRule<Int>.Array.parse(json.utf8))
}
/// Attempts to parse a JSON array from a raw span
public init(parsing span: RawSpan) throws {
self.init(
try span.withUnsafeBytes { buffer in
try JSON.NodeRule<Int>.Array.parse(buffer)
}
)
}
/// Attempts to parse a JSON array from a string.
public init(parsing string: String) throws {
self.init(try JSON.NodeRule<String.Index>.Array.parse(string.utf8))
}
/// Attempts to parse a JSON array from a substring.
public init(parsing string: Substring) throws {
self.init(try JSON.NodeRule<String.Index>.Array.parse(string.utf8))
}
}
extension JSON.Array: LosslessStringConvertible {
/// See ``init(parsing:) (String)``.
public init?(_ description: String) {
do { try self.init(parsing: description) } catch { return nil }
}
}