-
-
-static docstring const formatted(docstring const & text)
-{
- const int w = 80;
- docstring sout;
-
- if (text.empty())
- return sout;
-
- size_t curpos = 0;
- docstring line;
-
- while (true) {
- size_t const nxtpos1 = text.find(' ', curpos);
- size_t const nxtpos2 = text.find('\n', curpos);
- size_t const nxtpos = min(nxtpos1, nxtpos2);
-
- docstring const word =
- nxtpos == docstring::npos ?
- text.substr(curpos) :
- text.substr(curpos, nxtpos - curpos);
-
- bool const newline = (nxtpos2 != docstring::npos &&
- nxtpos2 < nxtpos1);
-
- docstring const line_plus_word =
- line.empty() ? word : line + char_type(' ') + word;
-
- // FIXME: make w be size_t
- if (int(line_plus_word.length()) >= w) {
- sout += line + char_type('\n');
- if (newline) {
- sout += word + char_type('\n');
- line.erase();
- } else {
- line = word;
- }
-
- } else if (newline) {
- sout += line_plus_word + char_type('\n');
- line.erase();
-
- } else {
- if (!line.empty())
- line += char_type(' ');
- line += word;
- }
-
- if (nxtpos == docstring::npos) {
- if (!line.empty())
- sout += line;
- break;
- }
-
- curpos = nxtpos + 1;
- }
-
- return sout;
-}
-
-