FBB::String(3bobcat)
π FBB::String β Operations on std::string objects π
okay bestie, welcome to FBB::String(3bobcat), the manual page for the bobcat girlies who need to do cute little transformations on std::string objects. pull up a chair, grab a strawberry π, and let's get into it.
β¨ NAME β¨
FBB::String β Several operations on std::string objects π¦
β¨ SYNOPSIS β¨
#include <bobcat/string>
Linking option: -lbobcat
β¨ DESCRIPTION β¨
So like, this class is serving facilities for transformations you do all the time on std::string objects β the ones that the std::string class itself simply does not support. rude of it, but okay. and the way that every single member of FBB::String is static? iconic. π
ngl, this class originally was derived from std::string. but deriving from std::string is considerd bad design, because std::string was never designed to be a base-class. so we said no ma'am, we're not doing that. π
instead, FBB::String offers a whole series of static member functions providing the facilities that were originally implemented as non-static members. one of these members is the (overloaded) split member, which splits 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 get converted to their implied byte-values (like, \n is converted to byte value 10) β unless they're embedded in single-quoted (sub) strings. and the quotes surrounding double- and single-quoted (sub) strings? they get removed from the elements returned by the split members. bye quotes, you did your job. π
β¨ NAMESPACE β¨
FBB
all constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. periodt.
β¨ INHERITS FROM β¨
--
(it inherits from nothing, bestie. self-made queen. π)
β¨ ENUMERATIONS β¨
πΈ Type
this enumeration indicates the nature of the content of an element in the array returned by the overloaded split members (peep those below π).
DQUOTEβ a subset of the characters in the matching string element was delimited by double quotes in the string that was parsed by thesplitmembers.DQUOTE_UNTERMINATEDβ the content of the string that was parsed by thesplitmembers started at some point with a double quote, but the matching ending double quote was lacking. π not the unfinished quote...ESCAPED_ENDβ the content of the string that was parsed by thesplitmembers ended in a mere backslash. literally just a lonely little\at the end.NORMALβ a normal string;SEPARATORβ a separator;SQUOTEβ a subset of the characters in the matching string element was delimited by quotes in the string that was parsed by thesplitmembers.SQUOTE_UNTERMINATEDβ the content of the string that was parsed by thesplitmembers started at some point with a quote, but the matching ending quote was lacking. same tragedy, single-quote edition. π
π SplitType
this enumeration is used to specify how split members should split the information in the string objects that are passed to these members. choose your fighter:
TOKβ thesplitmember acts like the standard C functionstrtok(3). the essence here is that no empty elements are returned. e.g., a string containing"a,,"which is processed using theTOKmode returns aNORMALelement containing"a". the empties simply did not make the cut. πTOKSEPβ thesplitmember acts like the standard C functionstrtok(3), and also returns information about encountered separators. sincestrtokdoesn't return empty elements,TOKSEPuses empty elements to indicate the occurrence of separators. e.g., a string containing"a,,"which is processed using theTOKSEPmode returns aNORMALelement containing"a", followed by two emptySEPARATORelements.STRβ thesplitmember acts like the standard C functionstrstr(3). the essence here is that empty elements are also returned. e.g., a string containing"a,,"which is processed using theSTRmode returns an element containing"a", followed by two emptyNORMALelements.STRSEPβ thesplitmember acts like the standard C functionstrstr(3), and also returns information about encountered separators. e.g., a string containing"a,,"which is processed using theSTRSEPmode returns aNORMALelement containing"a", followed by aSEPARATORelement containing",", followed by aNORMALempty element, followed by aSEPARATORelement containing",", and finally followed by aNORMALempty element. the full roster, no crumbs left. β¨
β¨ NESTED TYPE β¨
the struct SplitPair defines a std::pair<std::string, String::Type> and is used by some overloaded split members (again, see below π).
β¨ STATIC MEMBER FUNCTIONS β¨
okay bestie, this is the good part β you don't even need an object for any of these, you just hit String:: and go π
char const **argv(std::vector<std::string> const &words)β hands you back a pointer to a freshly allocated series of pointers pointing at the C strings sitting inside thewordsvector. β οΈ listen up: you are the one responsible for giving that array of pointers back to the common pool β but do not delete the C-strings those pointers point at, they're not yours. And the last element of the returned array is guaranteed to be a 0-pointer, so you can walk it safely π«Άint casecmp(std::string const &lhs, std::string const &rhs)β compares twostd::stringcontents without caring about case (so bougie). Negative value =lhsshould be ordered beforerhs;0= they're literally identical in content; positive value =lhsshould be ordered beyondrhs. Periodt.std::string escape(std::string const &str, char const *series = "β\"\\")β gives you a copy ofstrwhere every character inseriesgets a backslash shoved in front of it. it's giving "make it safe" energy β¨std::string join(std::vector<std::string> const &words, char sep)β all the elements of thewordsvector come back as one single string, with thesepcharacter separating them from each other πΈstd::string join(std::vector<SplitPair> const &entries, char sep, bool all = true)β the first fields of the elements inentriescome back as one string, separated by thesepcharacter. Now, if you passallasfalse, then elements whose second fields are equal toString::SEPARATORget ignored. no cap.std::string lc(std::string const &str) constβ copy ofstrwith all the letters transformed into lower case letters. lowercase era πstd::vector<String::SplitPair> split(std::string const &str, SplitType mode, char const *sep = " \t")β chopsstrinto substrings, separated by any of the characters insep, and returns them in a vector ofSplitPairelements, using whateverSplitTypemodeyou asked for (go peek at theSplitPairvalues and what they do in the ENUMERATIONS section, iykyk).std::vector<String::SplitPair> split(std::string const &str, char const *separators = " \t", bool addEmpty = false)β same behavior as the previous one, except it picks the mode for you:addEmpty == falseselects modeTOK, andaddEmpty == trueselects modeTOKSEPπsize_t split(std::vector<String::SplitPair> *entries, std::string const &str, SplitType mode, char const *sep = " \t")β does the exact same thing as the firstsplitmember, but it stores theSplitPairelements in the vector thatentriespoints at, and it clears that vector first. Returns the new value ofentries->size(). iconic.size_t split(std::vector<String::SplitPair> *entries, std::string const &str, char const *sep = " \t", bool addEmpty = false)β acts like the previous one, again withaddEmpty == falsepicking modeTOKandaddEmpty == truepicking modeTOKSEPπ¦std::vector<std::string> split(Type *type, std::string const &str, SplitType stype, char const *sep = " \t")β same as the firstsplitmember, but this one only keeps the first fields of theSplitPairelements in the returned vector. And here's the juicy bit: theString::Typevariable whose address you passed totypegets set toNORMALif the final entry was successfully determined; toDQUOTE_UNTERMINATEDif a final closing double quote could not be found; toSQUOTE_UNTERMINATEDif a final closing single quote could not be found; and toESCAPE_ENDif the final character instris a backslash character. vibe check on your quotes, fr fr.std::vector<std::string> split(Type *type, std::string const &str, char const *sep = " \t", bool addEmpty = false)β acts like the previous one, with the usual deal:addEmpty == falseβ modeTOK,addEmpty == trueβ modeTOKSEPπ«size_t split(std::vector<std::string> *words, std::string const &str, SplitType stype, char const *sep = " \t")β same as the firstsplitmember, but it only stores the first fields of the encounteredSplitPairelements in the vector thatwordspoints at, and it clears that vector first. Returns the new value ofwords->size()π₯size_t split(std::vector<std::string> *words, std::string const &str, char const *sep = " \t", bool addEmpty = false)β acts like the previous one;addEmpty == falsegrabs modeTOK,addEmpty == truegrabs modeTOKSEP. yes bestie, same pattern, we love consistency πstd::string to_string(Type value, unsigned base = 10)β returnsvalueconverted to astd::stringusing number systembase. Rules, bestie:Typemust be an unsigned integral type, and2 <= base <= 36. If that last condition doesn't hold true, you get an empty string back (nothing, ghosted). Leading zeroes are ignored, and a single0comes back as a string containing a single'0'-character. Forbase > 10, subsequent letters of the alphabet stand in for the values 10, 11, 12, ..., 36. And ngl the returned string does not start with a prefix telling you which number system it is β like, there's no0xprefix when you use base 16. no notes πstd::string trim(std::string const &str)β copy ofstrwith the leading and trailing blank characters removed. fresh start energy πΈstd::string uc(std::string const &str)β copy ofstrwhere all the letters were capitalized. LOUD. screaming, even π£std::string unescape(std::string const &str)β copy ofstrwhere the escaped characters (meaning those prefixed by a backslash) got interpreted. All the standard escape characters (\a,\b,\f,\n,\r,\t,\v) are recognized. If an escape character is followed byx, at most the next two characters are interpreted as a hexadecimal number. If an escape character is followed by an octal digit, then at most 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. that's the whole rulebook πstd::string urlDecode(std::string const &str)β so URL specifications use%xxencoding to encode characters, except for alpha-numeric characters and the characters-,_,.and~, which stay as-is. Everything else gets encoded by a%character followed by two hexadecimal characters representing those characters' byte value. E.g., a blank space is encoded as%20, a plus character is encoded as%2B. This member returns astd::stringcontaining the decoded characters of the url-encoded string you passed as its argument π§std::string urlEncode(std::string const &str)β see the memberurlDecode:urlEncodereturns astd::stringcontaining the url-encoded characters of the characters in the string that's passed as argument to this member. the reverse-uno card π
π EXAMPLE π
okay here's the whole little driver, and honestly? it ate. π
#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β;
}
and this is what it spits out when you run it β the comment block is verbatim, bestie, don't @ me:
/*
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β
*/
(also can we talk about how it printed three out of thr\x65\145 β that's the escape knowledge paying off πβ¨)
π FILES π
bobcat/stringβ defines the class interface. that's the one you include, periodt. π«Ά
π SEE ALSO π
bobcat(7)β go read it, bestie, it's the vibe-setting overview.
π BUGS π
None Reported. (iconic behavior honestly, we love a clean record π)
π BOBCAT PROJECT FILES π
- https://fbb-git.gitlab.io/bobcat/ : gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
π BOBCAT π
Bobcat is an acronym of `Brokkenβs Own Base Classes And Templatesβ. the name is a whole flex, fr fr π
π COPYRIGHT π
This is free software, distributed under the terms of the GNU General Public License (GPL). free software bestie, share the love πΈ
π¦ AUTHOR π¦
Frank B. Brokken (f.b.brokken@rug.nl). the man, the myth, the maintainer π
and that's the whole page, you made it to the end π this one is libbobcat-dev_6.15.01, dated 2005-2026, and it's the FBB::String(3bobcat) page β go split some strings, you've got this π
β¨
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms