mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-02 15:41:36 +02:00
enh(NumberFormatter): Introduce backward compatible options for formatHex functions (#4333)
* enh(NumberFormatter): Introduce backward compatible options for formatHex functions. * enh(NumberFormatter): Corrections and improvements suggested in code review. * fix(ci): disable testEncryptDecryptGCM on macOS which often fails. * enh(NumberFormatter): Improved naming.
This commit is contained in:
parent
a464a4eabf
commit
111fe90dd9
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@ -215,11 +215,13 @@ jobs:
|
||||
CppUnit::TestCaller<ExpireLRUCacheTest>.testAccessExpireN,
|
||||
CppUnit::TestCaller<UniqueExpireLRUCacheTest>.testExpireN,
|
||||
CppUnit::TestCaller<ExpireLRUCacheTest>.testAccessExpireN,
|
||||
CppUnit::TestCaller<SyslogTest>.testOldBSD"
|
||||
CppUnit::TestCaller<SyslogTest>.testOldBSD,
|
||||
CppUnit::TestCaller<PollSetTest>.testPollClosedServer,
|
||||
CppUnit::TestCaller<CryptoTest>.testEncryptDecryptGCM"
|
||||
EXCLUDE_TESTS="Redis Data/MySQL Data/ODBC Data/PostgreSQL MongoDB PDF"
|
||||
./ci/runtests.sh
|
||||
|
||||
macos-clang-cmake:
|
||||
macos-clang-cmake-openssl:
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@ -240,7 +242,8 @@ jobs:
|
||||
CppUnit::TestCaller<ExpireLRUCacheTest>.testAccessExpireN,
|
||||
CppUnit::TestCaller<UniqueExpireLRUCacheTest>.testExpireN,
|
||||
CppUnit::TestCaller<ExpireLRUCacheTest>.testAccessExpireN,
|
||||
CppUnit::TestCaller<PollSetTest>.testPollClosedServer"
|
||||
CppUnit::TestCaller<PollSetTest>.testPollClosedServer,
|
||||
CppUnit::TestCaller<CryptoTest>.testEncryptDecryptGCM"
|
||||
PWD=`pwd`
|
||||
ctest --output-on-failure -E "(DataMySQL)|(DataODBC)|(PostgreSQL)|(MongoDB)|(Redis)"
|
||||
|
||||
|
@ -212,6 +212,12 @@ void CryptoTest::testEncryptDecryptDESECB()
|
||||
|
||||
void CryptoTest::testEncryptDecryptGCM()
|
||||
{
|
||||
//
|
||||
// The test sometimes fails when it is running for longer time
|
||||
// This conversation perhaps contains a hint:
|
||||
// https://github.com/openssl/openssl/issues/21119
|
||||
//
|
||||
|
||||
CipherKey key("aes-256-gcm");
|
||||
|
||||
CipherKey::ByteVec iv(20, 213);
|
||||
|
@ -43,6 +43,17 @@ public:
|
||||
FMT_ON_OFF
|
||||
};
|
||||
|
||||
enum class Options
|
||||
/// Options to control the format of the generated string.
|
||||
{
|
||||
DEFAULT = 0,
|
||||
/// formatHex defaults: No 0x prefix, uppercase hexadecimal values
|
||||
PREFIX = 1 << 0,
|
||||
/// formatHex: Prepend prefix 0x
|
||||
LOWERCASE = 1 << 1
|
||||
/// formatHex: Use lowercase letters for hexadecimal values
|
||||
};
|
||||
|
||||
static const unsigned NF_MAX_INT_STRING_LEN = 32; // increase for 64-bit binary formatting support
|
||||
static const unsigned NF_MAX_FLT_STRING_LEN = POCO_MAX_FLT_STRING_LEN;
|
||||
|
||||
@ -59,18 +70,18 @@ public:
|
||||
/// 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, Options options = Options::DEFAULT);
|
||||
/// Formats an int value in hexadecimal notation.
|
||||
/// If prefix is true, "0x" prefix is prepended to the
|
||||
/// resulting string.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
/// The value is treated as unsigned.
|
||||
|
||||
static std::string formatHex(int value, int width, bool prefix = false);
|
||||
/// Formats a int value in hexadecimal notation,
|
||||
static std::string formatHex(int value, int width, Options options = Options::DEFAULT);
|
||||
/// Formats an int 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 prepended to the
|
||||
/// resulting string.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
/// The value is treated as unsigned.
|
||||
|
||||
static std::string format(unsigned value);
|
||||
@ -86,17 +97,17 @@ public:
|
||||
/// 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, Options options = Options::DEFAULT);
|
||||
/// Formats an unsigned int value in hexadecimal notation.
|
||||
/// If prefix is true, "0x" prefix is prepended to the
|
||||
/// resulting string.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string formatHex(unsigned value, int width, bool prefix = false);
|
||||
/// Formats a int value in hexadecimal notation,
|
||||
static std::string formatHex(unsigned value, int width, Options options = Options::DEFAULT);
|
||||
/// Formats an unsigned 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 prepended to the
|
||||
/// resulting string.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string format(long value);
|
||||
/// Formats a long value in decimal notation.
|
||||
@ -111,19 +122,17 @@ public:
|
||||
/// right justified and zero-padded in a field
|
||||
/// having at least the specified width.
|
||||
|
||||
static std::string formatHex(long value, bool prefix = false);
|
||||
/// 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, Options options = Options::DEFAULT);
|
||||
/// Formats a long value in hexadecimal notation.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string formatHex(long value, int width, bool prefix = false);
|
||||
/// Formats an unsigned long 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 prepended to the
|
||||
/// resulting string.
|
||||
/// The value is treated as unsigned.
|
||||
static std::string formatHex(long value, int width, Options options = Options::DEFAULT);
|
||||
/// Formats a long value in hexadecimal notation,
|
||||
/// right justified and zero-padded in
|
||||
/// a field having at least the specified width.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string format(unsigned long value);
|
||||
/// Formats an unsigned long value in decimal notation.
|
||||
@ -138,17 +147,17 @@ public:
|
||||
/// 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, Options options = Options::DEFAULT);
|
||||
/// Formats an unsigned long value in hexadecimal notation.
|
||||
/// If prefix is true, "0x" prefix is prepended to the
|
||||
/// resulting string.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string formatHex(unsigned long value, int width, bool prefix = false);
|
||||
static std::string formatHex(unsigned long value, int width, Options options = Options::DEFAULT);
|
||||
/// Formats an unsigned long 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 prepended to the
|
||||
/// resulting string.
|
||||
/// right justified and zero-padded in
|
||||
/// a field having at least the specified width.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
#ifdef POCO_HAVE_INT64
|
||||
#ifdef POCO_INT64_IS_LONG
|
||||
@ -165,18 +174,18 @@ public:
|
||||
/// 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, Options options = Options::DEFAULT);
|
||||
/// 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.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string formatHex(long long value, int width, bool prefix = false);
|
||||
static std::string formatHex(long long value, int width, Options options = Options::DEFAULT);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
/// The value is treated as unsigned.
|
||||
/// If prefix is true, "0x" prefix is prepended to the resulting string.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string format(unsigned long long value);
|
||||
/// Formats an unsigned 64-bit integer value in decimal notation.
|
||||
@ -190,16 +199,18 @@ public:
|
||||
/// 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);
|
||||
/// 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, Options options = Options::DEFAULT);
|
||||
/// Formats an unsigned 64-bit value in hexadecimal notation.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string formatHex(unsigned long long value, int width, bool prefix = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
static std::string formatHex(unsigned long long value, int width, Options options = Options::DEFAULT);
|
||||
/// Formats an unsigned 64-bit 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
|
||||
/// prepended to the resulting string.
|
||||
/// the specified width.
|
||||
/// The value is treated as unsigned.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
#else // ifndef POCO_INT64_IS_LONG
|
||||
|
||||
@ -215,18 +226,18 @@ public:
|
||||
/// 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, Options options = Options::DEFAULT);
|
||||
/// 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.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string formatHex(Int64 value, int width, bool prefix = false);
|
||||
static std::string formatHex(Int64 value, int width, Options options = Options::DEFAULT);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
/// The value is treated as unsigned.
|
||||
/// If prefix is true, "0x" prefix is prepended to the resulting string.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string format(UInt64 value);
|
||||
/// Formats an unsigned 64-bit integer value in decimal notation.
|
||||
@ -240,16 +251,18 @@ public:
|
||||
/// right justified and zero-padded in a field having at least the
|
||||
/// specified width.
|
||||
|
||||
static std::string formatHex(UInt64 value, bool prefix = false);
|
||||
/// 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, Options options = Options::DEFAULT);
|
||||
/// Formats an unsigned 64-bit integer in hexadecimal notation.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
static std::string formatHex(UInt64 value, int width, bool prefix = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
static std::string formatHex(UInt64 value, int width, Options options = Options::DEFAULT);
|
||||
/// Formats an unsigned 64-bit integer in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width. If prefix is true, "0x" prefix is
|
||||
/// prepended to the resulting string.
|
||||
/// the specified width.
|
||||
/// The value is treated as unsigned.
|
||||
/// Options (see NumberFormatter::Options) define the format of the
|
||||
/// generated string.
|
||||
|
||||
#endif // ifdef POCO_INT64_IS_LONG
|
||||
#endif // ifdef POCO_HAVE_INT64
|
||||
@ -325,10 +338,10 @@ public:
|
||||
/// right justified and zero-padded in a field having at
|
||||
/// least the specified width.
|
||||
|
||||
static void appendHex(std::string& str, unsigned value);
|
||||
static void appendHex(std::string& str, unsigned value, bool lowercase = false);
|
||||
/// Formats an unsigned int value in hexadecimal notation.
|
||||
|
||||
static void appendHex(std::string& str, unsigned value, int width);
|
||||
static void appendHex(std::string& str, unsigned value, int width, bool lowercase = false);
|
||||
/// Formats a int value in hexadecimal notation,
|
||||
/// right justified and zero-padded in
|
||||
/// a field having at least the specified width.
|
||||
@ -346,11 +359,11 @@ public:
|
||||
/// right justified and zero-padded in a field
|
||||
/// having at least the specified width.
|
||||
|
||||
static void appendHex(std::string& str, long value);
|
||||
static void appendHex(std::string& str, long value, bool lowercase = false);
|
||||
/// Formats an unsigned long value in hexadecimal notation.
|
||||
/// The value is treated as unsigned.
|
||||
|
||||
static void appendHex(std::string& str, long value, int width);
|
||||
static void appendHex(std::string& str, long value, int width, bool lowercase = false);
|
||||
/// Formats an unsigned long value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least the
|
||||
/// specified width.
|
||||
@ -369,10 +382,10 @@ public:
|
||||
/// right justified and zero-padded
|
||||
/// in a field having at least the specified width.
|
||||
|
||||
static void appendHex(std::string& str, unsigned long value);
|
||||
static void appendHex(std::string& str, unsigned long value, bool lowercase = false);
|
||||
/// Formats an unsigned long value in hexadecimal notation.
|
||||
|
||||
static void appendHex(std::string& str, unsigned long value, int width);
|
||||
static void appendHex(std::string& str, unsigned long value, int width, bool lowercase = false);
|
||||
/// Formats an unsigned long value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least the
|
||||
/// specified width.
|
||||
@ -392,11 +405,11 @@ public:
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
|
||||
static void appendHex(std::string& str, long long value);
|
||||
static void appendHex(std::string& str, long long value, bool lowercase = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation.
|
||||
/// The value is treated as unsigned.
|
||||
|
||||
static void appendHex(std::string& str, long long value, int width);
|
||||
static void appendHex(std::string& str, long long value, int width, bool lowercase = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
@ -414,10 +427,10 @@ public:
|
||||
/// right justified and zero-padded in a field having at least the
|
||||
/// specified width.
|
||||
|
||||
static void appendHex(std::string& str, unsigned long long value);
|
||||
static void appendHex(std::string& str, unsigned long long value, bool lowercase = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation.
|
||||
|
||||
static void appendHex(std::string& str, unsigned long long value, int width);
|
||||
static void appendHex(std::string& str, unsigned long long value, int width, bool lowercase = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
@ -436,11 +449,11 @@ public:
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
|
||||
static void appendHex(std::string& str, Int64 value);
|
||||
static void appendHex(std::string& str, Int64 value, bool lowercase = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation.
|
||||
/// The value is treated as unsigned.
|
||||
|
||||
static void appendHex(std::string& str, Int64 value, int width);
|
||||
static void appendHex(std::string& str, Int64 value, int width, bool lowercase = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
@ -458,10 +471,10 @@ public:
|
||||
/// right justified and zero-padded in a field having at least the
|
||||
/// specified width.
|
||||
|
||||
static void appendHex(std::string& str, UInt64 value);
|
||||
static void appendHex(std::string& str, UInt64 value, bool lowercase = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation.
|
||||
|
||||
static void appendHex(std::string& str, UInt64 value, int width);
|
||||
static void appendHex(std::string& str, UInt64 value, int width, bool lowercase = false);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
@ -500,7 +513,137 @@ public:
|
||||
/// sixteen (64-bit architectures) characters wide
|
||||
/// field in hexadecimal notation.
|
||||
|
||||
//
|
||||
// Deprecated functions
|
||||
//
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(int value, bool prefix);
|
||||
/// 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.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(int value, int width, bool prefix);
|
||||
/// Formats an int 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 prepended to the
|
||||
/// resulting string.
|
||||
/// The value is treated as unsigned.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(unsigned value, bool prefix);
|
||||
/// Formats an unsigned int value in hexadecimal notation.
|
||||
/// If prefix is true, "0x" prefix is prepended to the
|
||||
/// resulting string.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(unsigned value, int width, bool prefix);
|
||||
/// Formats an unsigned 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 prepended to the
|
||||
/// resulting string.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(long value, bool prefix);
|
||||
/// Formats a long value in hexadecimal notation.
|
||||
/// If prefix is true, "0x" prefix is prepended to the
|
||||
/// resulting string.
|
||||
/// The value is treated as unsigned.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(long value, int width, bool prefix);
|
||||
/// Formats a long 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 prepended to the
|
||||
/// resulting string.
|
||||
/// The value is treated as unsigned.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(unsigned long value, bool prefix);
|
||||
/// Formats an unsigned long value in hexadecimal notation.
|
||||
/// If prefix is true, "0x" prefix is prepended to the
|
||||
/// resulting string.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(unsigned long value, int width, bool prefix);
|
||||
/// Formats an unsigned long 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 prepended to the
|
||||
/// resulting string.
|
||||
|
||||
#ifdef POCO_HAVE_INT64
|
||||
#ifdef POCO_INT64_IS_LONG
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(long long value, bool prefix);
|
||||
/// 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.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(long long value, int width, bool prefix);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
/// The value is treated as unsigned.
|
||||
/// If prefix is true, "0x" prefix is prepended to the resulting string.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(unsigned long long value, bool prefix);
|
||||
/// Formats an unsigned 64-bit integer value in hexadecimal notation.
|
||||
/// If prefix is true, "0x" prefix is prepended to the
|
||||
/// resulting string.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(unsigned long long value, int width, bool prefix);
|
||||
/// Formats an unsigned 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
|
||||
/// prepended to the resulting string.
|
||||
|
||||
#else // ifndef POCO_INT64_IS_LONG
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(Int64 value, bool prefix);
|
||||
/// 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.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(Int64 value, int width, bool prefix);
|
||||
/// Formats a 64-bit integer value in hexadecimal notation,
|
||||
/// right justified and zero-padded in a field having at least
|
||||
/// the specified width.
|
||||
/// The value is treated as unsigned.
|
||||
/// If prefix is true, "0x" prefix is prepended to the resulting string.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(UInt64 value, bool prefix);
|
||||
/// Formats an unsigned 64-bit integer value in hexadecimal notation.
|
||||
/// If prefix is true, "0x" prefix is prepended to the
|
||||
/// resulting string.
|
||||
|
||||
[[deprecated("use formatHex with options instead")]]
|
||||
static std::string formatHex(UInt64 value, int width, bool prefix);
|
||||
/// Formats an unsigned 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
|
||||
/// prepended to the resulting string.
|
||||
|
||||
#endif // ifdef POCO_INT64_IS_LONG
|
||||
#endif // ifdef POCO_HAVE_INT64
|
||||
|
||||
private:
|
||||
|
||||
static bool isEnabled(NumberFormatter::Options options, NumberFormatter::Options opt);
|
||||
};
|
||||
|
||||
|
||||
@ -508,6 +651,42 @@ private:
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline NumberFormatter::Options operator | (NumberFormatter::Options lhs, NumberFormatter::Options rhs)
|
||||
{
|
||||
using T = std::underlying_type_t<NumberFormatter::Options>;
|
||||
return static_cast<NumberFormatter::Options>(static_cast<T>(lhs) | static_cast<T>(rhs));
|
||||
}
|
||||
|
||||
|
||||
inline NumberFormatter::Options& operator |= (NumberFormatter::Options& lhs, NumberFormatter::Options rhs)
|
||||
{
|
||||
lhs = lhs | rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
|
||||
inline NumberFormatter::Options operator & (NumberFormatter::Options lhs, NumberFormatter::Options rhs)
|
||||
{
|
||||
using T = std::underlying_type_t<NumberFormatter::Options>;
|
||||
return static_cast<NumberFormatter::Options>(static_cast<T>(lhs) & static_cast<T>(rhs));
|
||||
}
|
||||
|
||||
|
||||
inline NumberFormatter::Options& operator &= (NumberFormatter::Options& lhs, NumberFormatter::Options rhs)
|
||||
{
|
||||
lhs = lhs & rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
|
||||
inline bool NumberFormatter::isEnabled(Options options, Options opt)
|
||||
{
|
||||
using T = std::underlying_type_t<Options>;
|
||||
return static_cast<T>(options & opt) != 0;
|
||||
}
|
||||
|
||||
|
||||
inline std::string NumberFormatter::format(int value)
|
||||
{
|
||||
std::string result;
|
||||
@ -532,19 +711,15 @@ 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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(static_cast<unsigned int>(value), 0x10, result, prefix);
|
||||
return result;
|
||||
return formatHex(static_cast<unsigned int>(value), options);
|
||||
}
|
||||
|
||||
|
||||
inline std::string NumberFormatter::formatHex(int value, int width, bool prefix)
|
||||
inline std::string NumberFormatter::formatHex(int value, int width, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(static_cast<unsigned int>(value), 0x10, result, prefix, width, '0');
|
||||
return result;
|
||||
return formatHex(static_cast<unsigned int>(value), width, options);
|
||||
}
|
||||
|
||||
|
||||
@ -572,18 +747,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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(value, 0x10, result, prefix);
|
||||
intToStr(value, 0x10, result, isEnabled(options, Options::PREFIX),-1, ' ', 0, isEnabled(options, Options::LOWERCASE));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline std::string NumberFormatter::formatHex(unsigned value, int width, bool prefix)
|
||||
inline std::string NumberFormatter::formatHex(unsigned value, int width, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(value, 0x10, result, prefix, width, '0');
|
||||
intToStr(value, 0x10, result, isEnabled(options, Options::PREFIX), width, '0', 0, isEnabled(options, Options::LOWERCASE));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -612,19 +787,15 @@ 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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(static_cast<unsigned long>(value), 0x10, result, prefix);
|
||||
return result;
|
||||
return formatHex(static_cast<unsigned long>(value), options);
|
||||
}
|
||||
|
||||
|
||||
inline std::string NumberFormatter::formatHex(long value, int width, bool prefix)
|
||||
inline std::string NumberFormatter::formatHex(long value, int width, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(static_cast<unsigned long>(value), 0x10, result, prefix, width, '0');
|
||||
return result;
|
||||
return formatHex(static_cast<unsigned long>(value), width, options);
|
||||
}
|
||||
|
||||
|
||||
@ -652,22 +823,21 @@ 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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(value, 0x10, result, prefix);
|
||||
intToStr(value, 0x10, result, isEnabled(options, Options::PREFIX), -1, ' ', 0, isEnabled(options, Options::LOWERCASE));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline std::string NumberFormatter::formatHex(unsigned long value, int width, bool prefix)
|
||||
inline std::string NumberFormatter::formatHex(unsigned long value, int width, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(value, 0x10, result, prefix, width, '0');
|
||||
intToStr(value, 0x10, result, isEnabled(options, Options::PREFIX), width, '0', 0, isEnabled(options, Options::LOWERCASE));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#ifdef POCO_HAVE_INT64
|
||||
#ifdef POCO_INT64_IS_LONG
|
||||
|
||||
@ -696,19 +866,15 @@ 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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(static_cast<unsigned long long>(value), 0x10, result, prefix);
|
||||
return result;
|
||||
return formatHex(static_cast<unsigned long long>(value), options);
|
||||
}
|
||||
|
||||
|
||||
inline std::string NumberFormatter::formatHex(long long value, int width, bool prefix)
|
||||
inline std::string NumberFormatter::formatHex(long long value, int width, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(static_cast<unsigned long long>(value), 0x10, result, prefix, width, '0');
|
||||
return result;
|
||||
return formatHex(static_cast<unsigned long long>(value), width, options);
|
||||
}
|
||||
|
||||
|
||||
@ -736,18 +902,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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(value, 0x10, result, prefix);
|
||||
intToStr(value, 0x10, result, isEnabled(options, Options::PREFIX), -1, ' ', 0, isEnabled(options, Options::LOWERCASE));
|
||||
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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(value, 0x10, result, prefix, width, '0');
|
||||
intToStr(value, 0x10, result, isEnabled(options, Options::PREFIX), width, '0', 0, isEnabled(options, Options::LOWERCASE));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -779,19 +945,15 @@ 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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(static_cast<UInt64>(value), 0x10, result, prefix);
|
||||
return result;
|
||||
return formatHex(static_cast<UInt64>(value), options);
|
||||
}
|
||||
|
||||
|
||||
inline std::string NumberFormatter::formatHex(Int64 value, int width, bool prefix)
|
||||
inline std::string NumberFormatter::formatHex(long long value, int width, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(static_cast<UInt64>(value), 0x10, result, prefix, width, '0');
|
||||
return result;
|
||||
return formatHex(static_cast<UInt64>(value), width, options);
|
||||
}
|
||||
|
||||
|
||||
@ -819,18 +981,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, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(value, 0x10, result, prefix);
|
||||
intToStr(value, 0x10, result, isEnabled(options, Options::PREFIX), -1, ' ', 0, isEnabled(options, Options::LOWERCASE));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline std::string NumberFormatter::formatHex(UInt64 value, int width, bool prefix)
|
||||
inline std::string NumberFormatter::formatHex(UInt64 value, int width, Options options)
|
||||
{
|
||||
std::string result;
|
||||
intToStr(value, 0x10, result, prefix, width, '0');
|
||||
intToStr(value, 0x10, result, isEnabled(options, Options::PREFIX), width, '0', 0, isEnabled(options, Options::LOWERCASE));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,8 @@ typedef Poco::Int64 intmax_t;
|
||||
#pragma warning(disable : 4146)
|
||||
#endif // POCO_COMPILER_MSVC
|
||||
|
||||
// binary numbers are supported, thus 64 (bits) + 1 (string terminating zero)
|
||||
#define POCO_MAX_INT_STRING_LEN 65
|
||||
// binary numbers are supported, thus 64 (bits) + 1 (string terminating zero) + 2 (hex prefix)
|
||||
#define POCO_MAX_INT_STRING_LEN (67)
|
||||
// value from strtod.cc (double_conversion::kMaxSignificantDecimalDigits)
|
||||
#define POCO_MAX_FLT_STRING_LEN 780
|
||||
|
||||
|
@ -128,20 +128,20 @@ void NumberFormatter::append0(std::string& str, unsigned int value, int width)
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned value)
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned value, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(value, 0x10, result, sz);
|
||||
intToStr(value, 0x10, result, sz, false, -1, ' ', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned value, int width)
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned value, int width, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(value, 0x10, result, sz, false, width, '0');
|
||||
intToStr(value, 0x10, result, sz, false, width, '0', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
@ -173,20 +173,20 @@ void NumberFormatter::append0(std::string& str, long value, int width)
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, long value)
|
||||
void NumberFormatter::appendHex(std::string& str, long value, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(static_cast<unsigned long>(value), 0x10, result, sz);
|
||||
intToStr(static_cast<unsigned long>(value), 0x10, result, sz, false, -1, ' ', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, long value, int width)
|
||||
void NumberFormatter::appendHex(std::string& str, long value, int width, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(static_cast<unsigned long>(value), 0x10, result, sz, false, width, '0');
|
||||
intToStr(static_cast<unsigned long>(value), 0x10, result, sz, false, width, '0', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
@ -218,20 +218,20 @@ void NumberFormatter::append0(std::string& str, unsigned long value, int width)
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned long value)
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned long value, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(value, 0x10, result, sz);
|
||||
intToStr(value, 0x10, result, sz, false, -1, ' ', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned long value, int width)
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned long value, int width, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(value, 0x10, result, sz, false, width, '0');
|
||||
intToStr(value, 0x10, result, sz, false, width, '0', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
@ -267,20 +267,20 @@ void NumberFormatter::append0(std::string& str, long long value, int width)
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, long long value)
|
||||
void NumberFormatter::appendHex(std::string& str, long long value, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(static_cast<unsigned long long>(value), 0x10, result, sz);
|
||||
intToStr(static_cast<unsigned long long>(value), 0x10, result, sz, false, -1, ' ', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, long long value, int width)
|
||||
void NumberFormatter::appendHex(std::string& str, long long value, int width, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(static_cast<unsigned long long>(value), 0x10, result, sz, false, width, '0');
|
||||
intToStr(static_cast<unsigned long long>(value), 0x10, result, sz, false, width, '0', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
@ -312,20 +312,20 @@ void NumberFormatter::append0(std::string& str, unsigned long long value, int wi
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned long long value)
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned long long value, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(value, 0x10, result, sz);
|
||||
intToStr(value, 0x10, result, sz, false, -1, ' ', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned long long value, int width)
|
||||
void NumberFormatter::appendHex(std::string& str, unsigned long long value, int width, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(value, 0x10, result, sz, false, width, '0');
|
||||
intToStr(value, 0x10, result, sz, false, width, '0', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
@ -360,20 +360,20 @@ void NumberFormatter::append0(std::string& str, Int64 value, int width)
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, Int64 value)
|
||||
void NumberFormatter::appendHex(std::string& str, Int64 value, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(static_cast<UInt64>(value), 0x10, result, sz);
|
||||
intToStr(static_cast<UInt64>(value), 0x10, result, sz, false, -1, ' ', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, Int64 value, int width)
|
||||
void NumberFormatter::appendHex(std::string& str, Int64 value, int width, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(static_cast<UInt64>(value), 0x10, result, sz, false, width, '0');
|
||||
intToStr(static_cast<UInt64>(value), 0x10, result, sz, false, width, '0', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
@ -405,20 +405,20 @@ void NumberFormatter::append0(std::string& str, UInt64 value, int width)
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, UInt64 value)
|
||||
void NumberFormatter::appendHex(std::string& str, UInt64 value, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(value, 0x10, result, sz);
|
||||
intToStr(value, 0x10, result, sz, false, -1, ' ', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::appendHex(std::string& str, UInt64 value, int width)
|
||||
void NumberFormatter::appendHex(std::string& str, UInt64 value, int width, bool lowercase)
|
||||
{
|
||||
char result[NF_MAX_INT_STRING_LEN];
|
||||
std::size_t sz = NF_MAX_INT_STRING_LEN;
|
||||
intToStr(value, 0x10, result, sz, false, width, '0');
|
||||
intToStr(value, 0x10, result, sz, false, width, '0', 0, lowercase);
|
||||
str.append(result, sz);
|
||||
}
|
||||
|
||||
@ -485,4 +485,116 @@ void NumberFormatter::append(std::string& str, const void* ptr)
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Deprecated functions
|
||||
//
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(int value, bool prefix)
|
||||
{
|
||||
return formatHex(static_cast<unsigned int>(value), prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(int value, int width, bool prefix)
|
||||
{
|
||||
return formatHex(static_cast<unsigned int>(value), width, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(unsigned value, bool prefix)
|
||||
{
|
||||
return formatHex(value, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(unsigned value, int width, bool prefix)
|
||||
{
|
||||
return formatHex(value, width, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(long value, bool prefix)
|
||||
{
|
||||
return formatHex(static_cast<unsigned long>(value), prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(long value, int width, bool prefix)
|
||||
{
|
||||
return formatHex(static_cast<unsigned long>(value), width, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(unsigned long value, bool prefix)
|
||||
{
|
||||
return formatHex(value, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(unsigned long value, int width, bool prefix)
|
||||
{
|
||||
return formatHex(value, width, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
#ifdef POCO_HAVE_INT64
|
||||
#ifdef POCO_INT64_IS_LONG
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(long long value, bool prefix)
|
||||
{
|
||||
return formatHex(static_cast<unsigned long long>(value), prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(long long value, int width, bool prefix)
|
||||
{
|
||||
return formatHex(static_cast<unsigned long long>(value), width, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(unsigned long long value, bool prefix)
|
||||
{
|
||||
return formatHex(value, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(unsigned long long value, int width, bool prefix)
|
||||
{
|
||||
return formatHex(value, width, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
#else // ifndef POCO_LONG_IS_64_BIT
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(Int64 value, bool prefix)
|
||||
{
|
||||
return formatHex(static_cast<UInt64>(value), prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(Int64 value, int width, bool prefix)
|
||||
{
|
||||
return formatHex(static_cast<UInt64>(value), width, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(UInt64 value, bool prefix)
|
||||
{
|
||||
return formatHex(value, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
std::string NumberFormatter::formatHex(UInt64 value, int width, bool prefix)
|
||||
{
|
||||
return formatHex(value, width, prefix ? Options::PREFIX : Options::DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
#endif // ifdef POCO_INT64_IS_LONG
|
||||
#endif // ifdef POCO_HAVE_INT64
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
@ -113,105 +113,156 @@ void NumberFormatterTest::testFormatBool()
|
||||
|
||||
void NumberFormatterTest::testFormatHex()
|
||||
{
|
||||
using Opt = NumberFormatter::Options;
|
||||
|
||||
assertTrue (NumberFormatter::formatHex(0x12) == "12");
|
||||
assertTrue (NumberFormatter::formatHex(0xab) == "AB");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, Opt::LOWERCASE) == "ab");
|
||||
assertTrue (NumberFormatter::formatHex(0x12, 4) == "0012");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, 4) == "00AB");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, 4, Opt::LOWERCASE) == "00ab");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0x12) == "12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab) == "AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, Opt::LOWERCASE) == "ab");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0x12, 4) == "0012");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4) == "00AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4, Opt::LOWERCASE) == "00ab");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex((long) 0x12) == "12");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab) == "AB");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, Opt::LOWERCASE) == "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, Opt::LOWERCASE) == "ab");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, 4) == "0012");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4) == "00AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4, Opt::LOWERCASE) == "00ab");
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0x12) == "12");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab) == "AB");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, Opt::LOWERCASE) == "ab");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0x12, 4) == "0012");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4) == "00AB");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4, Opt::LOWERCASE) == "00ab");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0x12) == "12");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab) == "AB");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, Opt::LOWERCASE) == "ab");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0x12, 4) == "0012");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4) == "00AB");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4, Opt::LOWERCASE) == "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, Opt::LOWERCASE) == "ab");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0x12, 4) == "0012");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, 4) == "00AB");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, 4, Opt::LOWERCASE) == "00ab");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0x12) == "12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab) == "AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, Opt::LOWERCASE) == "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, Opt::LOWERCASE) == "00ab");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Deprecated function
|
||||
assertTrue (NumberFormatter::formatHex(0x12, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex(0x12, 4, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, 4, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex(0x12, 6, true) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, 6, true) == "0x00AB");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex(0x12, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex(0x12, 4, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, 4, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, 4, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex(0x12, 6, Opt::PREFIX) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, 6, Opt::PREFIX) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex(0xab, 6, Opt::PREFIX | Opt::LOWERCASE) == "0x00ab");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0x12, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0x12, 4, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0x12, 6, true) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 6, true) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0x12, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0x12, 4, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 4, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0x12, 6, Opt::PREFIX) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 6, Opt::PREFIX) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned) 0xab, 6, Opt::PREFIX | Opt::LOWERCASE) == "0x00ab");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex((long) 0x12, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0x12, 4, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, 4, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0x12, 6, true) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, 6, true) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0x12, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0x12, 4, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, 4, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, 4, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0x12, 6, Opt::PREFIX) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, 6, Opt::PREFIX) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((long) 0xab, 6, Opt::PREFIX | Opt::LOWERCASE) == "0x00ab");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, 4, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, 6, true) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 6, true) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, 4, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 4, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0x12, 6, Opt::PREFIX) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 6, Opt::PREFIX) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long) 0xab, 6, Opt::PREFIX | Opt::LOWERCASE) == "0x00ab");
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0x12, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0x12, 4, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0x12, 6, true) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, 6, true) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0x12, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0x12, 4, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, 4, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0x12, 6, Opt::PREFIX) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, 6, Opt::PREFIX) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((Int64) 0xab, 6, Opt::PREFIX | Opt::LOWERCASE) == "0x00ab");
|
||||
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0x12, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0x12, 4, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0x12, 6, true) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 6, true) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0x12, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0x12, 4, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 4, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0x12, 6, Opt::PREFIX) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 6, Opt::PREFIX) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((UInt64) 0xab, 6, Opt::PREFIX | Opt::LOWERCASE) == "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) 0x12, 4, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, 4, true) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0x12, 6, true) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, 6, true) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0x12, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0x12, 4, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, 4, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, 4, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0x12, 6, Opt::PREFIX) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, 6, Opt::PREFIX) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((long long) 0xab, 6, Opt::PREFIX | Opt::LOWERCASE) == "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) 0x12, 4, true) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 4, true) == "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) 0x12, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0x12, 4, Opt::PREFIX) == "0x12");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 4, Opt::PREFIX) == "0xAB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 4, Opt::PREFIX | Opt::LOWERCASE) == "0xab");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0x12, 6, Opt::PREFIX) == "0x0012");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 6, Opt::PREFIX) == "0x00AB");
|
||||
assertTrue (NumberFormatter::formatHex((unsigned long long) 0xab, 6, Opt::PREFIX | Opt::LOWERCASE) == "0x00ab");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user