File: splitdriver.cc

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (83 lines) | stat: -rw-r--r-- 2,558 bytes parent folder | download | duplicates (3)
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";
   }
}