aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbutl/utility.cxx15
-rw-r--r--libbutl/utility.mxx2
2 files changed, 9 insertions, 8 deletions
diff --git a/libbutl/utility.cxx b/libbutl/utility.cxx
index 502586c..1212aa1 100644
--- a/libbutl/utility.cxx
+++ b/libbutl/utility.cxx
@@ -104,17 +104,18 @@ namespace butl
assert (trim (r = "a \r") == "a");
assert (trim (r = " a ") == "a");
assert (trim (r = " \ta \r") == "a");
+ assert (trim (r = "\na\n") == "a");
*/
- size_t i (0), n (l.size ());
+ auto ws = [] (char c )
+ {
+ return c == ' ' || c == '\t' || c == '\n' || c == '\r';
+ };
- for (char c;
- i != n && ((c = l[i]) == ' ' || c == '\t' || c == '\r');
- ++i) ;
+ size_t i (0), n (l.size ());
- for (char c;
- n != i && ((c = l[n - 1]) == ' ' || c == '\t' || c == '\r');
- --n) ;
+ for (; i != n && ws (l[i]); ++i) ;
+ for (; n != i && ws (l[n - 1]); --n) ;
if (i != 0)
{
diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx
index 252a4b4..ee2aed7 100644
--- a/libbutl/utility.mxx
+++ b/libbutl/utility.mxx
@@ -140,7 +140,7 @@ LIBBUTL_MODEXPORT namespace butl
// Basic string utilities.
//
- // Trim leading/trailing whitespacec, including '\r'.
+ // Trim leading/trailing whitespaces, including '\n' and '\r'.
//
LIBBUTL_SYMEXPORT std::string&
trim (std::string&);