diff options
Diffstat (limited to 'libbutl/utility.cxx')
-rw-r--r-- | libbutl/utility.cxx | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/libbutl/utility.cxx b/libbutl/utility.cxx index a891fc2..b03a8f8 100644 --- a/libbutl/utility.cxx +++ b/libbutl/utility.cxx @@ -1,9 +1,7 @@ // file : libbutl/utility.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#ifndef __cpp_modules_ts -#include <libbutl/utility.mxx> -#endif +#include <libbutl/utility.hxx> #ifdef _WIN32 #include <libbutl/win32-utility.hxx> @@ -11,35 +9,15 @@ #include <stdlib.h> // getenv(), setenv(), unsetenv(), _putenv() -#ifndef __cpp_lib_modules_ts -#include <string> -#include <cstddef> -#include <utility> - #include <cstring> // strncmp(), strlen() #include <ostream> #include <type_traits> // enable_if, is_base_of #include <system_error> -#endif #include <libbutl/ft/lang.hxx> #include <libbutl/ft/exception.hxx> -#ifdef __cpp_modules_ts -module butl.utility; - -// Only imports additional to interface. -#ifdef __clang__ -#ifdef __cpp_lib_modules_ts -import std.core; -import std.io; -#endif -#endif - -import butl.utf8; -#else -#include <libbutl/utf8.mxx> -#endif +#include <libbutl/utf8.hxx> namespace butl { @@ -193,13 +171,42 @@ namespace butl for (; i != n && ws (l[i]); ++i) ; for (; n != i && ws (l[n - 1]); --n) ; - if (i != 0) + if (n != l.size ()) l.resize (n); + if (i != 0) l.erase (0, i); + + return l; + } + + string& + trim_left (string& l) + { + auto ws = [] (char c ) { - string s (l, i, n - i); - l.swap (s); - } - else if (n != l.size ()) - l.resize (n); + return c == ' ' || c == '\t' || c == '\n' || c == '\r'; + }; + + size_t i (0), n (l.size ()); + + for (; i != n && ws (l[i]); ++i) ; + + if (i != 0) l.erase (0, i); + + return l; + } + + string& + trim_right (string& l) + { + auto ws = [] (char c ) + { + return c == ' ' || c == '\t' || c == '\n' || c == '\r'; + }; + + size_t i (0), n (l.size ()); + + for (; n != i && ws (l[n - 1]); --n) ; + + if (n != l.size ()) l.resize (n); return l; } |