From aa0370b08ea8a1ad679a746c7be21a874f264fb6 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 8 Aug 2016 00:49:04 +0300 Subject: Add ucase(), lcase(), casecmp(), alpha(), digit(), alnum() --- butl/utility | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'butl/utility') diff --git a/butl/utility b/butl/utility index 101d503..757edc2 100644 --- a/butl/utility +++ b/butl/utility @@ -5,14 +5,73 @@ #ifndef BUTL_UTILITY #define BUTL_UTILITY -#include // std::size_t +#include +#include // size_t #include // forward() -#include // strcmp +#include // strcmp(), strlen() #include namespace butl { + // Convert ASCII character/string case. If there is no upper/lower case + // counterpart, leave the character unchanged. The POSIX locale (also known + // as C locale) must be the current application locale. Otherwise the + // behavior is undefined. + // + // Note that the POSIX locale specifies behaviour on data consisting + // entirely of characters from the portable character set (subset of ASCII + // including 103 non-negative characters and English alphabet letters in + // particular) and the control character set (more about them at + // http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap06.html). + // + // Also note that according to the POSIX locale definition the case + // conversion can be applied only to [A-Z] and [a-z] character ranges being + // translated to each other (more about that at + // 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&); + LIBBUTL_EXPORT 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&); + LIBBUTL_EXPORT void 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 + // negative, zero or positive value if the left hand side is less, equal or + // greater than the right hand side, respectivelly. The POSIX locale (also + // known as C locale) must be the current application locale. Otherwise the + // behavior is undefined. + // + // The optional size argument specifies the maximum number of characters + // to compare. + // + int casecmp (char, char); + + int casecmp (const std::string&, const std::string&, + std::size_t = std::string::npos); + + int casecmp (const std::string&, const char*, + std::size_t = std::string::npos); + + LIBBUTL_EXPORT int casecmp (const char*, const char*, + std::size_t = std::string::npos); + + bool + alpha (char); + + bool + digit (char); + + bool + alnum (char); + // Key comparators (i.e., to be used in sets, maps, etc). // struct compare_c_string @@ -67,4 +126,6 @@ namespace butl reverse_iterate (T&& x) {return reverse_range (std::forward (x));} } +#include + #endif // BUTL_UTILITY -- cgit v1.1