HBParser

public struct HBParser
extension HBParser: Sequence

Reader object for parsing String buffers

  • Undocumented

    See more

    Declaration

    Swift

    public enum Error : Swift.Error
  • Create a Parser object

    Declaration

    Swift

    public init?<Bytes>(_ utf8Data: Bytes, validateUTF8: Bool = true) where Bytes : Collection, Bytes.Element == UInt8

    Parameters

    string

    UTF8 data to parse

  • Undocumented

    Declaration

    Swift

    public init(_ string: String)
  • Return contents of parser as a string

    Declaration

    Swift

    public var count: Int { get }
  • Return contents of parser as a string

    Declaration

    Swift

    public var string: String { get }

sub-parsers

  • initialise a parser that parses a section of the buffer attached to another parser

    Declaration

    Swift

    init(_ parser: HBParser, range: Range<Int>)
  • initialise a parser that parses a section of the buffer attached to this parser

    Declaration

    Swift

    func subParser(_ range: Range<Int>) -> HBParser
  • Return current character

    Throws

    .overflow

    Declaration

    Swift

    mutating func character() throws -> Unicode.Scalar

    Return Value

    Current character

  • Read the current character and return if it is as intended. If character test returns true then move forward 1

    Throws

    .overflow

    Declaration

    Swift

    mutating func read(_ char: Unicode.Scalar) throws -> Bool

    Parameters

    char

    character to compare against

    Return Value

    If current character was the one we expected

  • Read the current character and check if it is in a set of characters If character test returns true then move forward 1

    Throws

    .overflow

    Declaration

    Swift

    mutating func read(_ characterSet: Set<Unicode.Scalar>) throws -> Bool

    Parameters

    characterSet

    Set of characters to compare against

    Return Value

    If current character is in character set

  • Compare characters at current position against provided string. If the characters are the same as string provided advance past string

    Throws

    .overflow, .emptyString

    Declaration

    Swift

    mutating func read(_ string: String) throws -> Bool

    Parameters

    string

    String to compare against

    Return Value

    If characters at current position equal string

  • Read next so many characters from buffer

    Throws

    .overflow

    Declaration

    Swift

    mutating func read(count: Int) throws -> HBParser

    Parameters

    count

    Number of characters to read

    Return Value

    The string read from the buffer

  • Read from buffer until we hit a character. Position after this is of the character we were checking for

    Throws

    .overflow if we hit the end of the buffer before reading character

    Declaration

    Swift

    @discardableResult
    mutating func read(until: Unicode.Scalar, throwOnOverflow: Bool = true) throws -> HBParser

    Parameters

    until

    Unicode.Scalar to read until

    Return Value

    String read from buffer

  • Read from buffer until we hit a character in supplied set. Position after this is of the character we were checking for

    Throws

    .overflow

    Declaration

    Swift

    @discardableResult
    mutating func read(until characterSet: Set<Unicode.Scalar>, throwOnOverflow: Bool = true) throws -> HBParser

    Parameters

    characterSet

    Unicode.Scalar set to check against

    Return Value

    String read from buffer

  • Read from buffer until we hit a character that returns true for supplied closure. Position after this is of the character we were checking for

    Throws

    .overflow

    Declaration

    Swift

    @discardableResult
    mutating func read(until: (Unicode.Scalar) -> Bool, throwOnOverflow: Bool = true) throws -> HBParser

    Parameters

    until

    Function to test

    Return Value

    String read from buffer

  • Read from buffer until we hit a character where supplied KeyPath is true. Position after this is of the character we were checking for

    Throws

    .overflow

    Declaration

    Swift

    @discardableResult
    mutating func read(until keyPath: KeyPath<Unicode.Scalar, Bool>, throwOnOverflow: Bool = true) throws -> HBParser

    Parameters

    characterSet

    Unicode.Scalar set to check against

    Return Value

    String read from buffer

  • Read from buffer until we hit a string. By default the position after this is of the beginning of the string we were checking for

    Throws

    .overflow, .emptyString

    Declaration

    Swift

    @discardableResult
    mutating func read(untilString: String, throwOnOverflow: Bool = true, skipToEnd: Bool = false) throws -> HBParser

    Parameters

    untilString

    String to check for

    throwOnOverflow

    Throw errors if we hit the end of the buffer

    skipToEnd

    Should we set the position to after the found string

    Return Value

    String read from buffer

  • Read from buffer from current position until the end of the buffer

    Declaration

    Swift

    @discardableResult
    mutating func readUntilTheEnd() -> HBParser

    Return Value

    String read from buffer

  • Read while character at current position is the one supplied

    Declaration

    Swift

    @discardableResult
    mutating func read(while: Unicode.Scalar) -> Int

    Parameters

    while

    Unicode.Scalar to check against

    Return Value

    String read from buffer

  • Read while character at current position is in supplied set

    Declaration

    Swift

    @discardableResult
    mutating func read(while characterSet: Set<Unicode.Scalar>) -> HBParser

    Parameters

    while

    character set to check

    Return Value

    String read from buffer

  • Read while character returns true for supplied closure

    Declaration

    Swift

    @discardableResult
    mutating func read(while: (Unicode.Scalar) -> Bool) -> HBParser

    Parameters

    while

    character set to check

    Return Value

    String read from buffer

  • Read while character returns true for supplied KeyPath

    Declaration

    Swift

    @discardableResult
    mutating func read(while keyPath: KeyPath<Unicode.Scalar, Bool>) -> HBParser

    Parameters

    while

    character set to check

    Return Value

    String read from buffer

  • Split parser into sections separated by character

    Declaration

    Swift

    mutating func split(separator: Unicode.Scalar) -> [HBParser]

    Parameters

    separator

    Separator character

    Return Value

    arrays of sub parsers

  • Return whether we have reached the end of the buffer

    Declaration

    Swift

    func reachedEnd() -> Bool

    Return Value

    Have we reached the end

  • Return the character at the current position

    Throws

    .overflow

    Declaration

    Swift

    func current() -> Unicode.Scalar

    Return Value

    Unicode.Scalar

  • Move forward one character

    Throws

    .overflow

    Declaration

    Swift

    mutating func advance() throws
  • Move forward so many character

    Throws

    .overflow

    Declaration

    Swift

    mutating func advance(by amount: Int) throws

    Parameters

    amount

    number of characters to move forward

  • Move backwards one character

    Throws

    .overflow

    Declaration

    Swift

    mutating func retreat() throws
  • Move back so many characters

    Throws

    .overflow

    Declaration

    Swift

    mutating func retreat(by amount: Int) throws

    Parameters

    amount

    number of characters to move back

  • Undocumented

    Declaration

    Swift

    mutating func unsafeAdvance()
  • Undocumented

    Declaration

    Swift

    mutating func unsafeAdvance(by amount: Int)
  • Declaration

    Swift

    public typealias Element = Unicode.Scalar
  • Declaration

    Swift

    public  func makeIterator() -> Iterator
  • Declaration

    Swift

    public struct Iterator : IteratorProtocol
  • Undocumented

    Declaration

    Swift

    func decodeUTF8Character(at index: Int) -> (Unicode.Scalar, Int)
  • Undocumented

    Declaration

    Swift

    func skipUTF8Character(at index: Int) -> Int
  • Undocumented

    Declaration

    Swift

    func backOneUTF8Character(at index: Int) -> Int
  • same as decodeUTF8Character but adds extra validation, so we can make assumptions later on in decode and skip

    Declaration

    Swift

    func validateUTF8Character(at index: Int) -> (Unicode.Scalar?, Int)
  • return if the buffer is valid UTF8

    Declaration

    Swift

    func validateUTF8() -> Bool
  • percent decode UTF8

    Declaration

    Swift

    public func percentDecode() -> String?