]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Utilities::break_text_into_lines now also splits the string at \n
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 17 Jan 2012 22:30:56 +0000 (22:30 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 17 Jan 2012 22:30:56 +0000 (22:30 +0000)
git-svn-id: https://svn.dealii.org/trunk@24907 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/utilities.h
deal.II/source/base/utilities.cc

index 20feb50d7c48b1e83b3839439cd0fd987efcfbff..f7d8e7af3da9f0d9db1bee0c492d18a47afcb133 100644 (file)
@@ -74,6 +74,10 @@ enabled due to a missing include file in file
 
 <ol>
 
+<li> Improved: Utilities::break_text_into_lines now also splits the string at \n.
+<br>
+(Timo Heister, 2012/01/17)
+
 <li> Fixed: make_dependencies now behaves like the c++ compiler when
 searching include paths for #include "..." directives.
 <br>
index b20da3a0c9efeb0c59605be666f739f604943110..dd35fde65af7027d8c485acb4657a7dfe2fc28ec 100644 (file)
@@ -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<std::string>
   break_text_into_lines (const std::string &original_text,
index 91d389e8823a210d060a2f21f7c45a6fa8b4b221..eec4ec59ccb6fba7fc8d0aa789973dd2a55a34d2 100644 (file)
@@ -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);
           }
       }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.