mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-15 07:14:46 +02:00
separate function for unsigned to string conversion
Separated unsigned integer conversion to eliminate warnings (and slightly improve performance). Added Darwin-clang warning suppression for unused functions/variables
This commit is contained in:
@@ -68,13 +68,6 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
namespace Impl {
|
||||
|
||||
static char DUMMY_EXP_UNDERFLOW = 0; // dummy default val
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline char decimalSeparator()
|
||||
/// Returns decimal separator from global locale or
|
||||
/// default '.' for platforms where locale is unavailable.
|
||||
@@ -217,6 +210,13 @@ bool strToInt(const std::string& str, I& result, short base, char thSep = ',')
|
||||
{
|
||||
return strToInt(str.c_str(), result, base, thSep);
|
||||
}
|
||||
|
||||
|
||||
namespace Impl {
|
||||
|
||||
static char DUMMY_EXP_UNDERFLOW; // dummy default val
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename F>
|
||||
@@ -451,7 +451,7 @@ namespace Impl {
|
||||
const char* _beg;
|
||||
char* _cur;
|
||||
const char* _end;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Impl
|
||||
|
||||
@@ -534,6 +534,81 @@ bool intToStr(T value,
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool uIntToStr(T value,
|
||||
unsigned short base,
|
||||
char* result,
|
||||
unsigned& size,
|
||||
bool prefix = false,
|
||||
int width = -1,
|
||||
char fill = ' ',
|
||||
char thSep = 0)
|
||||
/// 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
|
||||
/// paddings are prepended to the formatted result with minus sign or base prefix included
|
||||
/// If prefix is true and base is octal or hexadecimal, respective prefix ('0' for octal,
|
||||
/// "0x" for hexadecimal) is prepended. For all other bases, prefix argument is ignored.
|
||||
/// Formatted string has at least [width] total length.
|
||||
{
|
||||
if (base < 2 || base > 0x10)
|
||||
{
|
||||
*result = '\0';
|
||||
return false;
|
||||
}
|
||||
|
||||
Impl::Ptr ptr(result, size);
|
||||
int thCount = 0;
|
||||
T tmpVal;
|
||||
do
|
||||
{
|
||||
tmpVal = value;
|
||||
value /= base;
|
||||
*ptr++ = "FEDCBA9876543210123456789ABCDEF"[15 + (tmpVal - value * base)];
|
||||
if (thSep && (base == 10) && (++thCount == 3))
|
||||
{
|
||||
*ptr++ = thSep;
|
||||
thCount = 0;
|
||||
}
|
||||
} while (value);
|
||||
|
||||
if ('0' == fill)
|
||||
{
|
||||
if (prefix && base == 010) --width;
|
||||
if (prefix && base == 0x10) width -= 2;
|
||||
while ((ptr - result) < width) *ptr++ = fill;
|
||||
}
|
||||
|
||||
if (prefix && base == 010) *ptr++ = '0';
|
||||
else if (prefix && base == 0x10)
|
||||
{
|
||||
*ptr++ = 'x';
|
||||
*ptr++ = '0';
|
||||
}
|
||||
|
||||
if ('0' != fill)
|
||||
{
|
||||
while ((ptr - result) < width) *ptr++ = fill;
|
||||
}
|
||||
|
||||
size = ptr - result;
|
||||
poco_assert_dbg (size <= ptr.span());
|
||||
poco_assert_dbg ((-1 == width) || (size >= width));
|
||||
*ptr-- = '\0';
|
||||
|
||||
char* ptrr = result;
|
||||
char tmp;
|
||||
while(ptrr < ptr)
|
||||
{
|
||||
tmp = *ptr;
|
||||
*ptr-- = *ptrr;
|
||||
*ptrr++ = tmp;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool intToStr (T number, unsigned short base, std::string& result, bool prefix = false, int width = -1, char fill = ' ', char thSep = 0)
|
||||
/// Converts integer to string; This is a wrapper function, for details see see the
|
||||
@@ -545,6 +620,19 @@ bool intToStr (T number, unsigned short base, std::string& result, bool prefix =
|
||||
result.assign(res, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool uIntToStr (T number, unsigned short base, std::string& result, bool prefix = false, int width = -1, char fill = ' ', char thSep = 0)
|
||||
/// 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};
|
||||
unsigned size = POCO_MAX_INT_STRING_LEN;
|
||||
bool ret = uIntToStr(number, base, res, size, prefix, width, fill, thSep);
|
||||
result.assign(res, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
Reference in New Issue
Block a user