/usr/include/wibble/text/wordwrap.h is in libwibble-dev 1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #include <string>
using namespace std;
namespace wibble {
namespace text {
/**
* Simple string wrapper.
*
* wibble::text::Wrap takes a string and splits it in lines of the give length
* with proper word wrapping.
*
* Example:
* \code
* WordWrap ww("The quick brown fox jumps over the lazy dog");
* ww.get(5); // Returns "The"
* ww.get(14); // Returns "quick brown"
* ww.get(3); // Returns "fox"
* // A line always gets some text, to avoid looping indefinitely in case of
* // words that are too long. Words that are too long are split crudely.
* ww.get(2); // Returns "ju"
* ww.get(90); // Returns "mps over the lazy dog"
* \endcode
*/
class WordWrap
{
std::string s;
size_t cursor;
public:
/**
* Creates a new word wrapper that takes data from the given string
*/
WordWrap(const std::string& s) : s(s), cursor(0) {}
/**
* Rewind the word wrapper, restarting the output from the beginning of the
* string
*/
void restart() { cursor = 0; }
/**
* Returns true if there is still data to be read in the string
*/
bool hasData() const { return cursor < s.size(); }
/**
* Get a line of text from the string, wrapped to a maximum of \c width
* characters
*/
std::string get(unsigned int width);
};
}
}
// vim:set ts=4 sw=4:
|