Fixed all issues found in spec so far
parse has got quite complex might look to simplify
This commit is contained in:
@@ -15,6 +15,7 @@ struct HBParser {
|
||||
case unexpected
|
||||
case emptyString
|
||||
case invalidUTF8
|
||||
case invalidPosition
|
||||
}
|
||||
|
||||
/// Create a Parser object
|
||||
@@ -282,6 +283,9 @@ extension HBParser {
|
||||
{
|
||||
unsafeAdvance()
|
||||
}
|
||||
if startIndex == index {
|
||||
return subParser(startIndex..<startIndex)
|
||||
}
|
||||
return subParser(startIndex ..< index)
|
||||
}
|
||||
|
||||
@@ -396,6 +400,15 @@ extension HBParser {
|
||||
amount -= 1
|
||||
}
|
||||
}
|
||||
|
||||
func getPosition() -> Int {
|
||||
return index
|
||||
}
|
||||
mutating func setPosition(_ index: Int) throws {
|
||||
guard range.contains(index) else { throw Error.invalidPosition }
|
||||
guard validateUTF8Character(at: index).0 != nil else { throw Error.invalidPosition }
|
||||
_setPosition(index)
|
||||
}
|
||||
}
|
||||
|
||||
/// extend Parser to conform to Sequence
|
||||
|
||||
Reference in New Issue
Block a user