From: heister Date: Tue, 17 Jan 2012 22:30:56 +0000 (+0000) Subject: Utilities::break_text_into_lines now also splits the string at \n X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0747abdb8172a7f38a151f52f2673c13e49d9d43;p=dealii-svn.git Utilities::break_text_into_lines now also splits the string at \n git-svn-id: https://svn.dealii.org/trunk@24907 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 20feb50d7c..f7d8e7af3d 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -74,6 +74,10 @@ enabled due to a missing include file in file
    +
  1. Improved: Utilities::break_text_into_lines now also splits the string at \n. +
    +(Timo Heister, 2012/01/17) +
  2. Fixed: make_dependencies now behaves like the c++ compiler when searching include paths for #include "..." directives.
    diff --git a/deal.II/include/deal.II/base/utilities.h b/deal.II/include/deal.II/base/utilities.h index b20da3a0c9..dd35fde65a 100644 --- a/deal.II/include/deal.II/base/utilities.h +++ b/deal.II/include/deal.II/base/utilities.h @@ -126,11 +126,14 @@ namespace Utilities * something, and try to break it into * individual lines of text at most @p * width characters wide, by breaking at - * positions marked by @p delimiter in the text. - * If this is not possible, return the shortest - * lines that are longer than @p width. - * The default value of the delimiter is a - * space character. + * positions marked by @p delimiter in the + * text. If this is not possible, return + * the shortest lines that are longer than + * @p width. The default value of the + * delimiter is a space character. If + * original_text contains newline + * characters (\n), the string is split at + * these locations, too. */ std::vector break_text_into_lines (const std::string &original_text, diff --git a/deal.II/source/base/utilities.cc b/deal.II/source/base/utilities.cc index 91d389e882..eec4ec59cc 100644 --- a/deal.II/source/base/utilities.cc +++ b/deal.II/source/base/utilities.cc @@ -262,11 +262,25 @@ namespace Utilities while ((text.length() != 0) && (text[0] == delimiter)) text.erase(0, 1); + std::size_t pos_newline = text.find_first_of("\n", 0); + if (pos_newline != std::string::npos && pos_newline <= width) + { + std::string line (text, 0, pos_newline); + while ((line.length() != 0) && (line[line.length()-1] == delimiter)) + line.erase(line.length()-1,1); + lines.push_back (line); + text.erase (0, pos_newline+1); + continue; + } + // if we can fit everything into one // line, then do so. otherwise, we have // to keep breaking if (text.length() < width) { + // remove trailing spaces + while ((text.length() != 0) && (text[text.length()-1] == delimiter)) + text.erase(text.length()-1,1); lines.push_back (text); text = ""; } @@ -292,7 +306,10 @@ namespace Utilities // now take the text up to the found // location and put it into a single // line, and remove it from 'text' - lines.push_back (std::string (text, 0, location)); + std::string line (text, 0, location); + while ((line.length() != 0) && (line[line.length()-1] == delimiter)) + line.erase(line.length()-1,1); + lines.push_back (line); text.erase (0, location); } }