diff options
-rw-r--r-- | libbutl/utility.hxx | 26 | ||||
-rw-r--r-- | libbutl/utility.ixx | 36 | ||||
-rw-r--r-- | tests/strcase/driver.cxx | 4 |
3 files changed, 44 insertions, 22 deletions
diff --git a/libbutl/utility.hxx b/libbutl/utility.hxx index 9eb052d..cdf7cf2 100644 --- a/libbutl/utility.hxx +++ b/libbutl/utility.hxx @@ -75,20 +75,26 @@ namespace butl std::string ucase (const std::string&, std::size_t p = 0, std::size_t n = std::string::npos); - std::string& ucase (std::string&, - std::size_t p = 0, - std::size_t n = std::string::npos); - void ucase (char*, std::size_t); + std::string ucase (std::string&&, + std::size_t p = 0, + std::size_t n = std::string::npos); + std::string& make_ucase (std::string&, + std::size_t p = 0, + std::size_t n = std::string::npos); + void make_ucase (char*, std::size_t); char lcase (char); std::string lcase (const char*, std::size_t n = std::string::npos); std::string lcase (const std::string&, std::size_t p = 0, std::size_t n = std::string::npos); - std::string& lcase (std::string&, - std::size_t p = 0, - std::size_t n = std::string::npos); - void lcase (char*, std::size_t); + std::string lcase (std::string&&, + std::size_t p = 0, + std::size_t n = std::string::npos); + std::string& make_lcase (std::string&, + std::size_t p = 0, + std::size_t n = std::string::npos); + void make_lcase (char*, std::size_t); // Compare ASCII characters/strings ignoring case. Behave as if characters // had been converted to the lower case and then byte-compared. Return a @@ -226,9 +232,9 @@ namespace butl // // Note that it doesn't make sure the first character is not a digit. // - std::string& sanitize_identifier (std::string&); - std::string sanitize_identifier (std::string&&); std::string sanitize_identifier (const std::string&); + std::string sanitize_identifier (std::string&&); + std::string& make_sanitized_identifier (std::string&); // Sanitize a string (e.g., a path) to be a valid C string literal by // escaping backslahes, double-quotes, and newlines. diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx index fda1ce5..f525ce4 100644 --- a/libbutl/utility.ixx +++ b/libbutl/utility.ixx @@ -14,15 +14,22 @@ namespace butl return std::toupper (c); } + inline std::string + ucase (std::string&& s, std::size_t p, std::size_t n) + { + make_ucase (s, p, n); + return std::move (s); + } + inline void - ucase (char* s, std::size_t n) + make_ucase (char* s, std::size_t n) { for (const char* e (s + n); s != e; ++s) *s = ucase (*s); } inline std::string& - ucase (std::string& s, std::size_t p, std::size_t n) + make_ucase (std::string& s, std::size_t p, std::size_t n) { if (n == std::string::npos) n = s.size () - p; @@ -30,7 +37,7 @@ namespace butl if (n != 0) { s.front () = s.front (); // Force copy in CoW. - ucase (const_cast<char*> (s.data ()) + p, n); + make_ucase (const_cast<char*> (s.data ()) + p, n); } return s; } @@ -39,7 +46,8 @@ namespace butl ucase (const char* s, std::size_t n) { std::string r (s, n == std::string::npos ? std::strlen (s) : n); - return ucase (r); + make_ucase (r); + return r; } inline std::string @@ -54,15 +62,22 @@ namespace butl return std::tolower (c); } + inline std::string + lcase (std::string&& s, std::size_t p, std::size_t n) + { + make_lcase (s, p, n); + return std::move (s); + } + inline void - lcase (char* s, std::size_t n) + make_lcase (char* s, std::size_t n) { for (const char* e (s + n); s != e; ++s) *s = lcase (*s); } inline std::string& - lcase (std::string& s, std::size_t p, std::size_t n) + make_lcase (std::string& s, std::size_t p, std::size_t n) { if (n == std::string::npos) n = s.size () - p; @@ -70,7 +85,7 @@ namespace butl if (n != 0) { s.front () = s.front (); // Force copy in CoW. - lcase (const_cast<char*> (s.data ()) + p, n); + make_lcase (const_cast<char*> (s.data ()) + p, n); } return s; } @@ -79,7 +94,8 @@ namespace butl lcase (const char* s, std::size_t n) { std::string r (s, n == std::string::npos ? std::strlen (s) : n); - return lcase (r); + make_lcase (r); + return r; } inline std::string @@ -271,7 +287,7 @@ namespace butl } inline std::string& - sanitize_identifier (std::string& s) + make_sanitized_identifier (std::string& s) { std::for_each (s.begin (), s.end (), [] (char& c) { @@ -284,7 +300,7 @@ namespace butl inline std::string sanitize_identifier (std::string&& s) { - sanitize_identifier (s); + make_sanitized_identifier (s); return std::move (s); } diff --git a/tests/strcase/driver.cxx b/tests/strcase/driver.cxx index 8e964a6..2d1ca6f 100644 --- a/tests/strcase/driver.cxx +++ b/tests/strcase/driver.cxx @@ -61,9 +61,9 @@ main () assert (lcase ("") == string ()); string s (upper); - assert (lcase (s) == lower); + assert (make_lcase (s) == lower); s = lower; - ucase (const_cast<char*> (s.data ()), s.size ()); + make_ucase (const_cast<char*> (s.data ()), s.size ()); assert (s == upper); } |