CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
strscan.h
Go to the documentation of this file.
1#pragma once
2
3#include <cx/string/strbase.h>
4
7
60
61CX_C_BEGIN
62
67
72typedef struct strscan {
73 strref s;
74 int32 pos;
75 int32 errpos;
76 bool ok;
77 flags_t flags;
78
79 // Private members - do not access directly
80 int32 _len;
81 int32 _spanoff;
82 int32 _spanlen;
84
85// Internal - use the strscInit() macro
86void _strscInit(_Out_ strscan* _Nonnull sc, _In_opt_ strref s, flags_t flags);
87
104#define strscInit(sc, s, ...) _strscInit(sc, s, opt_flags(__VA_ARGS__))
105
116bool strscFinish(_Inout_ strscan* _Nonnull sc);
117
124_meta_inline bool strscDone(_In_ strscan* _Nonnull sc)
125{
126 return sc->pos >= sc->_len;
127}
128
136_meta_inline int32 strscMark(_In_ strscan* _Nonnull sc)
137{
138 return sc->pos;
139}
140
149void strscRewind(_Inout_ strscan* _Nonnull sc, int32 mark);
150
159bool strscSeek(_Inout_ strscan* _Nonnull sc, int32 pos);
160
167void strscFail(_Inout_ strscan* _Nonnull sc);
168
176
182bool strscLit(_Inout_ strscan* _Nonnull sc, _In_opt_ strref lit);
183
189bool strscChar(_Inout_ strscan* _Nonnull sc, char ch);
190
196bool strscTry(_Inout_ strscan* _Nonnull sc, _In_opt_ strref lit);
197
203bool strscTryChar(_Inout_ strscan* _Nonnull sc, char ch);
204
210bool strscPeek(_In_ strscan* _Nonnull sc, _In_opt_ strref lit);
211
216uint8 strscPeekChar(_In_ strscan* _Nonnull sc);
217
222bool strscWS(_Inout_ strscan* _Nonnull sc);
223
228bool strscWS1(_Inout_ strscan* _Nonnull sc);
229
231
240
250bool strscToken(_Inout_ strscan* _Nonnull sc, _Inout_opt_ string* out, _In_opt_ strref delims);
251
261bool strscUntil(_Inout_ strscan* _Nonnull sc, _Inout_opt_ string* out, _In_opt_ strref text);
262
272bool strscWhile(_Inout_ strscan* _Nonnull sc, _Inout_opt_ string* out, _In_opt_ strref chars);
273
285bool strscQuoted(_Inout_ strscan* _Nonnull sc, _Inout_opt_ string* out);
286
295bool strscLine(_Inout_ strscan* _Nonnull sc, _Inout_opt_ string* out);
296
304bool strscRest(_Inout_ strscan* _Nonnull sc, _Inout_opt_ string* out);
305
323void strscSpan(_In_ strscan* _Nonnull sc, _Out_ int32* _Nonnull off, _Out_ int32* _Nonnull len);
324
326
335
342_Success_(
343 return) bool strscInt32(_Inout_ strscan* _Nonnull sc, _Out_ int32* _Nonnull out, int base);
344
351_Success_(
352 return) bool strscUInt32(_Inout_ strscan* _Nonnull sc, _Out_ uint32* _Nonnull out, int base);
353
360_Success_(
361 return) bool strscInt64(_Inout_ strscan* _Nonnull sc, _Out_ int64* _Nonnull out, int base);
362
369_Success_(
370 return) bool strscUInt64(_Inout_ strscan* _Nonnull sc, _Out_ uint64* _Nonnull out, int base);
371
377_Success_(return) bool strscFloat32(_Inout_ strscan* _Nonnull sc, _Out_ float32* _Nonnull out);
378
384_Success_(return) bool strscFloat64(_Inout_ strscan* _Nonnull sc, _Out_ float64* _Nonnull out);
385
393_Success_(return) bool strscBool(_Inout_ strscan* _Nonnull sc, _Out_ bool* _Nonnull out);
394
395// Internal - use the strscVal() macro
396bool _strscVal(_Inout_ strscan* _Nonnull sc, stype st, _Out_ stgeneric* _Nonnull out);
397
419#define strscVal(sc, type, pval) _strscVal(sc, stCheckedPtrArg(type, pval))
420
422
424
425CX_C_END
bool strscToken(strscan *sc, string *out, strref delims)
bool strscRest(strscan *sc, string *out)
bool strscQuoted(strscan *sc, string *out)
bool strscLine(strscan *sc, string *out)
bool strscUntil(strscan *sc, string *out, strref text)
void strscSpan(strscan *sc, int32 *off, int32 *len)
bool strscWhile(strscan *sc, string *out, strref chars)
bool strscTryChar(strscan *sc, char ch)
bool strscWS1(strscan *sc)
uint8 strscPeekChar(strscan *sc)
bool strscLit(strscan *sc, strref lit)
bool strscTry(strscan *sc, strref lit)
bool strscWS(strscan *sc)
bool strscPeek(strscan *sc, strref lit)
bool strscChar(strscan *sc, char ch)
bool strscBool(strscan *sc, bool *out)
bool strscUInt64(strscan *sc, uint64 *out, int base)
bool strscInt64(strscan *sc, int64 *out, int base)
bool strscUInt32(strscan *sc, uint32 *out, int base)
bool strscInt32(strscan *sc, int32 *out, int base)
bool strscFloat32(strscan *sc, float32 *out)
bool strscFloat64(strscan *sc, float64 *out)
bool strscSeek(strscan *sc, int32 pos)
bool strscFinish(strscan *sc)
int32 strscMark(strscan *sc)
Definition strscan.h:136
void strscFail(strscan *sc)
STRSC_FLAGS
Flags controlling how a scanner matches.
Definition strscan.h:64
void strscRewind(strscan *sc, int32 mark)
bool strscDone(strscan *sc)
Definition strscan.h:124
@ STRSC_CaseInsensitive
Literals and character sets match without regard to case.
Definition strscan.h:65
Core string types and fundamental operations.
int32 pos
Current byte offset.
Definition strscan.h:74
int32 errpos
Offset where the scan first failed, or -1.
Definition strscan.h:75
bool ok
False once anything has failed; every later call is a no-op.
Definition strscan.h:76
flags_t flags
STRSC_FLAGS the scanner was created with.
Definition strscan.h:77
strref s
String being scanned (borrowed)
Definition strscan.h:73