lib/base: Make to_hex() easier to use
This commit is contained in:
parent
7f71924a86
commit
96e0021572
|
@ -185,8 +185,7 @@ removeFileExt(std::string filename)
|
||||||
return filename.substr(0, dot);
|
return filename.substr(0, dot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
std::string to_hex(const std::string& subject, int width, const char fill)
|
||||||
toHex(std::string& subject, int width, const char fill)
|
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::hex;
|
ss << std::hex;
|
||||||
|
@ -194,7 +193,7 @@ toHex(std::string& subject, int width, const char fill)
|
||||||
ss << std::setw(width) << std::setfill(fill) << (int)(unsigned char)subject[i];
|
ss << std::setw(width) << std::setfill(fill) << (int)(unsigned char)subject[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
subject = ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -75,7 +75,7 @@ std::string removeFileExt(std::string filename);
|
||||||
/*!
|
/*!
|
||||||
Convert each character in \c subject into hexdecimal form with \c width
|
Convert each character in \c subject into hexdecimal form with \c width
|
||||||
*/
|
*/
|
||||||
void toHex(std::string& subject, int width, const char fill = '0');
|
std::string to_hex(const std::string& subject, int width, const char fill = '0');
|
||||||
|
|
||||||
//! Convert to all uppercase
|
//! Convert to all uppercase
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -23,7 +23,7 @@ std::string format_ssl_fingerprint(const std::string& fingerprint, bool hex, boo
|
||||||
std::string result = fingerprint;
|
std::string result = fingerprint;
|
||||||
if (hex) {
|
if (hex) {
|
||||||
// to hexadecimal
|
// to hexadecimal
|
||||||
barrier::string::toHex(result, 2);
|
result = barrier::string::to_hex(result, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// all uppercase
|
// all uppercase
|
||||||
|
@ -36,4 +36,5 @@ std::string format_ssl_fingerprint(const std::string& fingerprint, bool hex, boo
|
||||||
result.insert(i * 3 - 1, ":");
|
result.insert(i * 3 - 1, ":");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,9 +59,7 @@ TEST(StringTests, toHex_plaintext_hexString)
|
||||||
String subject = "foobar";
|
String subject = "foobar";
|
||||||
int width = 2;
|
int width = 2;
|
||||||
|
|
||||||
string::toHex(subject, width);
|
EXPECT_EQ("666f6f626172", string::to_hex(subject, width));
|
||||||
|
|
||||||
EXPECT_EQ("666f6f626172", subject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StringTests, uppercase_lowercaseInput_uppercaseOutput)
|
TEST(StringTests, uppercase_lowercaseInput_uppercaseOutput)
|
||||||
|
|
Loading…
Reference in New Issue