diff options
Diffstat (limited to 'libbutl/utility.hxx')
-rw-r--r-- | libbutl/utility.hxx | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/libbutl/utility.hxx b/libbutl/utility.hxx index 95a7f78..779a0aa 100644 --- a/libbutl/utility.hxx +++ b/libbutl/utility.hxx @@ -132,11 +132,13 @@ namespace butl bool digit (char); bool alnum (char); bool xdigit (char); + bool wspace (char); bool alpha (wchar_t); bool digit (wchar_t); bool alnum (wchar_t); bool xdigit (wchar_t); + bool wspace (wchar_t); // Basic string utilities. // @@ -170,7 +172,7 @@ namespace butl return move (trim_right (s)); } - // Find the beginning and end poistions of the next word. Return the size + // Find the beginning and end positions 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: // @@ -188,6 +190,24 @@ namespace butl // // The second version examines up to the n'th character in the string. // + // The third version, instead of skipping consecutive delimiters, treats + // them as separating empty words. The additional m variable contains an + // unspecified internal state and should be initialized to 0. Note that in + // this case you should use the (b == n) condition to detect the end. Note + // also that a leading delimiter is considered as separating an empty word + // from the rest and the trailing delimiter is considered as separating the + // rest from an empty word. For example, this is how to parse lines while + // observing blanks: + // + // for (size_t b (0), e (0), m (0), n (s.size ()); + // next_word (s, n, b, e, m, '\n', '\r'), b != n; ) + // { + // string l (s, b, e - b); + // } + // + // For string "\na\n" this code will observe the {"", "a", ""} words. And + // for just "\n" it will observe the {"", ""} words. + // std::size_t next_word (const std::string&, std::size_t& b, std::size_t& e, char d1 = ' ', char d2 = '\0'); @@ -196,6 +216,11 @@ namespace butl next_word (const std::string&, std::size_t n, 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, std::size_t& m, + char d1 = ' ', char d2 = '\0'); + // Sanitize a string to only contain characters valid in an identifier // (ASCII alphanumeric plus `_`) replacing all others with `_`. // @@ -312,8 +337,8 @@ namespace butl // Move-to-empty-only type. // - auto_thread_env (auto_thread_env&&); - auto_thread_env& operator= (auto_thread_env&&); + auto_thread_env (auto_thread_env&&) noexcept; + auto_thread_env& operator= (auto_thread_env&&) noexcept; auto_thread_env (const auto_thread_env&) = delete; auto_thread_env& operator= (const auto_thread_env&) = delete; |