Skip to content

Commit

Permalink
util: Make ToLower and ToUpper take a char
Browse files Browse the repository at this point in the history
Unfortunately, `std::string` elements are (bare) chars. As these
are the most likely type to be passed to these functions, make them use
char instead of unsigned char. This avoids some casts.
  • Loading branch information
laanwj committed Jan 10, 2019
1 parent edb5bb3 commit 332b3dd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/test/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ BOOST_AUTO_TEST_CASE(test_ToLower)
BOOST_CHECK_EQUAL(ToLower('Z'), 'z');
BOOST_CHECK_EQUAL(ToLower('['), '[');
BOOST_CHECK_EQUAL(ToLower(0), 0);
BOOST_CHECK_EQUAL(ToLower(255), 255);
BOOST_CHECK_EQUAL(ToLower('\xff'), '\xff');

std::string testVector;
Downcase(testVector);
Expand All @@ -1246,7 +1246,7 @@ BOOST_AUTO_TEST_CASE(test_ToUpper)
BOOST_CHECK_EQUAL(ToUpper('z'), 'Z');
BOOST_CHECK_EQUAL(ToUpper('{'), '{');
BOOST_CHECK_EQUAL(ToUpper(0), 0);
BOOST_CHECK_EQUAL(ToUpper(255), 255);
BOOST_CHECK_EQUAL(ToUpper('\xff'), '\xff');
}

BOOST_AUTO_TEST_CASE(test_Capitalize)
Expand Down
2 changes: 1 addition & 1 deletion src/uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void base_blob<BITS>::SetHex(const char* psz)
psz++;

// skip 0x
if (psz[0] == '0' && ToLower((unsigned char)psz[1]) == 'x')
if (psz[0] == '0' && ToLower(psz[1]) == 'x')
psz += 2;

// hex string to uint
Expand Down
2 changes: 1 addition & 1 deletion src/util/strencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypa

void Downcase(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c){return ToLower(c);});
std::transform(str.begin(), str.end(), str.begin(), [](char c){return ToLower(c);});
}

std::string Capitalize(std::string str)
Expand Down
4 changes: 2 additions & 2 deletions src/util/strencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ NODISCARD bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32
* @return the lowercase equivalent of c; or the argument
* if no conversion is possible.
*/
constexpr unsigned char ToLower(unsigned char c)
constexpr char ToLower(char c)
{
return (c >= 'A' && c <= 'Z' ? (c - 'A') + 'a' : c);
}
Expand All @@ -229,7 +229,7 @@ void Downcase(std::string& str);
* @return the uppercase equivalent of c; or the argument
* if no conversion is possible.
*/
constexpr unsigned char ToUpper(unsigned char c)
constexpr char ToUpper(char c)
{
return (c >= 'a' && c <= 'z' ? (c - 'a') + 'A' : c);
}
Expand Down

0 comments on commit 332b3dd

Please sign in to comment.