This class offers the same functionality as std::string, adding
facilities for often used transformations, currently missing in
std::string.
NAMESPACE
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
INHERITS FROM
--
ENUMERATION
Type:
This enumeration has the following values, which are used in the second
variant of the split member (see below):
DQUOTE, a series of characters surrounded by double quotes
in the original string;
DQUOTE_UNTERMINATED, a series of characters beginning with
a double quote in the original string, but lacking the matching terminating
double quote;
ESCAPED_END, a series of characters representing an
otherwise normal string, but terminating in a plain backslash;
NORMAL, a normal string;
SEPARATOR, a separator;
SQUOTE, a series of characters surrounded by single quotes
in the original string;
SQUOTE_UNTERMINATED, a series of characters beginning with
a single quote in the original string, but lacking the matching terminating
single quote.
TYPEDEF
The typedef SplitPair represents std::pair<std::string,
String::Type> and is used in the second variant of the split member (see
below).
HISTORY
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.
Currently String offers a series of static member functions
providing the facilities originally implemented in non-static members.
STATIC MEMBER FUNCTIONS
char const **argv(std::vector<std::string> const &words):
Returns a pointer to an allocated series of pointers to the C
strings stored in the vector words. The caller is responsible for
returning the array of pointers to the common pool, but should not delete
the C-strings to which the pointers point. The last element of the
returned array is guaranteed to be a 0-pointer.
int casecmp(std::string const &lhs, std::string const &rhs):
Performs a case-insensitive comparison between the two std::string
objects. A negative value is returned if lhs should be ordered before
rhs; 0 is returned if the two strings have identical contents; a
positive value is returned if the lhs object should be ordered beyond
rhs.
std::string escape(std::string const &str,
char const *series = "'\"\\"):
Returns a copy of the str object in which all characters in
series are prefixed by a backslash character.
std::string lc(std::string const &str) const:
Returns a copy of the str object in which all letters were
transformed to lower case letters.
std::string trim(std::string const &str):
Returns a copy of the str object from which the leading and
trailing blanks have been removed.
size_t split(std::vector<std::string> *words,
std::string const &str,
char const *separators = " \t", bool addEmpty = false):
Fills words with all elements of the str object, separated by
any of the characters in separators. If the parameter addEmpty is set
to true, the individual separators are stored as empty strings in
words. If a word starts with " or ' all characters until a
matching terminating " or ' at the end of a word are considered as one
word. The surrounding quotes are not stored. The function returns the number
of elements in the vector pointed to by words. This vector is initially
cleared.
size_t split(std::vector<SplitPair> *words,
std::string const &str,
char const *separators = " \t", bool addEmpty = false):
Same functionality as the former member, but the words vector is
filled with pairs, of which the first elements are the recognized strings, and
the second elements values of the String::Type enumeration. If
addEmpty is requested, then the string elements contain the actual
contents of the separator, while the Type elements are set to
SEPARATOR.
std::string unescape(std::string const &str):
Returns a copy of the str object in which the escaped (i.e.,
prefixed by a backslash) characters have been interpreted. All standard escape
characters (\a, \b, \f, \n, \r, \t, \v) are
recognized. If an escape character is followed by x or X the next two
characters are interpreted as a hexadecimal number. If an escape character is
followed by an octal digit, then the next three characters following the
backslash are interpreted as an octal number. In all other cases, the
backslash is removed and the character following the backslash is kept.
std::string uc(std::string const &str):
Returns a copy of the str object in which all letters were
capitalized.
EXAMPLE
#include <iostream>
#include <vector>
#include <bobcat/string>
using namespace std;
using namespace FBB;
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]) << endl;
if (argc == 1)
cout << "Provide any argument to suppress SEPARATOR fields\n";
while (true)
{
cout << "Enter a line, or empty line to stop:" << endl;
String line;
if (!getline(cin, line) || !line.length())
break;
vector<String::SplitPair> splitpair;
cout << "Split into " << line.split(&splitpair, " \t", argc == 1) <<
" fields\n";
for
(
vector<String::SplitPair>::iterator it = splitpair.begin();
it != splitpair.end();
++it
)
cout << (it - splitpair.begin() + 1) << ": " <<
type[it->second] << ": `" << it->first <<
"', unescaped: `" << String(it->first).unescape() <<
"'" << endl;
}
return 0;
}
FILES
bobcat/string - defines the class interface
SEE ALSO
bobcat(7)
BUGS
None Reported.
DISTRIBUTION FILES
bobcat_2.02.03-x.dsc: detached signature;
bobcat_2.02.03-x.tar.gz: source archive;
bobcat_2.02.03-x_i386.changes: change log;
libbobcat1_2.02.03-x_*.deb: debian package holding the
libraries;
libbobcat1-dev_2.02.03-x_*.deb: debian package holding the
libraries, headers and manual pages;
http://sourceforge.net/projects/bobcat: public archive location;
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).