parseutils
nimony/lib/std/parseutils.nim
This module contains helpers for parsing tokens, numbers, integers, floats, identifiers, etc.
func parseHex(s: openArray; number: var T; maxLen: int64): int64Parses a hexadecimal number and stores its value in
number.Returns the number of the parsed characters or 0 in case of an error. If error, the value of
numberis not changed.If
maxLen == 0, the parsing continues until the first non-hex character or to the end of the string. Otherwise, no more thanmaxLencharacters are parsed starting from thestartposition.It does not check for overflow. If the value represented by the string is too big to fit into
number, only the value of last fitting characters will be stored innumberwithout producing an error.func parseHex(s: string; number: var T; start: int64; maxLen: int64): int64Parses a hexadecimal number and stores its value in
number.Returns the number of the parsed characters or 0 in case of an error. If error, the value of
numberis not changed.If
maxLen == 0, the parsing continues until the first non-hex character or to the end of the string. Otherwise, no more thanmaxLencharacters are parsed starting from thestartposition.It does not check for overflow. If the value represented by the string is too big to fit into
number, only the value of last fitting characters will be stored innumberwithout producing an error.func parseBiggestInt(s: openArray; number: var int64): int64Parses an integer and stores the value into
number. Result is the number of processed chars, or 0 if there is no integer. If the parsed integer is out of the validBiggestIntrange the result is a negative number-n(wherenchars form the out-of-range literal) andnumberis left unchanged, so the caller can detect the overflow and handle it instead of aborting.func parseBiggestUInt(s: openArray; number: var uint64): int64Parses an unsigned integer and stores the value into
number. Result is the number of processed chars, or 0 if there is no integer. If the parsed integer is out of the validBiggestUIntrange (including a leading-) the result is a negative number-nandnumberis left unchanged, so the caller can detect the overflow instead of aborting.func parseBiggestFloat(s: openArray; number: var float64): int64Parses a float and stores the value into
number. Result is the number of processed chars or 0 if a parsing error occurred.func skipIgnoreCase(s: openArray; token: openArray): int64Same as
skipbut case is ignored for token matching.func skipUntil(s: openArray; until: set[char]): int64Skips all characters until one char from the set
untilis found or the end is reached. Returns number of characters skipped.func skipUntil(s: openArray; until: char): int64Skips all characters until the char
untilis found or the end is reached. Returns number of characters skipped.func skipUntil(s: string; until: set[char]; start: int64): int64Skips all characters until one char from the set
untilis found or the end is reached. Returns number of characters skipped.func skipUntil(s: string; until: char; start: int64): int64Skips all characters until the char
untilis found or the end is reached. Returns number of characters skipped.