* something, and try to break it into
* individual lines of text at most @p
* width characters wide, by breaking at
- * spaces in the text. If this is not
- * possible, return the shortest lines than
- * are longer than @p width.
+ * positions marked by @p delimiter in the text.
+ * If this is not possible, return the shortest
+ * lines than are longer than @p width.
+ * The default value of the delimiter is a
+ * space character.
*/
std::vector<std::string>
break_text_into_lines (const std::string &original_text,
- const unsigned int width);
-
+ const unsigned int width,
+ const char delimiter = ' ');
/**
* Teturn true if the given pattern
std::vector<std::string>
break_text_into_lines (const std::string &original_text,
- const unsigned int width)
+ const unsigned int width,
+ const char delimiter)
{
std::string text = original_text;
std::vector<std::string> lines;
// remove trailing spaces
- while ((text.length() != 0) && (text[text.length()-1] == ' '))
+ while ((text.length() != 0) && (text[text.length()-1] == delimiter))
text.erase(text.length()-1,1);
// then split the text into lines
{
// in each iteration, first remove
// leading spaces
- while ((text.length() != 0) && (text[0] == ' '))
+ while ((text.length() != 0) && (text[0] == delimiter))
text.erase(0, 1);
// if we can fit everything into one
// that we can break around there
int location = std::min<int>(width,text.length()-1);
for (; location>=0; --location)
- if (text[location] == ' ')
+ if (text[location] == delimiter)
break;
// if there are no spaces, then try if
for (location = std::min<int>(width,text.length()-1);
location<static_cast<int>(text.length());
++location)
- if (text[location] == ' ')
+ if (text[location] == delimiter)
break;
// now take the text up to the found