|
CX Framework
Cross-platform C utility framework
|
Functions | |
| bool | strscToken (strscan *sc, string *out, strref delims) |
| bool | strscUntil (strscan *sc, string *out, strref text) |
| bool | strscWhile (strscan *sc, string *out, strref chars) |
| bool | strscQuoted (strscan *sc, string *out) |
| bool | strscLine (strscan *sc, string *out) |
| bool | strscRest (strscan *sc, string *out) |
| void | strscSpan (strscan *sc, int32 *off, int32 *len) |
Every extraction function takes an output string handle that may be NULL, which consumes the text without building a string for it. The span that was consumed is always recorded and can be read back with strscSpan(), which is how a token is compared against something without materializing it at all.
| bool strscLine | ( | strscan * | sc, |
| string * | out | ||
| ) |
Reads one line and consumes its terminator.
Accepts CRLF or a bare LF. The last line of a string needs no terminator. The result never includes the terminator, and an empty line is a valid result.
| sc | Scanner to read from |
| out | Receives the line, or NULL to consume it |
| bool strscQuoted | ( | strscan * | sc, |
| string * | out | ||
| ) |
Reads a double-quoted string and removes its escapes.
Requires a " at the cursor and reads to the closing one, turning \x into x along the way. The quotes themselves are consumed but are not part of the result.
The recorded span covers the text between the quotes as it appeared in the input, so it still contains any backslashes.
| sc | Scanner to read from |
| out | Receives the unescaped contents, or NULL to consume them |
| bool strscRest | ( | strscan * | sc, |
| string * | out | ||
| ) |
Reads everything left and moves the cursor to the end.
An empty remainder is a valid result.
| sc | Scanner to read from |
| out | Receives the remaining text, or NULL to consume it |
| void strscSpan | ( | strscan * | sc, |
| int32 * | off, | ||
| int32 * | len | ||
| ) |
Reports the span of the most recent extraction.
The offset and length index into the scanner's own string, so the text can be compared with strRangeEq() or copied out with strSubStr() without having built a string for it in the first place.
| sc | Scanner to inspect |
| off | Receives the byte offset of the span |
| len | Receives the length of the span |
Example:
| bool strscToken | ( | strscan * | sc, |
| string * | out, | ||
| strref | delims | ||
| ) |
Reads a run of bytes up to the next delimiter.
Stops before the delimiter without consuming it. An empty token is a failure - use strscUntil() where an empty result is meaningful.
| sc | Scanner to read from |
| out | Receives the token, or NULL to consume it without building a string |
| delims | Set of bytes that end the token |
| bool strscUntil | ( | strscan * | sc, |
| string * | out, | ||
| strref | text | ||
| ) |
Reads everything up to the next occurrence of some text.
Stops before the text without consuming it, and fails if the text does not appear at all. An empty result is fine - it just means the text is at the cursor already.
| sc | Scanner to read from |
| out | Receives the text read, or NULL to consume it without building a string |
| text | Text to stop before |
| bool strscWhile | ( | strscan * | sc, |
| string * | out, | ||
| strref | chars | ||
| ) |
Reads a run of bytes drawn from a set.
The mirror of strscToken(): it stops at the first byte that is not in the set. An empty run is a failure.
| sc | Scanner to read from |
| out | Receives the run, or NULL to consume it without building a string |
| chars | Set of bytes the run may contain |