1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// compile with
// gx splitdriver.cc -L ../tmp/ -lstring -lbobcat
#include <iostream>
#include "../string"
using namespace std;
using namespace FBB;
char const *typeName[] =
{
"DQUOTE_UNTERMINATED", // unterminated d-quoted element
"SQUOTE_UNTERMINATED", // unterminated s-quoted element
"ESCAPED_END", // word with plain \ at the end
"SEPARATOR", // separator encountered
"NORMAL", // normal string-element in the original string
"DQUOTE", // string-element originally surrounded by " chars
"SQUOTE", // string-element originally surrounded by ' chars
};
// enum SplitType
// {
// TOK, // 0 acts like strtok (10: addEmpty == false)
// TOKSEP, // 1 same, returns separators (11: addempty true)
// STR, // 2 acts like strstr
// STRSEP, // 3 same, but return separators
// };
int main(int argc, char **argv)
{
while (true)
{
cout << "? ";
int type;
cin >> type;
cin.ignore();
string line;
if (not getline(cin, line))
break;
// vector<String::SplitPair> vect{
// type >= 10 ?
// String::split(line, ",", type == 11)
// :
// String::split(line,
// static_cast<String::SplitType>(type), ",") };
vector<String::SplitPair> vect;
if (type >= 10)
String::split(&vect, line, ",", type == 11);
else
String::split(&vect, line,
static_cast<String::SplitType>(type), ",");
for (auto const &element: vect)
cout << '`' << element.first << "': " <<
typeName[element.second] << '\n';
// String::Type strType;
// vector<string> vect{
// type >= 10 ?
// String::split(&strType, line, ",", type == 11)
// :
// String::split(&strType, line,
// static_cast<String::SplitType>(type), ",")
// };
//
// cout << "Final type: " << strType << '\n';
// vector<string> vect;
// if (type >= 10)
// String::split(&vect, line, ",", type == 11);
// else
// String::split(&vect, line,
// static_cast<String::SplitType>(type), ",");
//
// for (auto const &element: vect)
// cout << '`' << element << "'\n";
}
}
|