Function isSubChar

  • Again, when parsing, you want to allocate as little as possible. So this function lets you say:

    isSubChar(isSpace, offset, "this is the source string") // => newOffset
    

    The (Char -> Bool) argument is called a predicate. The newOffset value can be a few different things:

    • -1 means that the predicate failed
    • -2 means the predicate succeeded with a \n
    • otherwise you will get offset + 1 or offset + 2 depending on whether the UTF16 character is one or two words wide.

    Parameters

    • predicate: ((src: string) => boolean)
        • (src: string): boolean
        • Parameters

          • src: string

          Returns boolean

    • offset: number
    • string: string

    Returns number