39 bool negative =
false;
54 while ((*str ==
'x' || *str ==
'X') || (*str >=
'0' && *str <=
'9')
55 || (*str >=
'a' && *str <=
'f') || (*str >=
'A' && *str <=
'F')) {
58 if (c ==
'x' || c ==
'X') {
71 if (base == 10 && (c < '0' || c >
'9'))
75 if (c >=
'a' && c <=
'f')
77 if (c >=
'A' && c <=
'F')
80 if (base == 16 && (n < 0 || n > 15))
83 result = result * base + n;
102 vector<string> strings;
104 bool lastWasSplitter =
false;
106 for (
size_t i=0, n=str.length(); i<n; i++) {
108 if (ch == splitter) {
109 strings.push_back(word);
111 lastWasSplitter =
true;
114 lastWasSplitter =
false;
118 if (word !=
"" || lastWasSplitter)
119 strings.push_back(word);
130 static void Test_StringHelper_ParseNumber_Simple()
141 static void Test_StringHelper_ParseNumber_SimpleError()
151 static void Test_StringHelper_ParseNumber_Negative()
162 static void Test_StringHelper_ParseNumber_LeadingSpaces()
173 static void Test_StringHelper_ParseNumber_LeadingSpacesAndNegative()
184 static void Test_StringHelper_ParseNumber_LeadingSpacesAndErrorNegative()
194 static void Test_StringHelper_ParseNumber_SimpleHexLowerCase()
205 static void Test_StringHelper_ParseNumber_SimpleHexUpperCase()
216 static void Test_StringHelper_ParseNumber_HexErrorDoubleX()
226 static void Test_StringHelper_ParseNumber_HexErrorNonZeroPrefix()
236 static void Test_StringHelper_ParseNumber_NumberFollowedByErrorValidHexChar()
246 static void Test_StringHelper_ParseNumber_NumberFollowedByError()
256 static void Test_StringHelper_SplitStringIntoVector_Simple()
266 static void Test_StringHelper_SplitStringIntoVector_EmptyInput()
273 static void Test_StringHelper_SplitStringIntoVector_Simple2()
282 static void Test_StringHelper_SplitStringIntoVector_WithZeroLengthParts()
295 static void Test_StringHelper_SplitStringIntoVector_WithTrailingZeroLengthParts()
305 static void Test_StringHelper_SplitStringIntoVector_WithHeadingZeroLengthParts()
316 UNITTEST(Test_StringHelper_ParseNumber_Simple);
317 UNITTEST(Test_StringHelper_ParseNumber_SimpleError);
318 UNITTEST(Test_StringHelper_ParseNumber_Negative);
319 UNITTEST(Test_StringHelper_ParseNumber_LeadingSpaces);
320 UNITTEST(Test_StringHelper_ParseNumber_LeadingSpacesAndNegative);
321 UNITTEST(Test_StringHelper_ParseNumber_LeadingSpacesAndErrorNegative);
322 UNITTEST(Test_StringHelper_ParseNumber_SimpleHexLowerCase);
323 UNITTEST(Test_StringHelper_ParseNumber_SimpleHexUpperCase);
324 UNITTEST(Test_StringHelper_ParseNumber_HexErrorDoubleX);
325 UNITTEST(Test_StringHelper_ParseNumber_HexErrorNonZeroPrefix);
326 UNITTEST(Test_StringHelper_ParseNumber_NumberFollowedByErrorValidHexChar);
327 UNITTEST(Test_StringHelper_ParseNumber_NumberFollowedByError);
329 UNITTEST(Test_StringHelper_SplitStringIntoVector_Simple);
330 UNITTEST(Test_StringHelper_SplitStringIntoVector_EmptyInput);
331 UNITTEST(Test_StringHelper_SplitStringIntoVector_Simple2);
332 UNITTEST(Test_StringHelper_SplitStringIntoVector_WithZeroLengthParts);
333 UNITTEST(Test_StringHelper_SplitStringIntoVector_WithTrailingZeroLengthParts);
334 UNITTEST(Test_StringHelper_SplitStringIntoVector_WithHeadingZeroLengthParts);
static vector< string > SplitStringIntoVector(const string &str, const char splitter)
Splits a string with a certain delimiter into a vector of strings.
static uint64_t ParseNumber(const char *str, bool &error)
Parses a string into a 64-bit number.
#define UNITTESTS(class)
Helper for unit test case execution.
A helper class, with static functions for common string operations.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
#define UNITTEST(functionname)
Helper for unit test case execution.