aboutsummaryrefslogtreecommitdiff
path: root/libbutl/utility.mxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-04-28 16:34:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-04-28 16:34:57 +0200
commiteba3042910f063ae638a7e0134b79175978e2fca (patch)
treec17863f5f87f578cdb80736154e22a4f1d187205 /libbutl/utility.mxx
parentb32579bad74e1b7f3a719fa49aad8566d20a6d2b (diff)
Move trim(), next_word() basic string utilities from build2
Diffstat (limited to 'libbutl/utility.mxx')
-rw-r--r--libbutl/utility.mxx64
1 files changed, 49 insertions, 15 deletions
diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx
index 4c83827..b957282 100644
--- a/libbutl/utility.mxx
+++ b/libbutl/utility.mxx
@@ -57,21 +57,6 @@ LIBBUTL_MODEXPORT namespace butl
[[noreturn]] LIBBUTL_SYMEXPORT void
throw_system_error (int system_code, int fallback_errno_code = 0);
- // If an input stream is in a failed state, then return true if this is
- // because of the eof and throw istream::failure otherwise. If the stream
- // is not in a failed state, return false. This helper function is normally
- // used like this:
- //
- // is.exceptions (istream::badbit);
- //
- // for (string l; !eof (getline (is, l)); )
- // {
- // ...
- // }
- //
- bool
- eof (std::istream&);
-
// Convert ASCII character/string case. If there is no upper/lower case
// counterpart, leave the character unchanged. The POSIX locale (also known
// as C locale) must be the current application locale. Otherwise the
@@ -149,6 +134,55 @@ LIBBUTL_MODEXPORT namespace butl
bool alnum (wchar_t);
bool xdigit (wchar_t);
+ // Basic string utilities.
+ //
+
+ // Trim leading/trailing whitespacec, including '\r'.
+ //
+ std::string&
+ trim (std::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.
+ //
+ std::size_t
+ next_word (const std::string&, std::size_t& b, std::size_t& e,
+ char d1 = ' ', char d2 = '\0');
+
+ std::size_t
+ next_word (const std::string&, std::size_t n, std::size_t& b, std::size_t& e,
+ char d1 = ' ', char d2 = '\0');
+
+ // If an input stream is in a failed state, then return true if this is
+ // because of the eof and throw istream::failure otherwise. If the stream
+ // is not in a failed state, return false. This helper function is normally
+ // used like this:
+ //
+ // is.exceptions (istream::badbit);
+ //
+ // for (string l; !eof (getline (is, l)); )
+ // {
+ // ...
+ // }
+ //
+ bool
+ eof (std::istream&);
+
// Key comparators (i.e., to be used in sets, maps, etc).
//
struct compare_c_string