aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-10-01 11:51:38 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-10-01 11:51:38 +0200
commit177d187a8e1eb01d18f4541726467bf6eef114fd (patch)
treeca807d5961b1cf2408d7691145fae5d46e85f8b5
parentfbfd4eed353baf6577f7a09b8a7c15e89d33bda7 (diff)
Add position and size arguments to lcase()/ucase() functions
-rw-r--r--libbutl/utility.ixx26
-rw-r--r--libbutl/utility.mxx21
2 files changed, 30 insertions, 17 deletions
diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx
index 72fbc5b..fa37a14 100644
--- a/libbutl/utility.ixx
+++ b/libbutl/utility.ixx
@@ -25,12 +25,15 @@ namespace butl
}
inline std::string&
- ucase (std::string& s)
+ ucase (std::string& s, std::size_t p, std::size_t n)
{
- if (size_t n = s.size ())
+ if (n == std::string::npos)
+ n = s.size () - p;
+
+ if (n != 0)
{
s.front () = s.front (); // Force copy in CoW.
- ucase (const_cast<char*> (s.data ()), n);
+ ucase (const_cast<char*> (s.data ()) + p, n);
}
return s;
}
@@ -43,9 +46,9 @@ namespace butl
}
inline std::string
- ucase (const std::string& s)
+ ucase (const std::string& s, std::size_t p, std::size_t n)
{
- return ucase (s.c_str (), s.size ());
+ return ucase (s.c_str () + p, n != std::string::npos ? n : s.size () - p);
}
inline char
@@ -62,12 +65,15 @@ namespace butl
}
inline std::string&
- lcase (std::string& s)
+ lcase (std::string& s, std::size_t p, std::size_t n)
{
- if (size_t n = s.size ())
+ if (n == std::string::npos)
+ n = s.size () - p;
+
+ if (n != 0)
{
s.front () = s.front (); // Force copy in CoW.
- lcase (const_cast<char*> (s.data ()), n);
+ lcase (const_cast<char*> (s.data ()) + p, n);
}
return s;
}
@@ -80,9 +86,9 @@ namespace butl
}
inline std::string
- lcase (const std::string& s)
+ lcase (const std::string& s, std::size_t p, std::size_t n)
{
- return lcase (s.c_str (), s.size ());
+ return lcase (s.c_str () + p, n != std::string::npos ? n : s.size () - p);
}
inline int
diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx
index 78c9355..a59686b 100644
--- a/libbutl/utility.mxx
+++ b/libbutl/utility.mxx
@@ -86,16 +86,23 @@ LIBBUTL_MODEXPORT namespace butl
// http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html#tag_07_02)
//
char ucase (char);
- std::string ucase (const char*, std::size_t = std::string::npos);
-
- std::string ucase (const std::string&);
- std::string& ucase (std::string&);
+ std::string ucase (const char*, std::size_t n = std::string::npos);
+ 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);
char lcase (char);
- std::string lcase (const char*, std::size_t = std::string::npos);
- std::string lcase (const std::string&);
- std::string& lcase (std::string&);
+ 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);
// Compare ASCII characters/strings ignoring case. Behave as if characters