diff options
Diffstat (limited to 'src/common/strlib.h')
-rw-r--r-- | src/common/strlib.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/common/strlib.h b/src/common/strlib.h index 3f4f984cf..f5819bbcb 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -78,6 +78,27 @@ typedef enum e_svopt /// Other escape sequences supported by the C compiler. #define SV_ESCAPE_C_SUPPORTED "abtnvfr\?\"'\\" +/// Parse state. +/// The field is [start,end[ +struct s_svstate +{ + const char* str; //< string to parse + int len; //< string length + int off; //< current offset in the string + int start; //< where the field starts + int end; //< where the field ends + enum e_svopt opt; //< parse options + char delim; //< field delimiter + bool done; //< if all the text has been parsed +}; + +/// Parses a single field in a delim-separated string. +/// The delimiter after the field is skipped. +/// +/// @param sv Parse state +/// @return 1 if a field was parsed, 0 if done, -1 on error. +int sv_parse_next(struct s_svstate* sv); + /// Parses a delim-separated string. /// Starts parsing at startoff and fills the pos array with position pairs. /// out_pos[0] and out_pos[1] are the start and end of line. |