Restrict hex string generation to non-negative values.

It turns out the specific generator I use doesn't support signed
integers, which is OK, since I only ever plug unsigned integers into it.
Updated the function argument type to reflect that.
This commit is contained in:
Oliver Hamlet
2015-07-12 18:37:24 +01:00
parent cedb054ab5
commit 6d2dc6b2fc
3 changed files with 4 additions and 5 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ namespace loot {
}
//Converts an integer to a hex string using BOOST's Spirit.Karma, which is apparently a lot faster than a stringstream conversion...
std::string IntToHexString(const int n) {
std::string IntToHexString(const uint32_t n) {
string out;
back_insert_iterator<string> sink(out);
karma::generate(sink, karma::upper[karma::hex], n);
+2 -2
View File
@@ -33,8 +33,8 @@ namespace loot {
//Calculate the CRC of the given file for comparison purposes.
uint32_t GetCrc32(const boost::filesystem::path& filename);
//Converts an integer to a hex string using BOOST's Spirit.Karma. Faster than a stringstream conversion.
std::string IntToHexString(const int n);
//Converts an unsigned 32-bit integer to a hex string using BOOST's Spirit.Karma. Faster than a stringstream conversion.
std::string IntToHexString(const uint32_t n);
#ifdef _WIN32
//Get registry subkey value string.
+1 -2
View File
@@ -39,9 +39,8 @@ TEST_F(GetCrc32, ValidFile) {
EXPECT_EQ(0x0B5B7B90, loot::GetCrc32(dataPath / "Blank.esp"));
}
TEST(IntToHexString, PositiveNegativeZeroValues) {
TEST(IntToHexString, PositiveAndZeroValues) {
EXPECT_EQ("14", loot::IntToHexString(20));
EXPECT_EQ("-14", loot::IntToHexString(-20));
EXPECT_EQ("0", loot::IntToHexString(0));
}