Evo C++ Library v0.5.1
Classes | Macros | Typedefs
EvoTokenizers

Evo string tokenizers. More...

Classes

class  StrTok
 String forward tokenizer. More...
 
class  StrTokBase
 Base tokenizer class – see StrTok and StrTokR. More...
 
class  StrTokLine
 String line tokenizer. More...
 
class  StrTokR
 String reverse tokenizer. More...
 
class  StrTokRS
 String reverse tokenizer (strict). More...
 
class  StrTokS
 String forward tokenizer (strict). More...
 
struct  StrTokVariant< T, NextCh, NextAny >
 String tokenizer adapter used internally to create variants of existing tokenizers – do not use directly. More...
 

Macros

#define EVO_TOK_NEXT_OR_BREAK(TOK, DELIM)   if (!TOK.next(DELIM)) break
 Helper for tokenizing using a break-loop. More...
 
#define EVO_TOK_OR_BREAK(EXPR)   if (!EXPR) break
 Helper for tokenizing using a break-loop. More...
 

Typedefs

typedef StrTokVariant< StrTok,&StrTok::nextq,&StrTok::nextanyqStrTokQ
 String forward tokenizer based on StrTok with quoted token support. More...
 
typedef StrTokVariant< StrTokR,&StrTokR::nextq,&StrTokR::nextanyqStrTokQR
 String reverse tokenizer based on StrTokR with quoted token support. More...
 
typedef StrTokVariant< StrTok,&StrTok::nextwStrTokWord
 String forward word tokenizer based on StrTok. More...
 
typedef StrTokVariant< StrTokR,&StrTokR::nextwStrTokWordR
 String reverse word tokenizer based on StrTokR. More...
 
typedef StrTokVariant< StrTokRS,&StrTokRS::nextwStrTokWordRS
 String reverse word tokenizer based on StrTokRS (strict). More...
 
typedef StrTokVariant< StrTokS,&StrTokS::nextwStrTokWordS
 String forward word tokenizer based on StrTokS (strict). More...
 

Detailed Description

Evo string tokenizers.

Macro Definition Documentation

◆ EVO_TOK_NEXT_OR_BREAK

#define EVO_TOK_NEXT_OR_BREAK (   TOK,
  DELIM 
)    if (!TOK.next(DELIM)) break

Helper for tokenizing using a break-loop.

  • A break-loop is a loop that always breaks at the end so doesn't actually loop, but also allows an early break to skip remaining code in the loop
  • This calls TOK.next() and if it fails this does a break to stop current loop
  • This makes tokenizing and validating fields more readable by condensing repetitive if-statements
  • See also: EVO_TOK_OR_BREAK()
Example

These examples use assert() to represent field validation.

#include <evo/strtok.h>
using namespace evo;
int main() {
StrTok tok("1,2,3");
for (;;) {
// Field 1
assert(tok.value() == "1");
// Field 2
assert(tok.value() == "2");
// Field 3
assert(tok.value() == "3");
// Field 4
assert(false);
break;
}
return 0;
}

When used with StrTokLine, leave the DELIM argument empty.

#include <evo/strtok.h>
using namespace evo;
int main() {
StrTokLine tok("1\n2");
for (;;) {
// Line 1
assert(tok.value() == "1");
// Line 2
assert(tok.value() == "2");
break;
}
return 0;
}

◆ EVO_TOK_OR_BREAK

#define EVO_TOK_OR_BREAK (   EXPR)    if (!EXPR) break

Helper for tokenizing using a break-loop.

  • A break-loop is a loop that always breaks at the end so doesn't actually loop, but also allows an early break to skip remaining code in the loop
  • This is similar to EVO_TOK_NEXT_OR_BREAK(), but allows using a more generic expression
Example

These examples use assert() to represent field validation.

#include <evo/strtok.h>
using namespace evo;
int main() {
StrTok tok("1,'2a,2b',3");
for (;;) {
// Field 1
EVO_TOK_OR_BREAK(tok.nextq(','));
assert(tok.value() == "1");
// Field 2
EVO_TOK_OR_BREAK(tok.nextq(','));
assert(tok.value() == "2a,2b");
// Field 3
EVO_TOK_OR_BREAK(tok.nextq(','));
assert(tok.value() == "3");
// Field 4
EVO_TOK_OR_BREAK(tok.nextq(','));
assert(false);
break;
}
return 0;
}

Typedef Documentation

◆ StrTokQ

String forward tokenizer based on StrTok with quoted token support.

Example:

#include <evo/strtok.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
SubString str = "one, \"two\", three";
// Tokens:
// one
// two
// three
StrTokQ tok(str);
while (tok.next(','))
c.out << tok.value();
return 0;
}

◆ StrTokQR

String reverse tokenizer based on StrTokR with quoted token support.

Example:

#include <evo/strtok.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
SubString str = "one, \"two\", three";
// Tokens:
// three
// two
// one
StrTokQR tok(str);
while (tok.next(','))
c.out << tok.value();
return 0;
}

◆ StrTokWord

String forward word tokenizer based on StrTok.

Example:

#include <evo/strtok.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
SubString str = "one, two, three";
// Tokens:
// one
// two
// three
StrTokWord tok(str);
while (tok.next(','))
c.out << tok.value();
return 0;
}

◆ StrTokWordR

String reverse word tokenizer based on StrTokR.

Example:

#include <evo/strtok.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
SubString str = "one, two, three";
// Tokens:
// three
// two
// one
StrTokWordR tok(str);
while (tok.next(','))
c.out << tok.value();
return 0;
}

◆ StrTokWordRS

String reverse word tokenizer based on StrTokRS (strict).

Example:

#include <evo/strtok.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
SubString str = "one,two,three";
// Tokens:
// three
// two
// one
StrTokWordRS tok(str);
while (tok.next(','))
c.out << tok.value();
return 0;
}

◆ StrTokWordS

String forward word tokenizer based on StrTokS (strict).

Example:

#include <evo/strtok.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
SubString str = "one,two,three";
// Tokens:
// one
// two
// three
StrTokWordS tok(str);
while (tok.next(','))
c.out << tok.value();
return 0;
}