41#define NV_MAX_TOKEN_LEN 1024
42#define NV_MAX_DELIM_COUNT 16
60 explicit Tokenizer(
const char* src,
const char* delims =
nullptr)
67 if (
nullptr == delims)
79 while (mNumDelims < NV_MAX_DELIM_COUNT && delims[i])
81 const char c = delims[i++];
83 if (c ==
' ' || c ==
'\t' ||
84 c ==
'"' || c ==
'\'' ||
85 c ==
'\n' || c ==
'\r')
87 mDelims[mNumDelims++] = c;
104 return (
' ' == c ||
'\t' == c);
112 return (
'"' == c ||
'\'' == c);
120 return (
'\n' == c ||
'\r' == c);
136 for (uint32_t i = 0; i < mNumDelims; i++)
137 if (c == mDelims[i])
return true;
149 return (0 == *mSrcBuf);
160 mTermChar = *mSrcBuf++;
174 mTermChar = *mSrcBuf++;
177 mTermChar = *mSrcBuf;
196 char startedWithQuote = 0;
206 startedWithQuote = *mSrcBuf;
212 if (
isEOL(*mSrcBuf)) {
213 mTermChar = *mSrcBuf;
217 if (startedWithQuote) {
218 if (startedWithQuote == *mSrcBuf) {
221 mTermChar = startedWithQuote;
227 mTermChar = *mSrcBuf;
231 mTokBuf[mTokLen] = *mSrcBuf;
237 mTokBuf[mTokLen] = 0;
239 return (mTokLen > 0 || startedWithQuote);
248 if (find ==
nullptr || find[0] == 0)
253 const size_t findlen = strlen(find);
254 if (findlen != mTokLen)
256 if (0 != memcmp(mTokBuf, find, findlen))
293 returnTok.assign(mTokBuf);
324 returnTok.assign(mTokBuf);
342 if (mTokLen > outmax)
345 memcpy(out, mTokBuf, outmax - 1);
349 memcpy(out, mTokBuf, mTokLen + 1);
364 out = (float)strtod(mTokBuf,
nullptr);
377 char firstdelim = 0, delim = 0;
382 if (delim == firstdelim)
387 out[i++] = (float)strtod(mTokBuf,
nullptr);
391 if (delim &&
isEOL(delim))
393 if (i == 1) firstdelim = delim;
407 char firstdelim = 0, delim = 0;
412 if (delim == firstdelim)
417 out[i++] = (int32_t)strtol(mTokBuf,
nullptr, 0);
421 if (delim &&
isEOL(delim))
423 if (i == 1) firstdelim = delim;
439 out = (int32_t)strtol(mTokBuf,
nullptr, 0);
454 out = (uint32_t)strtoul(mTokBuf,
nullptr, 0);
470 (mTokBuf[0] ==
'0' || mTokBuf[0] ==
'1')) {
471 out = (mTokBuf[0] ==
'1');
474 else if ((0 == strcmp(mTokBuf,
"true")) ||
475 (0 == strcmp(mTokBuf,
"TRUE")) ||
476 (0 == strcmp(mTokBuf,
"yes")) ||
477 (0 == strcmp(mTokBuf,
"YES"))) {
481 else if ((0 == strcmp(mTokBuf,
"false")) ||
482 (0 == strcmp(mTokBuf,
"FALSE")) ||
483 (0 == strcmp(mTokBuf,
"no")) ||
484 (0 == strcmp(mTokBuf,
"NO"))) {
494 char mTokBuf[NV_MAX_TOKEN_LEN];
497 char mDelims[NV_MAX_DELIM_COUNT];
bool getTokenString(std::string &returnTok)
Gets the next token as a std::string.
Definition tokenizer.h:318
bool getTokenString(char out[], const uint32_t outmax)
Gets the next token as a char array with a maximum size.
Definition tokenizer.h:334
uint32_t getTokenIntArray(int32_t out[], uint32_t size)
Gets the next tokens as an array of integer numbers.
Definition tokenizer.h:404
bool getLastToken(std::string &returnTok)
Gets the last read token as a std::string.
Definition tokenizer.h:289
bool atEOF()
Checks if the tokenizer has reached the end of the source string.
Definition tokenizer.h:147
bool isWhitespace(const char c)
Checks if the given character is a whitespace character.
Definition tokenizer.h:103
char consumeOneDelim()
Consumes one delimiter character from the source string.
Definition tokenizer.h:167
bool getTokenFloat(float &out)
Gets the next token as a floating-point number.
Definition tokenizer.h:358
uint32_t getTokenFloatArray(float out[], uint32_t size)
Gets the next tokens as an array of floating-point numbers.
Definition tokenizer.h:374
bool requireToken(const char *find)
Checks if the next token matches the given string.
Definition tokenizer.h:246
bool getTokenUint(uint32_t &out)
Gets the next token as an unsigned integer.
Definition tokenizer.h:448
void setConsumeWS(bool ws)
Sets whether to consume whitespace characters.
Definition tokenizer.h:96
char consumeWhitespace()
Consumes whitespace characters from the source string.
Definition tokenizer.h:155
Tokenizer(const char *src, const char *delims=nullptr)
Constructor that initializes the tokenizer with a source string and optional delimiters.
Definition tokenizer.h:60
bool getTokenInt(int32_t &out)
Gets the next token as an integer.
Definition tokenizer.h:433
bool isDelim(const char c)
Checks if the given character is a delimiter.
Definition tokenizer.h:135
const char * getLastTokenPtr()
Gets the last read token as a const char*.
Definition tokenizer.h:301
bool isTerm(const char c)
Checks if the given character is a termination character.
Definition tokenizer.h:127
char getTermChar() const
Gets the character that caused the stop of the last token read.
Definition tokenizer.h:280
uint32_t getLastTokenLen() const
Gets the length of the last read token.
Definition tokenizer.h:309
bool getTokenBool(bool &out)
Gets the next token as a boolean value.
Definition tokenizer.h:463
bool isEOL(const char c)
Checks if the given character is an end-of-line character.
Definition tokenizer.h:119
void consumeToEOL()
Consumes characters up to the end of the line.
Definition tokenizer.h:183
bool requireTokenDelim(const char *find)
Checks if the next token matches the given string and consumes a delimiter.
Definition tokenizer.h:266
bool readToken()
Reads the next token from the source string.
Definition tokenizer.h:194
bool isQuote(const char c)
Checks if the given character is a quote character.
Definition tokenizer.h:111
Definition collider.cpp:182