summaryrefslogtreecommitdiffstats
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r--src/StringUtils.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index ad622d707..7488a3073 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -247,18 +247,22 @@ int NoCaseCompare(const AString & s1, const AString & s2)
-unsigned int RateCompareString(const AString & s1, const AString & s2 )
+size_t RateCompareString(const AString & s1, const AString & s2)
{
- unsigned int MatchedLetters = 0;
- unsigned int s1Length = s1.length();
+ size_t MatchedLetters = 0;
+ size_t s1Length = s1.length();
- if( s1Length > s2.length() ) return 0; // Definitely not a match
+ if (s1Length > s2.length())
+ {
+ // Definitely not a match
+ return 0;
+ }
- for (unsigned int i = 0; i < s1Length; i++)
+ for (size_t i = 0; i < s1Length; i++)
{
- char c1 = (char)toupper( s1[i] );
- char c2 = (char)toupper( s2[i] );
- if( c1 == c2 )
+ char c1 = (char)toupper(s1[i]);
+ char c2 = (char)toupper(s2[i]);
+ if (c1 == c2)
{
++MatchedLetters;
}
@@ -288,11 +292,11 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString &
// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
-AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8)
+AString & RawBEToUTF8(const char * a_RawData, size_t a_NumShorts, AString & a_UTF8)
{
a_UTF8.clear();
a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size
- for (int i = 0; i < a_NumShorts; i++)
+ for (size_t i = 0; i < a_NumShorts; i++)
{
int c = GetBEShort(&a_RawData[i * 2]);
if (c < 0x80)
@@ -531,32 +535,32 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a
format binary data this way:
00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef
*/
-AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_LineLength)
+AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine)
{
- ASSERT(a_LineLength <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max
+ ASSERT(a_BytesPerLine <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max
char line[512];
char * p;
char * q;
- a_Out.reserve(a_Size / a_LineLength * (18 + 6 * a_LineLength));
- for (int i = 0; i < a_Size; i += a_LineLength)
+ a_Out.reserve(a_Size / a_BytesPerLine * (18 + 6 * a_BytesPerLine));
+ for (size_t i = 0; i < a_Size; i += a_BytesPerLine)
{
- int k = a_Size - i;
- if (k > a_LineLength)
+ size_t k = a_Size - i;
+ if (k > a_BytesPerLine)
{
- k = a_LineLength;
+ k = a_BytesPerLine;
}
#ifdef _MSC_VER
// MSVC provides a "secure" version of sprintf()
- int Count = sprintf_s(line, sizeof(line), "%08x:", i);
+ int Count = sprintf_s(line, sizeof(line), "%08x:", (unsigned)i);
#else
- int Count = sprintf(line, "%08x:", i);
+ int Count = sprintf(line, "%08x:", (unsigned)i);
#endif
// Remove the terminating NULL / leftover garbage in line, after the sprintf-ed value
memset(line + Count, 32, sizeof(line) - Count);
p = line + 10;
- q = p + 2 + a_LineLength * 3 + 1;
- for (int j = 0; j < k; j++)
+ q = p + 2 + a_BytesPerLine * 3 + 1;
+ for (size_t j = 0; j < k; j++)
{
unsigned char c = ((unsigned char *)a_Data)[i + j];
p[0] = HEX(c >> 4);