aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-04-28 16:34:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-04-28 16:34:18 +0200
commit9c8844e80d493eceaa706c1e4cdf983f7e32c59d (patch)
treec2a618d34f1558785a102eea056bea2c8be3c7a5
parent6f0f62a865a0bc04233388a049a2273e630bb840 (diff)
Move trim(), next_word() to libbutl
-rw-r--r--build2/utility.cxx37
-rw-r--r--build2/utility.hxx37
-rw-r--r--build2/utility.ixx29
3 files changed, 3 insertions, 100 deletions
diff --git a/build2/utility.cxx b/build2/utility.cxx
index f1def09..2f46124 100644
--- a/build2/utility.cxx
+++ b/build2/utility.cxx
@@ -71,43 +71,6 @@ namespace build2
// <build2/utility.hxx>
//
- string&
- trim (string& l)
- {
- /*
- assert (trim (r = "") == "");
- assert (trim (r = " ") == "");
- assert (trim (r = " \t\r") == "");
- assert (trim (r = "a") == "a");
- assert (trim (r = " a") == "a");
- assert (trim (r = "a ") == "a");
- assert (trim (r = " \ta") == "a");
- assert (trim (r = "a \r") == "a");
- assert (trim (r = " a ") == "a");
- assert (trim (r = " \ta \r") == "a");
- */
-
- size_t i (0), n (l.size ());
-
- for (char c;
- i != n && ((c = l[i]) == ' ' || c == '\t' || c == '\r');
- ++i) ;
-
- for (char c;
- n != i && ((c = l[n - 1]) == ' ' || c == '\t' || c == '\r');
- --n) ;
-
- if (i != 0)
- {
- string s (l, i, n - i);
- l.swap (s);
- }
- else if (n != l.size ())
- l.resize (n);
-
- return l;
- }
-
options ops;
process_path argv0;
bool stderr_term;
diff --git a/build2/utility.hxx b/build2/utility.hxx
index d5809bc..bae2eb8 100644
--- a/build2/utility.hxx
+++ b/build2/utility.hxx
@@ -68,6 +68,9 @@ namespace build2
using butl::alnum;
using butl::digit;
+ using butl::trim;
+ using butl::next_word;
+
using butl::exception_guard;
using butl::make_exception_guard;
@@ -76,40 +79,6 @@ namespace build2
using butl::eof;
- // Basic string utilities.
- //
-
- // Trim leading/trailing whitespacec, including '\r'.
- //
- string&
- trim (string&);
-
- // Find the beginning and end poistions of the next word. Return the size
- // of the word or 0 and set b = e = n if there are no more words. For
- // example:
- //
- // for (size_t b (0), e (0); next_word (s, b, e); )
- // {
- // string w (s, b, e - b);
- // }
- //
- // Or:
- //
- // for (size_t b (0), e (0), n; n = next_word (s, b, e, ' ', ','); )
- // {
- // string w (s, b, n);
- // }
- //
- // The second version examines up to the n'th character in the string.
- //
- size_t
- next_word (const string&, size_t& b, size_t& e,
- char d1 = ' ', char d2 = '\0');
-
- size_t
- next_word (const string&, size_t n, size_t& b, size_t& e,
- char d1 = ' ', char d2 = '\0');
-
extern bool stderr_term; // True if stderr is a terminal.
// Command line options.
diff --git a/build2/utility.ixx b/build2/utility.ixx
index d0fe80c..3595ce4 100644
--- a/build2/utility.ixx
+++ b/build2/utility.ixx
@@ -4,35 +4,6 @@
namespace build2
{
- inline size_t
- next_word (const string& s, size_t& b, size_t& e, char d1, char d2)
- {
- return next_word (s, s.size (), b, e, d1, d2);
- }
-
- inline size_t
- next_word (const string& s, size_t n, size_t& b, size_t& e, char d1, char d2)
- {
- if (b != e)
- b = e;
-
- // Skip leading delimiters.
- //
- for (; b != n && (s[b] == d1 || s[b] == d2); ++b) ;
-
- if (b == n)
- {
- e = n;
- return 0;
- }
-
- // Find first trailing delimiter.
- //
- for (e = b + 1; e != n && s[e] != d1 && s[e] != d2; ++e) ;
-
- return e - b;
- }
-
inline void
hash_path (sha256& cs, const path& p, const dir_path& prefix)
{