File: driver.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 (69 lines) | stat: -rw-r--r-- 2,058 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
#include <iostream>
#include <vector>
#include <bobcat/string>

using namespace std;
using namespace FBB;

static char const *type[] =
{
    "DQUOTE_UNTERMINATED",
    "SQUOTE_UNTERMINATED",
    "ESCAPED_END",
    "SEPARATOR",
    "NORMAL",
    "DQUOTE",
    "SQUOTE",
};

int main(int argc, char **argv)
{
    cout << "Program's name in uppercase: " << String::uc(argv[0]) << "\n\n";

    vector<String::SplitPair> splitpair;
    string text{ "one, two, 'thr\\x65\\145'" };
    string encoded{ String::urlEncode(text) };

    cout << "The string `" << text << "'\n"
            "   as url-encoded string: `" << encoded << "'\n"
            "   and the latter string url-decoded: " <<
                                    String::urlDecode(encoded) << "\n"
            "\n"
            "Splitting `" << text << "' into " <<
                    String::split(&splitpair, text, String::STRSEP, ", ") <<
                " fields\n";

    for (auto it = splitpair.begin(); it != splitpair.end(); ++it)
        cout << (it - splitpair.begin() + 1) << ": " <<
                type[it->second] << ": `" << it->first <<
                "', unescaped: `" << String::unescape(it->first) <<
                "'\n";

    cout << '\n' <<
        text << ":\n"
        "   upper case: " << String::uc(text) << ",\n"
        "   lower case: " << String::lc(text) << '\n';
}

/*
    Calling the program as
        driver'
    results in the following output:
        Program's name in uppercase: DRIVER

        Splitting `one, two, 'thr\x65\145'' into 9 fields
        1: NORMAL: `one', unescaped: `one'
        2: SEPARATOR: `,', unescaped: `,'
        3: NORMAL: `', unescaped: `'
        4: SEPARATOR: ` ', unescaped: ` '
        5: NORMAL: `two', unescaped: `two'
        6: SEPARATOR: `,', unescaped: `,'
        7: NORMAL: `', unescaped: `'
        8: SEPARATOR: ` ', unescaped: ` '
        9: SQUOTE: `thr\x65\145', unescaped: `three'

        one, two, 'thr\x65\145':
           upper case: ONE, TWO, 'THR\X65\145',
           lower case: one, two, 'thr\x65\145'

*/