aboutsummaryrefslogtreecommitdiff
path: root/src/utilstrencodings.h
diff options
context:
space:
mode:
author251 <13120787+251Labs@users.noreply.github.com>2018-08-28 18:42:27 +0200
committer251 <13120787+251Labs@users.noreply.github.com>2018-08-28 18:42:27 +0200
commit7a208d9fade56e2347891daff2f6b903923c9d50 (patch)
tree575ae31e45b1069110bd344f0eb27d8ee8ef6ddb /src/utilstrencodings.h
parente2ba043b8d852d3f465bc293d6e494c8c6f75dfd (diff)
downloadbitcoin-7a208d9fade56e2347891daff2f6b903923c9d50.tar.xz
Implements custom tolower and toupper functions.
This commit implements custom equivalents for the C and C++ `tolower` and `toupper` Standard Library functions. In addition it implements a utility function to capitalize the first letter of a string.
Diffstat (limited to 'src/utilstrencodings.h')
-rw-r--r--src/utilstrencodings.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h
index 8f29f8f322..846a3917a2 100644
--- a/src/utilstrencodings.h
+++ b/src/utilstrencodings.h
@@ -186,4 +186,48 @@ bool ConvertBits(const O& outfn, I it, I end) {
/** Parse an HD keypaths like "m/7/0'/2000". */
bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath);
+/**
+ * Converts the given character to its lowercase equivalent.
+ * This function is locale independent. It only converts uppercase
+ * characters in the standard 7-bit ASCII range.
+ * @param[in] c the character to convert to lowercase.
+ * @return the lowercase equivalent of c; or the argument
+ * if no conversion is possible.
+ */
+constexpr unsigned char ToLower(unsigned char c)
+{
+ return (c >= 'A' && c <= 'Z' ? (c - 'A') + 'a' : c);
+}
+
+/**
+ * Converts the given string to its lowercase equivalent.
+ * This function is locale independent. It only converts uppercase
+ * characters in the standard 7-bit ASCII range.
+ * @param[in,out] str the string to convert to lowercase.
+ */
+void Downcase(std::string& str);
+
+/**
+ * Converts the given character to its uppercase equivalent.
+ * This function is locale independent. It only converts lowercase
+ * characters in the standard 7-bit ASCII range.
+ * @param[in] c the character to convert to uppercase.
+ * @return the uppercase equivalent of c; or the argument
+ * if no conversion is possible.
+ */
+constexpr unsigned char ToUpper(unsigned char c)
+{
+ return (c >= 'a' && c <= 'z' ? (c - 'a') + 'A' : c);
+}
+
+/**
+ * Capitalizes the first character of the given string.
+ * This function is locale independent. It only capitalizes the
+ * first character of the argument if it has an uppercase equivalent
+ * in the standard 7-bit ASCII range.
+ * @param[in] str the string to capitalize.
+ * @return string with the first letter capitalized.
+ */
+std::string Capitalize(std::string str);
+
#endif // BITCOIN_UTILSTRENCODINGS_H