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 the split members.
  • DQUOTE_UNTERMINATED β€” the content 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. 😭 not the unfinished quote...
  • ESCAPED_END β€” the content of the string that was parsed by the split members 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 the split members.
  • SQUOTE_UNTERMINATED β€” the content of the string that was parsed by the split members 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 β€” the split member acts like the standard C function strtok(3). the essence here is that no empty elements are returned. e.g., a string containing "a,," which is processed using the TOK mode returns a NORMAL element containing "a". the empties simply did not make the cut. πŸ’€
  • TOKSEP β€” the split member acts like the standard C function strtok(3), and also returns information about encountered separators. since strtok doesn't return empty elements, TOKSEP uses empty elements to indicate the occurrence of separators. e.g., a string containing "a,," which is processed using the TOKSEP mode returns a NORMAL element containing "a", followed by two empty SEPARATOR elements.
  • STR β€” the split member acts like the standard C function strstr(3). the essence here is that empty elements are also returned. e.g., a string containing "a,," which is processed using the STR mode returns an element containing "a", followed by two empty NORMAL elements.
  • STRSEP β€” the split member acts like the standard C function strstr(3), and also returns information about encountered separators. e.g., a string containing "a,," which is processed using the STRSEP mode returns a NORMAL element containing "a", followed by a SEPARATOR element containing ",", followed by a NORMAL empty element, followed by a SEPARATOR element containing ",", and finally followed by a NORMAL empty 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 the words vector. ⚠️ 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 two std::string contents without caring about case (so bougie). Negative value = lhs should be ordered before rhs; 0 = they're literally identical in content; positive value = lhs should be ordered beyond rhs. Periodt.
  • std::string escape(std::string const &str, char const *series = "’\"\\") β€” gives you a copy of str where every character in series gets 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 the words vector come back as one single string, with the sep character separating them from each other 🌸
  • std::string join(std::vector<SplitPair> const &entries, char sep, bool all = true) β€” the first fields of the elements in entries come back as one string, separated by the sep character. Now, if you pass all as false, then elements whose second fields are equal to String::SEPARATOR get ignored. no cap.
  • std::string lc(std::string const &str) const β€” copy of str with 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") β€” chops str into substrings, separated by any of the characters in sep, and returns them in a vector of SplitPair elements, using whatever SplitType mode you asked for (go peek at the SplitPair values 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 == false selects mode TOK, and addEmpty == true selects mode TOKSEP πŸŽ€
  • 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 first split member, but it stores the SplitPair elements in the vector that entries points at, and it clears that vector first. Returns the new value of entries->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 with addEmpty == false picking mode TOK and addEmpty == true picking mode TOKSEP πŸ¦‹
  • std::vector<std::string> split(Type *type, std::string const &str, SplitType stype, char const *sep = " \t") β€” same as the first split member, but this one only keeps the first fields of the SplitPair elements in the returned vector. And here's the juicy bit: the String::Type variable whose address you passed to type gets set to NORMAL if the final entry was successfully determined; to DQUOTE_UNTERMINATED if a final closing double quote could not be found; to SQUOTE_UNTERMINATED if a final closing single quote could not be found; and to ESCAPE_END if the final character in str is 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 β†’ mode TOK, addEmpty == true β†’ mode TOKSEP πŸ’«
  • size_t split(std::vector<std::string> *words, std::string const &str, SplitType stype, char const *sep = " \t") β€” same as the first split member, but it only stores the first fields of the encountered SplitPair elements in the vector that words points at, and it clears that vector first. Returns the new value of words->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 == false grabs mode TOK, addEmpty == true grabs mode TOKSEP. yes bestie, same pattern, we love consistency 🌈
  • std::string to_string(Type value, unsigned base = 10) β€” returns value converted to a std::string using number system base. Rules, bestie: Type must be an unsigned integral type, and 2 <= base <= 36. If that last condition doesn't hold true, you get an empty string back (nothing, ghosted). Leading zeroes are ignored, and a single 0 comes back as a string containing a single '0'-character. For base > 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 no 0x prefix when you use base 16. no notes πŸ‘‘
  • std::string trim(std::string const &str) β€” copy of str with the leading and trailing blank characters removed. fresh start energy 🌸
  • std::string uc(std::string const &str) β€” copy of str where all the letters were capitalized. LOUD. screaming, even πŸ“£
  • std::string unescape(std::string const &str) β€” copy of str where 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 by x, 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 %xx encoding 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 a std::string containing the decoded characters of the url-encoded string you passed as its argument 🧚
  • std::string urlEncode(std::string const &str) β€” see the member urlDecode: urlEncode returns a std::string containing 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 πŸŽ€

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 πŸ’œ


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