FBB::OFoldBuf(3bobcat)
β¨ NAME β¨
okay bestie, welcome to the <pink>FBB::OFoldBuf</pink> page β that's <pink>FBB::OFoldBuf(3bobcat)</pink> if we're being formal, section 3 of the bobcat manual. and what does it do? it folds long lines written to ostream. that's it, that's the whole job, and it does it beautifully. π
π SYNOPSIS π
#include <bobcat/ofoldbuf>
Linking option: -lbobcat
like literally just include it and link it, no drama. π«Ά
π DESCRIPTION π
so, <hotpink>FBB::OFoldBuf</hotpink> is a specialization of FBB::OFilterBuf that folds long lines written to an std::ostream object. and then the folded lines get written to a second ostream β that's the destination stream, and it's either used by or opened by the OFoldBuf object. two streams, one iconic little buddy in the middle. β¨
internally, OFoldBuf runs its whole situation off a little finite state automaton β fr, a tiny FSA. it knows three states (INDENT, WS and NON_WS) and three character categories (\n, other white space characters (space), and non-space characters). nine combinations, and we're gonna go through every single one below because that's the whole point of this page. π§
OFoldBuf objects will never fold lines in the middle of a series of non-blank characters (that's called a word from here on) β it will always break a line at a white space character. the resulting lines always show up to the right of a configurable left margin and to the left of a configurable right margin. π
there is a somewhat pathological exception to this: if a word is too long to fit in between the margins, then the word will exceed the right hand margin. it just does. no cap. the FSA said what it said. π
the indentation used for the left margins is configurable to either blanks (that's the default, queen) or tabs. and when tabs are used, the width of a tab character is configurable too, using a default of 8 positions in the destination stream.
so here's the rundown of the Finite State Automaton (FSA) defining what happens when various character types show up in its three states. whenever you read ... is written, that means the described information is written to the ostream used or opened by the OFoldBuf object. OFoldBuf's initial state is INDENT.
π State: INDENT
\nβ a new line character is written.- space β the indentation is set; the space character is added to the indentation; next state:
WS. - non-ws β the character is added to the currently stored word; next state:
NON_WS.
π State: WS
\nβ a new line character is written; stored white-space is erased; next state:INDENT.- space β white space character is added to the currently stored space characters.
- non-ws β the character is added to the currently stored word; next state:
NON_WS.
π State: NON_WS
\nβ stored white space and word are written; a new line is written; next state:INDENT.- space β stored white space and word are written; white space character is added to the currently stored space characters; next state:
WS. - non-ws β the character is added to the currently stored word.
π NAMESPACE π
FBB
all constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. periodt. π
π¦ INHERITS FROM π¦
FBB::OFilterBuf
π ENUMERATION π
the enumeration TabsOrBlanks is used to select tabs or blanks when writing the indentation. the default is blanks. when tabs are selected, the display width of tabs characters can be configured as well β using the default of 8 positions for each tab-character. this enumeration has two values:
BLANKSβ the default, indicating that the left margin is specified and written as a number of blanks;TABSβ indicating that the left margin is specified and written as a number of tab-characters.
the enumeration TrailingBlanks is used to configure the OFoldBuf object with respect to any trailing blanks that may appear on the final line. ngl these trailing blanks can appear on the final line if it is not properly terminated with a newline character but instead ends in white space. by default these white space characters are ignored, but they may be kept as well. this enumeration also has two values:
IGNORE_TRAILING_BLANKSβ this indicates that trailing blanks appearing at the final line if it is not terminated by a newline should not be written to the destinationstd::ostream. this is the default used byOFoldBufobjects.KEEP_TRAILING_BLANKSβ this indicates that trailing blanks at the final line if it is not terminated by a newline should be written to the destinationstd::ostream.
πΈ CONSTRUCTORS πΈ
OFoldBuf(size_t leftIndent = 0, size_t rightMargin = 80, TabsOrBlanks tob = BLANKS, TrailingBlanks tb = IGNORE_TRAILING_BLANKS)β this constructor initializes anOFoldBufobject but does not associate it with a destination stream. it can also be used as the default constructor. πOFoldBuf(char const *fname, size_t leftIndent = 0, size_t rightMargin = 80, TabsOrBlanks tob = BLANKS, TrailingBlanks tb = IGNORE_TRAILING_BLANKS)β this constructor initializes anOFoldBufobject and opens (usingstd::ios::out) the destination stream using the name specified as itsfnameargument. β¨OFoldBuf(std::ostream &stream, size_t leftIndent = 0, size_t rightMargin = 80, TabsOrBlanks tob = BLANKS, TrailingBlanks tb = IGNORE_TRAILING_BLANKS)β this constructor initializes anOFoldBufobject and uses as its destination stream thestd::ostreamstream. π«Ά
the destructor writes any buffered information to the destination stream and will then flush the destination stream. it leaves absolutely nothing behind, that's main character energy. π
copy and move constructors (and assignment operators) are not available. not up for discussion, bestie. π
π MEMBER FUNCTIONS π
all members of FBB::OFilterBuf, in particular its out() and reset members, are available, as FBB::OFoldBuf inherits from this class. iykyk. π§
void setMargins(size_t leftMargin, size_t rightMargin)β this member can be used to modify the left- and right folding margins. note that the left margin may also be modified using theFBB::lmandFBB::mlmmanipulators. β¨void setTrailingBlanks(TrailingBlanks tb)β this member can be used to modify the currently usedTrailingBlanksparameter.void useBlanks()β this member can be used to select blanks to be used when inserting left margins.void useTabs(size_t tabWidth = 8)β this member can be used to select tab-characters to be used when inserting left margins. the second parameter is used to specify the display width of a tab-character.
β STATIC MEMBER FUNCTIONS β
size_t leftMargin(std::ostreambuf const *buffer)β this member returns the current left margin setting of theOFoldBufobject passed to it as its argument. the member defines astd::streambufparameter which is down cast to anOFoldBuf, and anFBB::Exceptionexception is thrown if that cast fails. πsize_t rightMargin(std::ostreambuf const *buffer)β this member returns the current right margin setting of theOFoldBufobject passed to it as its argument. the member's parameter is down cast in the same way asleftMargin()'s argument: anFBB::Exceptionexception is thrown if that cast fails.
π EXAMPLE π
look at this gorgeous little program, she ate and left no crumbs:
#include <iostream>
#include <ostream>
#include <string>
#include <bobcat/ofoldbuf>
using namespace std;
using namespace FBB;
int main()
{
OFoldBuf fb(cout, 4, 40);
ostream out(&fb);
out << lm(4);
string line;
while (getline(cin, line))
out << line << β\nβ;
}
π FILES π
bobcat/ofoldbufβ defines the class interface
π SEE ALSO π
bobcat(7), lm(3bobcat), mlm(3bobcat), ofilterbuf(3bobcat), ofoldstream(3bobcat)
π BUGS π
None Reported.
(not a single one. she's perfect. πβ¨)
π₯ 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. π
π 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).
okay that's the whole page, bestie, you're officially an OFoldBuf expert. this little icon came to you from libbobcat-dev_6.15.01, dated 2005-2026, and it's filed under FBB::OFoldBuf(3bobcat). go fold some lines, slay, drink water, periodt. π«ΆππΈ
π¦ 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