Skip to content

Commit ec574df

Browse files
refactor: Lowercasing error enum cases
1 parent ec9ed2a commit ec574df

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

Sources/Haystack/IO/ZincReader.swift

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class ZincReader {
2222
/// Create a reader from the input zinc string. It is coerced to ASCII format.
2323
/// - Parameter data: The zinc string
2424
public convenience init(_ string: String) throws {
25-
guard let data = string.data(using: .ascii) else {
26-
throw ZincReaderError.InputIsNotASCII
25+
guard let data = string.data(using: .utf8) else {
26+
throw ZincReaderError.inputIsNotUtf8
2727
}
2828
try self.init(data)
2929
}
@@ -43,15 +43,15 @@ public class ZincReader {
4343
/// Read the Grid contained by the data. If the data does not contain a grid, throw an error.
4444
public func readGrid() throws -> Grid {
4545
guard let grid = try readVal() as? Grid else {
46-
throw ZincReaderError.InputIsNotGrid
46+
throw ZincReaderError.inputIsNotGrid
4747
}
4848
return grid
4949
}
5050

5151
private func parseVal() throws -> any Val {
5252
if cur == .id {
5353
guard let id = curVal as? String else {
54-
throw ZincReaderError.IdValueIsNotString(curVal)
54+
throw ZincReaderError.idValueIsNotString(curVal)
5555
}
5656
try consume(.id)
5757

@@ -74,7 +74,7 @@ public class ZincReader {
7474
case "NaN": return Number.nan
7575
case "INF": return Number.infinity
7676
default:
77-
throw ZincReaderError.UnexpectedId(id)
77+
throw ZincReaderError.unexpectedId(id)
7878
}
7979
}
8080

@@ -99,12 +99,12 @@ public class ZincReader {
9999
return try parseGrid()
100100
}
101101

102-
throw ZincReaderError.UnexpectedToken(cur)
102+
throw ZincReaderError.unexpectedToken(cur)
103103
}
104104

105105
private func parseCoord(_ id: String) throws -> Coord {
106106
guard id == "C" else {
107-
throw ZincReaderError.InvalidCoord
107+
throw ZincReaderError.invalidCoord
108108
}
109109
try consume(.lparen)
110110
let latitude = try consumeNumber()
@@ -116,7 +116,7 @@ public class ZincReader {
116116

117117
private func parseXStr(_ id: String) throws -> XStr {
118118
guard (id.first?.isLowercase ?? false) else {
119-
throw ZincReaderError.InvalidXStr
119+
throw ZincReaderError.invalidXStr
120120
}
121121
try consume(.lparen)
122122
let val = try consumeString()
@@ -128,7 +128,7 @@ public class ZincReader {
128128
var val = self.curVal
129129
if cur == .ref, peek == .str {
130130
guard let refVal = curVal as? String, let dis = peekVal as? String else {
131-
throw ZincReaderError.InvalidRef
131+
throw ZincReaderError.invalidRef
132132
}
133133
val = try Ref(refVal, dis: dis)
134134
try consume(.ref)
@@ -183,13 +183,13 @@ public class ZincReader {
183183

184184
// Check version
185185
guard cur == .id, curVal.equals("ver") else {
186-
throw ZincReaderError.GridDoesNotBeginWithVersion(curVal)
186+
throw ZincReaderError.gridDoesNotBeginWithVersion(curVal)
187187
}
188188
try consume()
189189
try consume(.colon)
190190
let version = try consumeString()
191191
guard version == "3.0" else {
192-
throw ZincReaderError.UnsupportedZincVersion(version)
192+
throw ZincReaderError.unsupportedZincVersion(version)
193193
}
194194

195195
// Metadata
@@ -216,7 +216,7 @@ public class ZincReader {
216216
try consume(.comma)
217217
}
218218
guard numCols > 0 else {
219-
throw ZincReaderError.GridHasNoColumns
219+
throw ZincReaderError.gridHasNoColumns
220220
}
221221
try consume(.nl)
222222

@@ -259,10 +259,10 @@ public class ZincReader {
259259
private func consumeTagName() throws -> String {
260260
try verify(.id)
261261
guard let id = curVal as? String else {
262-
throw ZincReaderError.IdValueIsNotString(curVal)
262+
throw ZincReaderError.idValueIsNotString(curVal)
263263
}
264264
guard (id.first?.isLowercase ?? false) else {
265-
throw ZincReaderError.InvalidTagName
265+
throw ZincReaderError.invalidTagName
266266
}
267267
try consume(.id)
268268
return id
@@ -271,7 +271,7 @@ public class ZincReader {
271271
private func consumeNumber() throws -> Number {
272272
try verify(.num)
273273
guard let number = curVal as? Number else {
274-
throw ZincReaderError.NumValueIsNotNumber(curVal)
274+
throw ZincReaderError.numValueIsNotNumber(curVal)
275275
}
276276
try consume(.num)
277277
return number
@@ -280,7 +280,7 @@ public class ZincReader {
280280
private func consumeString() throws -> String {
281281
try verify(.str)
282282
guard let number = curVal as? String else {
283-
throw ZincReaderError.StrValueIsNotString(curVal)
283+
throw ZincReaderError.strValueIsNotString(curVal)
284284
}
285285
try consume(.str)
286286
return number
@@ -301,25 +301,25 @@ public class ZincReader {
301301

302302
private func verify(_ expected: ZincToken) throws {
303303
if cur != expected {
304-
throw ZincReaderError.ExpectedToken(expected, not: cur)
304+
throw ZincReaderError.expectedToken(expected, not: cur)
305305
}
306306
}
307307
}
308308

309309
enum ZincReaderError: Error {
310-
case ExpectedToken(ZincToken, not: ZincToken)
311-
case GridDoesNotBeginWithVersion(any Val)
312-
case GridHasNoColumns
313-
case IdValueIsNotString(any Val)
314-
case InputIsNotASCII
315-
case InvalidCoord
316-
case InvalidRef
317-
case InvalidTagName
318-
case InvalidXStr
319-
case NumValueIsNotNumber(any Val)
320-
case StrValueIsNotString(any Val)
321-
case UnexpectedId(String)
322-
case UnexpectedToken(ZincToken)
323-
case InputIsNotGrid
324-
case UnsupportedZincVersion(String)
310+
case expectedToken(ZincToken, not: ZincToken)
311+
case gridDoesNotBeginWithVersion(any Val)
312+
case gridHasNoColumns
313+
case idValueIsNotString(any Val)
314+
case inputIsNotUtf8
315+
case invalidCoord
316+
case invalidRef
317+
case invalidTagName
318+
case invalidXStr
319+
case numValueIsNotNumber(any Val)
320+
case strValueIsNotString(any Val)
321+
case unexpectedId(String)
322+
case unexpectedToken(ZincToken)
323+
case inputIsNotGrid
324+
case unsupportedZincVersion(String)
325325
}

Sources/Haystack/IO/ZincTokenizer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ZincTokenizer {
1919
}
2020

2121
public convenience init(_ string: String) throws {
22-
guard let data = string.data(using: .ascii) else {
22+
guard let data = string.data(using: .utf8) else {
2323
throw ZincTokenizerError.inputIsNotUtf8
2424
}
2525
try self.init(data)

Sources/Haystack/Utils/GridBuilder.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ public class GridBuilder {
5757
/// - Returns: This instance for chaining
5858
public func addCol(name: String, meta: [String: any Val]? = nil) throws -> Self {
5959
guard rows.count == 0 else {
60-
throw GridBuilderError.CannotAddColAfterRows
60+
throw GridBuilderError.cannotAddColAfterRows
6161
}
6262

6363
guard !colNames.contains(name) else {
64-
throw GridBuilderError.ColAlreadyDefined(name: name)
64+
throw GridBuilderError.colAlreadyDefined(name: name)
6565
}
6666
colNames.append(name)
6767
if let meta = meta {
@@ -79,7 +79,7 @@ public class GridBuilder {
7979
/// - Returns: This instance for chaining
8080
public func setColMeta(name: String, _ keysAndVals: [String: any Val]) throws -> Self {
8181
guard var meta = colMeta[name] else {
82-
throw GridBuilderError.ColNotDefined(name: name)
82+
throw GridBuilderError.colNotDefined(name: name)
8383
}
8484
for (key, val) in keysAndVals {
8585
if val is Remove {
@@ -98,7 +98,7 @@ public class GridBuilder {
9898
/// - Returns: This instance for chaining
9999
public func addRow(_ vals: [any Val]) throws -> Self {
100100
guard vals.count == colNames.count else {
101-
throw GridBuilderError.ValCountDoesntMatchColCount
101+
throw GridBuilderError.valCountDoesntMatchColCount
102102
}
103103

104104
var row = [String: any Val]()
@@ -111,8 +111,8 @@ public class GridBuilder {
111111
}
112112

113113
enum GridBuilderError: Error {
114-
case CannotAddColAfterRows
115-
case ColAlreadyDefined(name: String)
116-
case ColNotDefined(name: String)
117-
case ValCountDoesntMatchColCount
114+
case cannotAddColAfterRows
115+
case colAlreadyDefined(name: String)
116+
case colNotDefined(name: String)
117+
case valCountDoesntMatchColCount
118118
}

0 commit comments

Comments
 (0)