diff --git a/Foundation/include/Poco/NumberFormatter.h b/Foundation/include/Poco/NumberFormatter.h index 7ae85e658e..b50333f6c0 100644 --- a/Foundation/include/Poco/NumberFormatter.h +++ b/Foundation/include/Poco/NumberFormatter.h @@ -59,13 +59,13 @@ class Foundation_API NumberFormatter /// right justified and zero-padded in a field /// having at least the specified width. - static std::string formatHex(int value, bool prefix = false); + static std::string formatHex(int value, bool prefix = false, bool upper = true); /// Formats an int value in hexadecimal notation. /// If prefix is true, "0x" prefix is prepended to the /// resulting string. /// The value is treated as unsigned. - static std::string formatHex(int value, int width, bool prefix = false); + static std::string formatHex(int value, int width, bool prefix = false, bool upper = true); /// Formats a int value in hexadecimal notation, /// right justified and zero-padded in /// a field having at least the specified width. @@ -86,12 +86,12 @@ class Foundation_API NumberFormatter /// right justified and zero-padded in a field having at /// least the specified width. - static std::string formatHex(unsigned value, bool prefix = false); + static std::string formatHex(unsigned value, bool prefix = false, bool upper = true); /// Formats an unsigned int value in hexadecimal notation. /// If prefix is true, "0x" prefix is prepended to the /// resulting string. - static std::string formatHex(unsigned value, int width, bool prefix = false); + static std::string formatHex(unsigned value, int width, bool prefix = false, bool upper = true); /// Formats a int value in hexadecimal notation, /// right justified and zero-padded in /// a field having at least the specified width. @@ -111,13 +111,13 @@ class Foundation_API NumberFormatter /// right justified and zero-padded in a field /// having at least the specified width. - static std::string formatHex(long value, bool prefix = false); + static std::string formatHex(long value, bool prefix = false, bool upper = true); /// Formats an unsigned long value in hexadecimal notation. /// If prefix is true, "0x" prefix is prepended to the /// resulting string. /// The value is treated as unsigned. - static std::string formatHex(long value, int width, bool prefix = false); + static std::string formatHex(long value, int width, bool prefix = false, bool upper = true); /// Formats an unsigned long value in hexadecimal notation, /// right justified and zero-padded in a field having at least the /// specified width. @@ -138,12 +138,12 @@ class Foundation_API NumberFormatter /// right justified and zero-padded /// in a field having at least the specified width. - static std::string formatHex(unsigned long value, bool prefix = false); + static std::string formatHex(unsigned long value, bool prefix = false, bool upper = true); /// Formats an unsigned long value in hexadecimal notation. /// If prefix is true, "0x" prefix is prepended to the /// resulting string. - static std::string formatHex(unsigned long value, int width, bool prefix = false); + static std::string formatHex(unsigned long value, int width, bool prefix = false, bool upper = true); /// Formats an unsigned long value in hexadecimal notation, /// right justified and zero-padded in a field having at least the /// specified width. @@ -165,13 +165,13 @@ class Foundation_API NumberFormatter /// right justified and zero-padded in a field having at least /// the specified width. - static std::string formatHex(long long value, bool prefix = false); + static std::string formatHex(long long value, bool prefix = false, bool upper = true); /// Formats a 64-bit integer value in hexadecimal notation. /// If prefix is true, "0x" prefix is prepended to the /// resulting string. /// The value is treated as unsigned. - static std::string formatHex(long long value, int width, bool prefix = false); + static std::string formatHex(long long value, int width, bool prefix = false, bool upper = true); /// Formats a 64-bit integer value in hexadecimal notation, /// right justified and zero-padded in a field having at least /// the specified width. @@ -190,12 +190,12 @@ class Foundation_API NumberFormatter /// right justified and zero-padded in a field having at least the /// specified width. - static std::string formatHex(unsigned long long value, bool prefix = false); + static std::string formatHex(unsigned long long value, bool prefix = false, bool upper = true); /// Formats a 64-bit integer value in hexadecimal notation. /// If prefix is true, "0x" prefix is prepended to the /// resulting string. - static std::string formatHex(unsigned long long value, int width, bool prefix = false); + static std::string formatHex(unsigned long long value, int width, bool prefix = false, bool upper = true); /// Formats a 64-bit integer value in hexadecimal notation, /// right justified and zero-padded in a field having at least /// the specified width. If prefix is true, "0x" prefix is @@ -215,13 +215,13 @@ class Foundation_API NumberFormatter /// right justified and zero-padded in a field having at least /// the specified width. - static std::string formatHex(Int64 value, bool prefix = false); + static std::string formatHex(Int64 value, bool prefix = false, bool upper = true); /// Formats a 64-bit integer value in hexadecimal notation. /// If prefix is true, "0x" prefix is prepended to the /// resulting string. /// The value is treated as unsigned. - static std::string formatHex(Int64 value, int width, bool prefix = false); + static std::string formatHex(Int64 value, int width, bool prefix = false, bool upper = true); /// Formats a 64-bit integer value in hexadecimal notation, /// right justified and zero-padded in a field having at least /// the specified width. @@ -240,12 +240,12 @@ class Foundation_API NumberFormatter /// right justified and zero-padded in a field having at least the /// specified width. - static std::string formatHex(UInt64 value, bool prefix = false); + static std::string formatHex(UInt64 value, bool prefix = false, bool upper = true); /// Formats a 64-bit integer value in hexadecimal notation. /// If prefix is true, "0x" prefix is prepended to the /// resulting string. - static std::string formatHex(UInt64 value, int width, bool prefix = false); + static std::string formatHex(UInt64 value, int width, bool prefix = false, bool upper = true); /// Formats a 64-bit integer value in hexadecimal notation, /// right justified and zero-padded in a field having at least /// the specified width. If prefix is true, "0x" prefix is @@ -532,18 +532,18 @@ inline std::string NumberFormatter::format0(int value, int width) } -inline std::string NumberFormatter::formatHex(int value, bool prefix) +inline std::string NumberFormatter::formatHex(int value, bool prefix, bool upper) { std::string result; - uIntToStr(static_cast(value), 0x10, result, prefix); + uIntToStr(static_cast(value), 0x10, result, prefix, -1, ' ', 0, upper); return result; } -inline std::string NumberFormatter::formatHex(int value, int width, bool prefix) +inline std::string NumberFormatter::formatHex(int value, int width, bool prefix, bool upper) { std::string result; - uIntToStr(static_cast(value), 0x10, result, prefix, width, '0'); + uIntToStr(static_cast(value), 0x10, result, prefix, width, '0', 0, upper); return result; } @@ -572,18 +572,18 @@ inline std::string NumberFormatter::format0(unsigned int value, int width) } -inline std::string NumberFormatter::formatHex(unsigned value, bool prefix) +inline std::string NumberFormatter::formatHex(unsigned value, bool prefix, bool upper) { std::string result; - uIntToStr(value, 0x10, result, prefix); + uIntToStr(value, 0x10, result, prefix, -1, ' ', 0, upper); return result; } -inline std::string NumberFormatter::formatHex(unsigned value, int width, bool prefix) +inline std::string NumberFormatter::formatHex(unsigned value, int width, bool prefix, bool upper) { std::string result; - uIntToStr(value, 0x10, result, prefix, width, '0'); + uIntToStr(value, 0x10, result, prefix, width, '0', 0, upper); return result; } @@ -612,18 +612,18 @@ inline std::string NumberFormatter::format0(long value, int width) } -inline std::string NumberFormatter::formatHex(long value, bool prefix) +inline std::string NumberFormatter::formatHex(long value, bool prefix, bool upper) { std::string result; - uIntToStr(static_cast(value), 0x10, result, prefix); + uIntToStr(static_cast(value), 0x10, result, prefix, -1, ' ', 0, upper); return result; } -inline std::string NumberFormatter::formatHex(long value, int width, bool prefix) +inline std::string NumberFormatter::formatHex(long value, int width, bool prefix, bool upper) { std::string result; - uIntToStr(static_cast(value), 0x10, result, prefix, width, '0'); + uIntToStr(static_cast(value), 0x10, result, prefix, width, '0', 0, upper); return result; } @@ -652,18 +652,18 @@ inline std::string NumberFormatter::format0(unsigned long value, int width) } -inline std::string NumberFormatter::formatHex(unsigned long value, bool prefix) +inline std::string NumberFormatter::formatHex(unsigned long value, bool prefix, bool upper) { std::string result; - uIntToStr(value, 0x10, result, prefix); + uIntToStr(value, 0x10, result, prefix, -1, ' ', 0, upper); return result; } -inline std::string NumberFormatter::formatHex(unsigned long value, int width, bool prefix) +inline std::string NumberFormatter::formatHex(unsigned long value, int width, bool prefix, bool upper) { std::string result; - uIntToStr(value, 0x10, result, prefix, width, '0'); + uIntToStr(value, 0x10, result, prefix, width, '0', 0, upper); return result; } @@ -696,18 +696,18 @@ inline std::string NumberFormatter::format0(long long value, int width) } -inline std::string NumberFormatter::formatHex(long long value, bool prefix) +inline std::string NumberFormatter::formatHex(long long value, bool prefix, bool upper) { std::string result; - uIntToStr(static_cast(value), 0x10, result, prefix); + uIntToStr(static_cast(value), 0x10, result, prefix, -1, ' ', 0, upper); return result; } -inline std::string NumberFormatter::formatHex(long long value, int width, bool prefix) +inline std::string NumberFormatter::formatHex(long long value, int width, bool prefix, bool upper) { std::string result; - uIntToStr(static_cast(value), 0x10, result, prefix, width, '0'); + uIntToStr(static_cast(value), 0x10, result, prefix, width, '0', 0, upper); return result; } @@ -736,18 +736,18 @@ inline std::string NumberFormatter::format0(unsigned long long value, int width) } -inline std::string NumberFormatter::formatHex(unsigned long long value, bool prefix) +inline std::string NumberFormatter::formatHex(unsigned long long value, bool prefix, bool upper) { std::string result; - uIntToStr(value, 0x10, result, prefix); + uIntToStr(value, 0x10, result, prefix, -1, ' ', 0, upper); return result; } -inline std::string NumberFormatter::formatHex(unsigned long long value, int width, bool prefix) +inline std::string NumberFormatter::formatHex(unsigned long long value, int width, bool prefix, bool upper) { std::string result; - uIntToStr(value, 0x10, result, prefix, width, '0'); + uIntToStr(value, 0x10, result, prefix, width, '0', 0, upper); return result; } @@ -779,18 +779,18 @@ inline std::string NumberFormatter::format0(Int64 value, int width) } -inline std::string NumberFormatter::formatHex(Int64 value, bool prefix) +inline std::string NumberFormatter::formatHex(Int64 value, bool prefix, bool upper) { std::string result; - uIntToStr(static_cast(value), 0x10, result, prefix); + uIntToStr(static_cast(value), 0x10, result, prefix, -1, ' ', 0, upper); return result; } -inline std::string NumberFormatter::formatHex(Int64 value, int width, bool prefix) +inline std::string NumberFormatter::formatHex(Int64 value, int width, bool prefix, bool upper) { std::string result; - uIntToStr(static_cast(value), 0x10, result, prefix, width, '0'); + uIntToStr(static_cast(value), 0x10, result, prefix, width, '0', 0, upper); return result; } @@ -819,18 +819,18 @@ inline std::string NumberFormatter::format0(UInt64 value, int width) } -inline std::string NumberFormatter::formatHex(UInt64 value, bool prefix) +inline std::string NumberFormatter::formatHex(UInt64 value, bool prefix, bool upper) { std::string result; - uIntToStr(value, 0x10, result, prefix); + uIntToStr(value, 0x10, result, prefix, -1, ' ', 0, upper); return result; } -inline std::string NumberFormatter::formatHex(UInt64 value, int width, bool prefix) +inline std::string NumberFormatter::formatHex(UInt64 value, int width, bool prefix, bool upper) { std::string result; - uIntToStr(value, 0x10, result, prefix, width, '0'); + uIntToStr(value, 0x10, result, prefix, width, '0', 0, upper); return result; } diff --git a/Foundation/include/Poco/NumericString.h b/Foundation/include/Poco/NumericString.h index 7fbb5b3f46..a992b65d18 100644 --- a/Foundation/include/Poco/NumericString.h +++ b/Foundation/include/Poco/NumericString.h @@ -374,7 +374,8 @@ bool intToStr(T value, bool prefix = false, int width = -1, char fill = ' ', - char thSep = 0) + char thSep = 0, + bool upper = true) /// Converts integer to string. Numeric bases from binary to hexadecimal are supported. /// If width is non-zero, it pads the return value with fill character to the specified width. /// When padding is zero character ('0'), it is prepended to the number itself; all other @@ -396,7 +397,10 @@ bool intToStr(T value, { tmpVal = value; value /= base; - *ptr++ = "FEDCBA9876543210123456789ABCDEF"[15 + (tmpVal - value * base)]; + if (upper) + *ptr++ = "FEDCBA9876543210123456789ABCDEF"[15 + (tmpVal - value * base)]; + else + *ptr++ = "fedcba9876543210123456789abcdef"[15 + (tmpVal - value * base)]; if (thSep && (base == 10) && (++thCount == 3)) { *ptr++ = thSep; @@ -452,7 +456,8 @@ bool uIntToStr(T value, bool prefix = false, int width = -1, char fill = ' ', - char thSep = 0) + char thSep = 0, + bool upper = true) /// Converts unsigned integer to string. Numeric bases from binary to hexadecimal are supported. /// If width is non-zero, it pads the return value with fill character to the specified width. /// When padding is zero character ('0'), it is prepended to the number itself; all other @@ -474,7 +479,10 @@ bool uIntToStr(T value, { tmpVal = value; value /= base; - *ptr++ = "FEDCBA9876543210123456789ABCDEF"[15 + (tmpVal - value * base)]; + if (upper) + *ptr++ = "FEDCBA9876543210123456789ABCDEF"[15 + (tmpVal - value * base)]; + else + *ptr++ = "fedcba9876543210123456789abcdef"[15 + (tmpVal - value * base)]; if (thSep && (base == 10) && (++thCount == 3)) { *ptr++ = thSep; @@ -520,26 +528,26 @@ bool uIntToStr(T value, template -bool intToStr (T number, unsigned short base, std::string& result, bool prefix = false, int width = -1, char fill = ' ', char thSep = 0) +bool intToStr (T number, unsigned short base, std::string& result, bool prefix = false, int width = -1, char fill = ' ', char thSep = 0, bool upper = true) /// Converts integer to string; This is a wrapper function, for details see see the /// bool intToStr(T, unsigned short, char*, int, int, char, char) implementation. { char res[POCO_MAX_INT_STRING_LEN] = {0}; std::size_t size = POCO_MAX_INT_STRING_LEN; - bool ret = intToStr(number, base, res, size, prefix, width, fill, thSep); + bool ret = intToStr(number, base, res, size, prefix, width, fill, thSep, upper); result.assign(res, size); return ret; } template -bool uIntToStr (T number, unsigned short base, std::string& result, bool prefix = false, int width = -1, char fill = ' ', char thSep = 0) +bool uIntToStr (T number, unsigned short base, std::string& result, bool prefix = false, int width = -1, char fill = ' ', char thSep = 0, bool upper = true) /// Converts unsigned integer to string; This is a wrapper function, for details see see the /// bool uIntToStr(T, unsigned short, char*, int, int, char, char) implementation. { char res[POCO_MAX_INT_STRING_LEN] = {0}; std::size_t size = POCO_MAX_INT_STRING_LEN; - bool ret = uIntToStr(number, base, res, size, prefix, width, fill, thSep); + bool ret = uIntToStr(number, base, res, size, prefix, width, fill, thSep, upper); result.assign(res, size); return ret; } diff --git a/Foundation/testsuite/src/NumberFormatterTest.cpp b/Foundation/testsuite/src/NumberFormatterTest.cpp index 71dd600354..c88c02a518 100644 --- a/Foundation/testsuite/src/NumberFormatterTest.cpp +++ b/Foundation/testsuite/src/NumberFormatterTest.cpp @@ -115,103 +115,142 @@ void NumberFormatterTest::testFormatHex() { assertTrue (NumberFormatter::formatHex(0x12) == "12"); assertTrue (NumberFormatter::formatHex(0xab) == "AB"); + assertTrue (NumberFormatter::formatHex(0xab, false, false) == "ab"); assertTrue (NumberFormatter::formatHex(0x12, 4) == "0012"); assertTrue (NumberFormatter::formatHex(0xab, 4) == "00AB"); + assertTrue (NumberFormatter::formatHex(0xab, 4, false, false) == "00ab"); assertTrue (NumberFormatter::formatHex((unsigned) 0x12) == "12"); assertTrue (NumberFormatter::formatHex((unsigned) 0xab) == "AB"); + assertTrue (NumberFormatter::formatHex((unsigned) 0xab, false, false) == "ab"); assertTrue (NumberFormatter::formatHex((unsigned) 0x12, 4) == "0012"); assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4) == "00AB"); + assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4, false, false) == "00ab"); assertTrue (NumberFormatter::formatHex((long) 0x12) == "12"); assertTrue (NumberFormatter::formatHex((long) 0xab) == "AB"); + assertTrue (NumberFormatter::formatHex((long) 0xab, false, false) == "ab"); assertTrue (NumberFormatter::formatHex((long) 0x12, 4) == "0012"); assertTrue (NumberFormatter::formatHex((long) 0xab, 4) == "00AB"); assertTrue (NumberFormatter::formatHex((unsigned long) 0x12) == "12"); assertTrue (NumberFormatter::formatHex((unsigned long) 0xab) == "AB"); + assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, false, false) == "ab"); assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, 4) == "0012"); assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4) == "00AB"); + assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4, false, false) == "00ab"); #if defined(POCO_HAVE_INT64) assertTrue (NumberFormatter::formatHex((Int64) 0x12) == "12"); assertTrue (NumberFormatter::formatHex((Int64) 0xab) == "AB"); + assertTrue (NumberFormatter::formatHex((Int64) 0xab, false, false) == "ab"); assertTrue (NumberFormatter::formatHex((Int64) 0x12, 4) == "0012"); assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4) == "00AB"); + assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4, false, false) == "00ab"); assertTrue (NumberFormatter::formatHex((UInt64) 0x12) == "12"); assertTrue (NumberFormatter::formatHex((UInt64) 0xab) == "AB"); + assertTrue (NumberFormatter::formatHex((UInt64) 0xab, false, false) == "ab"); assertTrue (NumberFormatter::formatHex((UInt64) 0x12, 4) == "0012"); assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4) == "00AB"); + assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4, false, false) == "00ab"); #if defined(POCO_LONG_IS_64_BIT) assertTrue (NumberFormatter::formatHex((long long) 0x12) == "12"); assertTrue (NumberFormatter::formatHex((long long) 0xab) == "AB"); + assertTrue (NumberFormatter::formatHex((long long) 0xab, false, false) == "ab"); assertTrue (NumberFormatter::formatHex((long long) 0x12, 4) == "0012"); assertTrue (NumberFormatter::formatHex((long long) 0xab, 4) == "00AB"); + assertTrue (NumberFormatter::formatHex((long long) 0xab, 4, false, false) == "00ab"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0x12) == "12"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab) == "AB"); + assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, false, false) == "ab"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0x12, 4) == "0012"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 4) == "00AB"); + assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 4, false, false) == "00ab"); #endif #endif assertTrue (NumberFormatter::formatHex(0x12, true) == "0x12"); assertTrue (NumberFormatter::formatHex(0xab, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex(0xab, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex(0x12, 4, true) == "0x12"); assertTrue (NumberFormatter::formatHex(0xab, 4, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex(0xab, 4, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex(0x12, 6, true) == "0x0012"); assertTrue (NumberFormatter::formatHex(0xab, 6, true) == "0x00AB"); + assertTrue (NumberFormatter::formatHex(0xab, 6, true, false) == "0x00ab"); assertTrue (NumberFormatter::formatHex((unsigned) 0x12, true) == "0x12"); assertTrue (NumberFormatter::formatHex((unsigned) 0xab, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((unsigned) 0xab, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((unsigned) 0x12, 4, true) == "0x12"); assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((unsigned) 0x12, 6, true) == "0x0012"); assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 6, true) == "0x00AB"); + assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 6, true, false) == "0x00ab"); assertTrue (NumberFormatter::formatHex((long) 0x12, true) == "0x12"); assertTrue (NumberFormatter::formatHex((long) 0xab, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((long) 0xab, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((long) 0x12, 4, true) == "0x12"); assertTrue (NumberFormatter::formatHex((long) 0xab, 4, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((long) 0xab, 4, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((long) 0x12, 6, true) == "0x0012"); assertTrue (NumberFormatter::formatHex((long) 0xab, 6, true) == "0x00AB"); + assertTrue (NumberFormatter::formatHex((long) 0xab, 6, true, false) == "0x00ab"); assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, true) == "0x12"); assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, 4, true) == "0x12"); assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, 6, true) == "0x0012"); assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 6, true) == "0x00AB"); + assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 6, true, false) == "0x00ab"); #if defined(POCO_HAVE_INT64) assertTrue (NumberFormatter::formatHex((Int64) 0x12, true) == "0x12"); assertTrue (NumberFormatter::formatHex((Int64) 0xab, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((Int64) 0xab, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((Int64) 0x12, 4, true) == "0x12"); assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((Int64) 0x12, 6, true) == "0x0012"); assertTrue (NumberFormatter::formatHex((Int64) 0xab, 6, true) == "0x00AB"); + assertTrue (NumberFormatter::formatHex((Int64) 0xab, 6, true, false) == "0x00ab"); assertTrue (NumberFormatter::formatHex((UInt64) 0x12, true) == "0x12"); assertTrue (NumberFormatter::formatHex((UInt64) 0xab, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((UInt64) 0xab, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((UInt64) 0x12, 4, true) == "0x12"); assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((UInt64) 0x12, 6, true) == "0x0012"); assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 6, true) == "0x00AB"); + assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 6, true, false) == "0x00ab"); #if defined(POCO_LONG_IS_64_BIT) assertTrue (NumberFormatter::formatHex((long long) 0x12, true) == "0x12"); assertTrue (NumberFormatter::formatHex((long long) 0xab, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((long long) 0xab, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((long long) 0x12, 4, true) == "0x12"); assertTrue (NumberFormatter::formatHex((long long) 0xab, 4, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((long long) 0xab, 4, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((long long) 0x12, 6, true) == "0x0012"); assertTrue (NumberFormatter::formatHex((long long) 0xab, 6, true) == "0x00AB"); + assertTrue (NumberFormatter::formatHex((long long) 0xab, 6, true, false) == "0x00ab"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0x12, true) == "0x12"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0x12, 4, true) == "0x12"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 4, true) == "0xAB"); + assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 4, true, false) == "0xab"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0x12, 6, true) == "0x0012"); assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 6, true) == "0x00AB"); + assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 6, true, false) == "0x00ab"); #endif #endif } diff --git a/Foundation/testsuite/src/StringTest.cpp b/Foundation/testsuite/src/StringTest.cpp index 6e5e003a5d..7a75e9e38c 100644 --- a/Foundation/testsuite/src/StringTest.cpp +++ b/Foundation/testsuite/src/StringTest.cpp @@ -1005,6 +1005,10 @@ void StringTest::testIntToString() assertTrue (result == "0xFFFFFFFFFFFFFFFF"); #endif + // hexadecimal with lower case + assertTrue (uIntToStr(0x1234567890ABCDEF, 0x10, result, true, -1, ' ', 0, false)); + assertTrue (result == "0x1234567890abcdef"); + try { char pResult[POCO_MAX_INT_STRING_LEN];