8 #ifndef INCL_evo_strtok_h 9 #define INCL_evo_strtok_h 65 string_ ( src.string_ ),
72 void copy(
const BaseType& src) {
147 { this->
copy(src);
return *
this; }
154 { this->
copy(src);
return *
this; }
195 for (
char ch; ind < size && ((ch=data[ind]) ==
' ' || ch ==
'\t'); )
207 const char* p = (
char*)::memchr(data, delim, size);
213 size = (
Size)(p - data);
216 ind = ind + size + 1;
242 for (
char ch; ind < size && ((ch=data[ind]) ==
' ' || ch ==
'\t'); )
252 const char* start = data + ind;
253 const char* end = data + size;
256 const char* p =
str_scan_endq(startq, endq, start, end, delim);
257 size = (
Size)(endq - startq);
265 ind = (
Size)(p + 1 - data);
289 for (
char ch; ind < size && ((ch=data[ind]) ==
' ' || ch ==
'\t' || ch == delim); )
301 const char* p = (
char*)::memchr(data, delim, size);
307 size = (
Size)(p - data);
310 ind = ind + size + 1;
332 for (
char ch; ind < size && ((ch=data[ind]) ==
' ' || ch ==
'\t'); )
343 const char* start = data + ind;
344 const char* end = start + size;
346 size = (
Size)(p - start);
353 ind = (
Size)(p + 1 - data);
380 for (
char ch; ind < size && ((ch=data[ind]) ==
' ' || ch ==
'\t'); )
393 ws_delim_char = (ws_i ==
NONE ? 0 : delims.
data_[ws_i]);
395 ws_delim_char = ws_delim;
398 const char* start = data + ind;
399 const char* end = data + size;
403 size = (
Size)(endq - startq);
411 ind = (
Size)(p + 1 - data);
429 return nextanyq(delims, 1);
442 for (
char ch; ind < size && ((ch=data[ind]) ==
' ' || ch ==
'\t'); )
458 template<
class C,
class T>
459 static typename C::Size
split(C& items,
const T& str,
char delim=
',') {
460 typename C::Size count = 0;
482 { result = tok.
value();
break; }
490 Size& ind_ = this->
index_;
493 while ( ind_ < str_size_ && ((ch=str_data_[ind_]) ==
' ' || ch ==
'\t') )
495 if (ind_ >= str_size_)
565 { this->
copy(src);
return *
this; }
572 { this->
copy(src);
return *
this; }
611 for (
char ch; ind > 0 && ((ch=data[ind - 1]) ==
' ' || ch ==
'\t'); )
627 size = (
Size)(data + ind - (++p));
630 ind = ind - size - 1;
655 for (
char ch; ind > 0 && ((ch=data[ind - 1]) ==
' ' || ch ==
'\t'); )
665 const char* end = data + ind;
669 size = (
Size)(endq - startq);
677 ind = (
Size)(p - data);
702 for (
char ch; ind > 0 && ((ch=data[ind - 1]) ==
' ' || ch ==
'\t' || ch == delim); )
718 size = (
Size)(data + ind - (++p));
721 ind = ind - size - 1;
743 for (
char ch; ind > 0 && ((ch=data[ind - 1]) ==
' ' || ch ==
'\t'); )
753 const char* end = data + ind;
755 size = (
Size)(end - p);
763 ind = (
Size)(p - data);
790 for (
char ch; ind > 0 && ((ch=data[ind - 1]) ==
' ' || ch ==
'\t'); )
803 ws_delim_char = (ws_i ==
NONE ? 0 : delims.
data_[ws_i]);
805 ws_delim_char = ws_delim;
808 const char* end = data + ind;
812 size = (
Size)(endq - startq);
820 ind = (
Size)(p - data);
839 return nextanyq(delims, 1);
853 template<
class C,
class T>
854 static typename C::Size
split(C& items,
const T& str,
char delim=
',') {
855 typename C::Size count = 0;
877 { result = tok.
value();
break; }
884 Size& ind_ = this->
index_;
887 while ( ind_ > 0 && ((ch=str_data_[ind_-1]) ==
' ' || ch ==
'\t') )
959 { this->
copy(src);
return *
this; }
966 { this->
copy(src);
return *
this; }
1001 }
else if (ind == size) {
1011 const char* p = (
char*)::memchr(data, delim, size);
1017 size = (
Size)(p - data);
1020 ind = ind + size + 1;
1032 Size& ind = this->
index_;
1042 while (ind < size && data[ind] == delim)
1054 const char* p = (
char*)::memchr(data, delim, size);
1060 size = (
Size)(p - data);
1063 ind = ind + size + 1;
1073 Size& ind = this->
index_;
1079 }
else if (ind == size) {
1089 const char* start = data + ind;
1090 const char* end = start + size;
1092 size = (
Size)(p - start);
1099 ind = (
Size)(p + 1 - data);
1115 template<
class C,
class T>
1116 static typename C::Size
split(C& items,
const T& str,
char delim=
',') {
1117 typename C::Size count = 0;
1139 { result = tok.
value();
break; }
1209 { this->
copy(src);
return *
this; }
1216 { this->
copy(src);
return *
this; }
1245 Size& ind = this->
index_;
1251 }
else if (ind == 0) {
1266 size = (
Size)(data + ind - (++p));
1269 ind = ind - size - 1;
1281 Size& ind = this->
index_;
1291 while (ind > 0 && data[ind - 1] == delim)
1307 size = (
Size)(data + ind - (++p));
1310 ind = ind - size - 1;
1320 Size& ind = this->
index_;
1326 }
else if (ind == 0) {
1335 const char* end = data + ind;
1337 size = (
Size)(end - p);
1345 ind = (
Size)(p - data);
1361 template<
class C,
class T>
1362 static typename C::Size
split(C& items,
const T& str,
char delim=
',') {
1363 typename C::Size count = 0;
1385 { result = tok.
value();
break; }
1400 template<
class T,
bool (T::*NextCh)(
char),
bool (T::*NextAny)(const StringBase&)=&T::nextany>
1416 { this->
copy(src);
return *
this; }
1418 { this->
copy(src);
return *
this; }
1420 { T::operator=(str);
return *
this; }
1423 {
return ( ((T*)
this)->*NextCh )(
delim); }
1425 {
return ( ((T*)
this)->*NextAny )(delims); }
1427 template<
class C,
class S>
1428 static typename C::Size
split(C& items,
const S& str,
char delim=
',') {
1429 typename C::Size count = 0;
1431 for (; (tok.*NextCh)(
delim); ++count)
1432 items.add( tok.value().template convert<typename C::Item>() );
1440 for (Size i=0; (tok.*NextCh)(
delim); ++i)
1442 { result = tok.value();
break; }
1675 { this->
copy(src);
return *
this; }
1679 { this->
copy(src);
return *
this; }
1706 Size& ind = this->
index_;
1712 }
else if (ind == size) {
1722 const char* start = data + ind;
1723 const char* end = start + size;
1725 size = (
Size)(p - start);
1731 ind = (
Size)(p + 1 - data);
1732 if (p + 1 < end && ((*p ==
'\r' && p[1] ==
'\n') || (*p ==
'\n' && p[1] ==
'\r')))
1748 template<
class C,
class T>
1749 static typename C::Size
split(C& items,
const T& str) {
1750 typename C::Size count = 0;
1752 for (; tok.
next(); ++count)
1769 for (Size i=0; tok.
next(); ++i)
1771 result = tok.
value();
1780 Size& ind_ = this->
index_;
1782 if (ind_ >= str_size_)
1854 #define EVO_TOK_NEXT_OR_BREAK(TOK, DELIM) if (!TOK.next(DELIM)) break 1895 #define EVO_TOK_OR_BREAK(EXPR) if (!EXPR) break StrTokLine(const BaseType &src)
Copy constructor.
Definition: strtok.h:1666
C convert() const
Convert string to value of given type.
Definition: substring.h:1427
StrTokR()
Default constructor creates empty tokenizer.
Definition: strtok.h:539
StrTokVariant()
Definition: strtok.h:1406
StrTokS ThisType
This type.
Definition: strtok.h:928
StrTok(const ThisType &src)
Copy constructor.
Definition: strtok.h:125
ThisType & operator=(const ThisType &src)
Assignment/Copy operator.
Definition: strtok.h:564
static C::Size split(C &items, const T &str)
Split string lines into list using next().
Definition: strtok.h:1749
StrTokLine(const StringBase &str)
Constructor to start tokenizing given string.
Definition: strtok.h:1670
bool nextany(const StringBase &delims)
Find next token using any of given delimiters.
Definition: strtok.h:1072
const char * str_scan_endq_r(const char *&startq, const char *&endq, const char *str, const char *end, char delim)
Scan string pointer in reverse and extract quoted or unquoted text with a delimiter and return new en...
Definition: strscan.h:1362
const char * str_scan_delim(const char *str, const char *end, char delim1, char delim2)
Scan string pointer for next delimiter and return stop pointer.
Definition: strscan.h:1037
StrTokVariant(const ThisType &src)
Definition: strtok.h:1408
Size skipws()
Advance current position for next token by skipping whitespace.
Definition: strtok.h:438
StrTokLine()
Default constructor creates empty tokenizer.
Definition: strtok.h:1658
StrTokBase BaseType
Base type.
Definition: strtok.h:535
bool nextw(char delim)
Find next token using word delimiter (in reverse order).
Definition: strtok.h:691
Nullable< T > & set()
Set as null.
Definition: type.h:342
StrTokVariant(const StringBase &str)
Definition: strtok.h:1412
bool next()
Find next token by finding next newline or newline pair.
Definition: strtok.h:1705
static C::Size split(C &items, const T &str, char delim=',')
Split delimited string into item list using next().
Definition: strtok.h:459
ThisType & reset()
Reset to tokenize from beginning of string.
Definition: strtok.h:983
static SubString splitat(const T &str, Size index)
Split string lines to extract token at line index.
Definition: strtok.h:1766
Basic character type (char) – see CharT.
Definition: type.h:775
ThisType & operator=(const ThisType &src)
Assignment/Copy operator.
Definition: strtok.h:1674
ThisType & operator=(const StringBase &str)
Assignment operator to start tokenizing given string from beginning.
Definition: strtok.h:1682
StrTok(const StringBase &str)
Constructor to start tokenizing given string.
Definition: strtok.h:139
ThisType & operator=(const StringBase &str)
Assignment operator to start tokenizing given string from beginning.
Definition: strtok.h:160
ThisType & reset()
Reset to tokenize from beginning of string.
Definition: strtok.h:171
StrTokLine(const ThisType &src)
Copy constructor.
Definition: strtok.h:1662
String tokenizer adapter used internally to create variants of existing tokenizers – do not use dire...
Definition: strtok.h:1401
SubString::Size Size
String size type
Definition: strtok.h:116
StrTokRS ThisType
This type.
Definition: strtok.h:1178
StrTokVariant< StrTokR,&StrTokR::nextq,&StrTokR::nextanyq > StrTokQR
String reverse tokenizer based on StrTokR with quoted token support.
Definition: strtok.h:1501
StrTok(const BaseType &src)
Copy constructor.
Definition: strtok.h:131
StrTokBase BaseType
Base type.
Definition: strtok.h:1179
StrTokBase()
Default constructor creates empty tokenizer.
Definition: strtok.h:52
SubString::Size Size
String size type
Definition: strtok.h:25
ThisType & operator=(const BaseType &src)
Assignment/Copy operator.
Definition: strtok.h:1678
Key findany(const char *chars, Size count, Key start=0, Key end=END) const
Find first occurrence of any given characters with forward search.
Definition: substring.h:828
ThisType & operator=(const ThisType &src)
Assignment/Copy operator.
Definition: strtok.h:958
bool next(char delim)
Find next token using delimiter.
Definition: strtok.h:994
StrTok()
Default constructor creates empty tokenizer.
Definition: strtok.h:119
String line tokenizer.
Definition: strtok.h:1651
StrTokR(const ThisType &src)
Copy constructor.
Definition: strtok.h:545
StrTokBase BaseType
Base type.
Definition: strtok.h:24
StrTokRS()
Default constructor creates empty tokenizer.
Definition: strtok.h:1183
static SubString splitat(const T &str, Size index, char delim=',')
Split delimited string to extract token at index (in reverse order).
Definition: strtok.h:1380
static C::Size split(C &items, const S &str, char delim=',')
Definition: strtok.h:1428
StrTokVariant(const BaseType &src)
Definition: strtok.h:1410
Size index() const
Get current index before next token.
Definition: strtok.h:30
StrTokR(const StringBase &str)
Constructor to start tokenizing given string.
Definition: strtok.h:557
ThisType & operator=(const StringBase &str)
Assignment operator to start tokenizing given string from beginning.
Definition: strtok.h:972
StrTokBase BaseType
Base type.
Definition: strtok.h:929
bool nextw(char delim)
Find next token using word delimiter.
Definition: strtok.h:1031
StrSizeT Size
List size integer type.
Definition: sublist.h:150
uint32 StrSizeT
Default Evo string size type.
Definition: sys.h:734
const char * string_memrchr(const char *str, char ch, size_t size)
Evo implementation of memrchr() to search for character in reverse.
Definition: str.h:1150
SubString::Size Size
String size type
Definition: strtok.h:1180
bool nextw(char delim)
Find next token using word delimiter (in reverse order).
Definition: strtok.h:1280
bool next(char delim)
Find next token using delimiter (in reverse order).
Definition: strtok.h:600
ThisType & operator=(const BaseType &src)
Assignment/Copy operator.
Definition: strtok.h:153
bool nextq(char delim)
Find next token using delimiter with quoting support.
Definition: strtok.h:231
ThisType & operator=(const ThisType &src)
Definition: strtok.h:1415
SubString & stripl()
Strip left (beginning) whitespace (spaces and tabs).
Definition: substring.h:1090
bool nextanyq(const StringBase &delims)
Find next token using any of given delimiters with quoting support.
Definition: strtok.h:428
SubString & stripr()
Strip right (ending) whitespace (spaces and tabs).
Definition: substring.h:1135
SubString::Size Size
String size type
Definition: strtok.h:1655
static const EndT END
Special integer value for indicating end of items or no item.
Definition: type.h:1846
SubString value_
Current value.
Definition: strtok.h:49
bool nextanyq(const StringBase &delims)
Find next token using any of given delimiters (in reverse order) with quoting support.
Definition: strtok.h:838
StrTokS(const ThisType &src)
Copy constructor.
Definition: strtok.h:939
SubString string_
String being tokenized, NULL for none
Definition: strtok.h:46
void copy(const BaseType &src)
Copy data.
Definition: strtok.h:72
StrTokBase(const BaseType &src)
Copy constructor.
Definition: strtok.h:64
const SubString & value() const
Get current token value from last call to next().
Definition: strtok.h:42
const char * str_scan_nws_r(const char *str, const char *end)
Scan string pointer for next non-whitespace character in reverse and return new end after stop pointe...
Definition: strscan.h:896
StrTokBase BaseType
Base type.
Definition: strtok.h:1654
const char * str_scan_endq(const char *&startq, const char *&endq, const char *str, const char *end)
Scan string pointer and extract quoted or unquoted text.
Definition: strscan.h:1172
StrTokVariant< StrTokR,&StrTokR::nextw > StrTokWordR
String reverse word tokenizer based on StrTokR.
Definition: strtok.h:1559
bool nextany(const StringBase &delims)
Find next token using any of given delimiters (in reverse order).
Definition: strtok.h:1319
StrTokBase BaseType
Root base type.
Definition: strtok.h:1403
bool nextanyq(const StringBase &delims, char ws_delim)
Find next token using any of given delimiters with quoting support.
Definition: strtok.h:369
static C::Size split(C &items, const T &str, char delim=',')
Split delimited string into item list using next() (in reverse order).
Definition: strtok.h:854
String reverse tokenizer (strict).
Definition: strtok.h:1176
ThisType & reset()
Reset to tokenize from beginning of string.
Definition: strtok.h:1691
bool nextanyq(const StringBase &delims, char ws_delim)
Find next token using any of given delimiters (in reverse order) with quoting support.
Definition: strtok.h:779
bool next(char delim)
Definition: strtok.h:1422
ThisType & operator=(const BaseType &src)
Definition: strtok.h:1417
ThisType & operator=(const ThisType &src)
Assignment/Copy operator.
Definition: strtok.h:146
bool nextw(char delim)
Find next token using word delimiter.
Definition: strtok.h:278
Evo C++ Library namespace.
Definition: alg.h:11
static const EndT NONE
Special integer value for indicating no item or unknown item.
Definition: type.h:1832
StrTokBase BaseType
Base type.
Definition: strtok.h:115
String forward tokenizer (strict).
Definition: strtok.h:926
ThisType & reset()
Reset to tokenize from beginning of string.
Definition: strtok.h:1233
SubString::Size Size
String size type
Definition: strtok.h:1404
StrTokVariant< T, NextCh, NextAny > ThisType
This type.
Definition: strtok.h:1402
SubString::Size Size
String size type
Definition: strtok.h:930
ThisType & operator=(const StringBase &str)
Assignment operator to start tokenizing given string from end.
Definition: strtok.h:1222
ThisType & operator=(const BaseType &src)
Assignment/Copy operator.
Definition: strtok.h:1215
ThisType & operator=(const StringBase &str)
Definition: strtok.h:1419
StrTokVariant< StrTok,&StrTok::nextq,&StrTok::nextanyq > StrTokQ
String forward tokenizer based on StrTok with quoted token support.
Definition: strtok.h:1474
bool nextany(const StringBase &delims)
Find next token using any of given delimiters (in reverse order).
Definition: strtok.h:732
bool nextany(const StringBase &delims)
Find next token using any of given delimiters.
Definition: strtok.h:321
String reverse tokenizer.
Definition: strtok.h:532
Char delim() const
Get current delimiter before next token.
Definition: strtok.h:36
SubString & strip()
Strip left (beginning) and right (ending) whitespace (spaces and tabs).
Definition: substring.h:1061
ThisType & operator=(const StringBase &str)
Assignment operator to start tokenizing given string from end.
Definition: strtok.h:578
bool next(char delim)
Find next token using delimiter.
Definition: strtok.h:184
SubString & setempty()
Set as empty but not null.
Definition: substring.h:1303
T * data_
Data pointer, NULL if null.
Definition: sys.h:979
StrTokVariant< StrTokRS,&StrTokRS::nextw > StrTokWordRS
String reverse word tokenizer based on StrTokRS (strict).
Definition: strtok.h:1615
String forward tokenizer.
Definition: strtok.h:112
StrTokLine ThisType
This type.
Definition: strtok.h:1653
static SubString splitat(const T &str, Size index, char delim=',')
Split delimited string to extract token at index (in reverse order).
Definition: strtok.h:872
bool nextany(const StringBase &delims)
Definition: strtok.h:1424
StrTokVariant< StrTokS,&StrTokS::nextw > StrTokWordS
String forward word tokenizer based on StrTokS (strict).
Definition: strtok.h:1587
StrTokRS(const ThisType &src)
Copy constructor.
Definition: strtok.h:1189
bool next(char delim)
Find next token using delimiter (in reverse order).
Definition: strtok.h:1244
ThisType & operator=(const BaseType &src)
Assignment/Copy operator.
Definition: strtok.h:571
SubString::Size Size
String size type
Definition: strtok.h:536
TSize size_
Data size as item count, 0 if empty or null.
Definition: sys.h:980
StrTokR ThisType
This type.
Definition: strtok.h:534
ThisType & reset()
Reset to tokenize from beginning of string.
Definition: strtok.h:589
ThisType & operator=(const ThisType &src)
Assignment/Copy operator.
Definition: strtok.h:1208
StrTokRS(const StringBase &str)
Constructor to start tokenizing given string.
Definition: strtok.h:1201
static C::Size split(C &items, const T &str, char delim=',')
Split delimited string into item list using next() (in reverse order).
Definition: strtok.h:1362
const char * str_scan_delim_r(const char *str, const char *end, char delim1, char delim2)
Scan string pointer for next delimiter in reverse and return new end after stop pointer.
Definition: strscan.h:1058
StrTokS()
Default constructor creates empty tokenizer.
Definition: strtok.h:933
bool nextq(char delim)
Find next token with quoting support using delimiter (in reverse order) with quoting support...
Definition: strtok.h:644
static SubString splitat(const S &str, Size index, char delim=',')
Definition: strtok.h:1437
StrTokVariant< StrTok,&StrTok::nextw > StrTokWord
String forward word tokenizer based on StrTok.
Definition: strtok.h:1531
StrTokS(const StringBase &str)
Constructor to start tokenizing given string.
Definition: strtok.h:951
SubString & set(const char *data)
Set as reference to terminated string.
Definition: substring.h:353
StrTokS(const BaseType &src)
Copy constructor.
Definition: strtok.h:945
Char delim_
Current delimiter, null when none or at end.
Definition: strtok.h:48
Base tokenizer class – see StrTok and StrTokR.
Definition: strtok.h:22
Reference and access existing string data.
Definition: substring.h:229
static C::Size split(C &items, const T &str, char delim=',')
Split delimited string into item list using next().
Definition: strtok.h:1116
static SubString splitat(const T &str, Size index, char delim=',')
Split delimited string to extract token at index.
Definition: strtok.h:1134
Base for all Evo list types (used internally).
Definition: sys.h:976
Size index_
Current index, END when at end.
Definition: strtok.h:47
StrTokBase(const StringBase &string)
Default constructor creates empty tokenizer.
Definition: strtok.h:56
ThisType & operator=(const BaseType &src)
Assignment/Copy operator.
Definition: strtok.h:965
StrTok ThisType
This type.
Definition: strtok.h:114
StrTokR(const BaseType &src)
Copy constructor.
Definition: strtok.h:551
static SubString splitat(const T &str, Size index, char delim=',')
Split delimited string to extract token at index.
Definition: strtok.h:477
StrTokRS(const BaseType &src)
Copy constructor.
Definition: strtok.h:1195