From 177d187a8e1eb01d18f4541726467bf6eef114fd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 1 Oct 2020 11:51:38 +0200 Subject: Add position and size arguments to lcase()/ucase() functions --- libbutl/utility.ixx | 26 ++++++++++++++++---------- libbutl/utility.mxx | 21 ++++++++++++++------- 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 (s.data ()), n); + ucase (const_cast (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 (s.data ()), n); + lcase (const_cast (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 -- cgit v1.1