Reads the next token from line and removes it, with any spaces before it, from line.
parse_token :: (
line: *string,
delimiters := DEFAULT_DELIMITERS,
spaces := DEFAULT_SPACES
) -> (value: string, success: bool)
A token is a run of bytes up to the next space or delimiter. A delimiter that starts a token is a
token of one byte. The result is the token and true; when only spaces are left, it is an empty
string and false and line is not changed. The token points into the original text.
Parameters
- line: *string
- delimiters := DEFAULT_DELIMITERS
- bytes that end a token. One that starts a token is a token by itself.
- spaces := DEFAULT_SPACES
- bytes that are skipped in front of a token and that end one. They never appear in a token.
Returns
- value: string
- success: bool
line := " name =value";
token, ok := parse_token(*line);
assert(ok && token == "name" && line == " =value");
token, ok = parse_token(*line);
assert(ok && token == "=" && line == "value");