other versions
- jessie 3.23.01-1
- stretch 4.04.00-1
- testing 4.08.06-1
- unstable 4.08.06-1
- experimental 4.09.00-1
other sections
FBB::String(3bobcat) | Operations on std::string objects | FBB::String(3bobcat) |
NAME¶
FBB::String - Several operations on std::string objectsSYNOPSIS¶
#include <bobcat/string>DESCRIPTION¶
This class offers facilities for often used transformations on std::string objects, but which are not supported by the std::string class itself. All members of FBB::String are static.NAMESPACE¶
FBBINHERITS FROM¶
--ENUMERATION¶
- o
- Type:
- DQUOTE, a subset of the characters in the matching string element was delimited by double quotes in the in the string that was parsed by the split members.
- DQUOTE_UNTERMINATED, the contents of the string that was parsed by the split members started at some point with a double quote, but the matching ending double quote was lacking.
- ESCAPED_END, the contents of the string that was parsed by the split members ended in a mere backslash.
- NORMAL, a normal string;
- SEPARATOR, a separator;
- SQUOTE, a subset of the characters in the matching string element was delimited by quotes in the in the string that was parsed by the split members.
- SQUOTE_UNTERMINATED, the contents of the string that was parsed by the split members started at some point with a quote, but the matching ending quote was lacking.
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. FBB::String offers a series of static member functions providing the facilities originally implemented as non-static members.STATIC MEMBER FUNCTIONS¶
- o
- char const **argv(std::vector<std::string> const &words):
- o
- int casecmp(std::string const &lhs, std::string const
&rhs):
- o
- std::string escape(std::string const &str, char const
*series = "’\"\\"):
- o
- std::string lc(std::string const &str) const:
- o
- std::string trim(std::string const &str):
- o
- std::vector<std::string> split(Type *type, std::string const
&str, char const *separators = " \t", bool addEmpty =
false):
- If the parameter addEmpty is set to true, then individual separators encountered in str are stored as empty strings in words (e.g., if two elements are separated by three blank spaces, then the returned vector contains three empty strings between the two elements).
- If an element in str contains a double quote ("), then
all characters from the initial double quote through the matching double
quote character are processed as follows: the surrounding double quotes
are removed, and the remaining characters are unescaped using the
String::unescape member. The resulting unescaped string is added to
the element currently under construction. E.g., if str contains
string="\"hello world\""
then the element becomesstring="hello world"
- If an element in str contains a single quote (’),
then all characters between the initial quote and the matching quote
character are literally appended to the element currently under
construction. E.g., if str contains
string=’"hello\ world"’
then the element becomesstring="hello\ world"
- Backslash characters encountered in str outside of single or double quoted strings are unescaped (using String::unescape) and the resulting character is appended to the element currently under construction.
- E.g., if str contains
string=\"hello\ world\"
then the element becomesstring="hello world"
- o
- std::vector<SplitPair> split(std::string const &str,
char const *separators = " \t", bool addEmpty = false):
- o
- size_t split(std::vector<std::string> *words, std::string
const &str, char const *separators = " \t", bool
addEmpty = false):
- o
- size_t split(std::vector<SplitPair> *words, std::string
const &str, char const *separators = " \t", bool
addEmpty = false):
- o
- std::string unescape(std::string const &str):
- o
- std::string uc(std::string const &str):
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 interfaceSEE ALSO¶
bobcat(7)BUGS¶
None Reported.DISTRIBUTION FILES¶
- o
- bobcat_3.23.01-x.dsc: detached signature;
- o
- bobcat_3.23.01-x.tar.gz: source archive;
- o
- bobcat_3.23.01-x_i386.changes: change log;
- o
- libbobcat1_3.23.01-x_*.deb: debian package holding the libraries;
- o
- libbobcat1-dev_3.23.01-x_*.deb: debian package holding the libraries, headers and manual pages;
- o
- 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).AUTHOR¶
Frank B. Brokken ( f.b.brokken@rug.nl).2005-2014 | libbobcat-dev_3.23.01-x.tar.gz |