chore: String toHex should return a string not do inplace conversion
This commit is contained in:
parent
ac54a97a3f
commit
9b1489384c
5 changed files with 7 additions and 11 deletions
|
|
@ -176,7 +176,7 @@ std::string removeFileExt(std::string filename)
|
|||
return filename.substr(0, dot);
|
||||
}
|
||||
|
||||
void toHex(std::string &subject, int width, const char fill)
|
||||
std::string toHex(const std::string &subject, int width, const char fill)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::hex;
|
||||
|
|
@ -184,7 +184,7 @@ void toHex(std::string &subject, int width, const char fill)
|
|||
ss << std::setw(width) << std::setfill(fill) << (int)(unsigned char)subject[i];
|
||||
}
|
||||
|
||||
subject = ss.str();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void uppercase(std::string &subject)
|
||||
|
|
|
|||
|
|
@ -71,8 +71,9 @@ std::string removeFileExt(std::string filename);
|
|||
//! Convert into hexdecimal
|
||||
/*!
|
||||
Convert each character in \c subject into hexdecimal form with \c width
|
||||
Return a new hexString
|
||||
*/
|
||||
void toHex(std::string &subject, int width, const char fill = '0');
|
||||
std::string toHex(const std::string &subject, int width, const char fill = '0');
|
||||
|
||||
//! Convert to all uppercase
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ int SslApi::getErrorCode(int status) const
|
|||
void SslApi::formatFingerprint(std::string &fingerprint) const
|
||||
{
|
||||
// to hexidecimal
|
||||
deskflow::string::toHex(fingerprint, 2);
|
||||
fingerprint = deskflow::string::toHex(fingerprint, 2);
|
||||
// all uppercase
|
||||
deskflow::string::uppercase(fingerprint);
|
||||
// add colon to separate each 2 charactors
|
||||
|
|
|
|||
|
|
@ -625,7 +625,7 @@ void SecureSocket::formatFingerprint(std::string &fingerprint, bool hex, bool se
|
|||
{
|
||||
if (hex) {
|
||||
// to hexidecimal
|
||||
deskflow::string::toHex(fingerprint, 2);
|
||||
fingerprint = deskflow::string::toHex(fingerprint, 2);
|
||||
}
|
||||
|
||||
// all uppercase
|
||||
|
|
|
|||
|
|
@ -56,12 +56,7 @@ TEST(StringTests, sprintf_formatWithArgument_formatedString)
|
|||
|
||||
TEST(StringTests, toHex_plaintext_hexString)
|
||||
{
|
||||
std::string subject = "foobar";
|
||||
int width = 2;
|
||||
|
||||
string::toHex(subject, width);
|
||||
|
||||
EXPECT_EQ("666f6f626172", subject);
|
||||
EXPECT_EQ("666f6f626172", string::toHex("foobar", 2));
|
||||
}
|
||||
|
||||
TEST(StringTests, uppercase_lowercaseInput_uppercaseOutput)
|
||||
|
|
|
|||
Loading…
Reference in a new issue