aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2024-12-06 09:13:17 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2024-12-06 11:20:01 +0200
commit44fba3192ad2401f33cccbe5d8ac88e3cf86b6f9 (patch)
tree0dbb7968280a875908daa925e68084830b3afdbc
parent794805e4c30e30f26286ac0c2d6a513d2391d38e (diff)
Rename some ucase(), lcase(), and sanitize_identifier() overloads to their make_*() variantsHEADmaster
-rw-r--r--libbutl/utility.hxx26
-rw-r--r--libbutl/utility.ixx36
-rw-r--r--tests/strcase/driver.cxx4
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);
}