FBB::String(3bobcat)

Operations on std::string objects
(libbobcat-dev_6.04.00)

2005-2023

NAME

FBB::String - Several operations on std::string objects

SYNOPSIS

#include <bobcat/string>
Linking option: -lbobcat

DESCRIPTION

This class offers facilities for often used transformations on std::string objects, which are not supported by the std::string class itself. All members of FBB::String are static.

Initially this class was derived from std::string. Deriving from std::string, however, is considerd bad design as std::string was not designed as a base-class.

FBB::String offers a series of static member functions providing the facilities originally implemented as non-static members. One of these members is the (overloaded) split member, splitting a string into elements separated by one or more configurable characters. These elements may contain or consist of double- or single-quoted (sub) strings and escape characters. Escape characters are converted to their implied byte-values (e.g., \n is converted to byte value 10) unless they are embedded in single-quoted (sub) strings. Quotes surrounding double- and single-quoted (sub) strings are removed from the elements returned by the split members.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

--

ENUMERATIONS

NESTED TYPE

The struct SplitPair defines a std::pair<std::string, String::Type> and is used by some overloaded split members (see below).

STATIC MEMBER FUNCTIONS

EXAMPLE

#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'

*/

FILES

bobcat/string - defines the class interface

SEE ALSO

bobcat(7)

BUGS

None Reported.

BOBCAT PROJECT FILES

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).