mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Final unit tests for all string types.
This commit is contained in:
parent
11da8e133f
commit
9ef75bd89e
1
.vs/.gitignore
vendored
Normal file
1
.vs/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/slnx.sqlite
|
||||
3
.vs/ProjectSettings.json
Normal file
3
.vs/ProjectSettings.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"CurrentProjectSetting": "x86-Debug"
|
||||
}
|
||||
17
CMakeSettings.json
Normal file
17
CMakeSettings.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "x86-Debug",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Debug",
|
||||
"inheritEnvironments": [
|
||||
"msvc_x86"
|
||||
],
|
||||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
|
||||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -55,8 +55,10 @@ namespace etl
|
||||
basic_format_spec()
|
||||
: base_(10)
|
||||
, width_(0)
|
||||
, precision_(0)
|
||||
, upper_case_(true)
|
||||
, left_justified_(false)
|
||||
, boolalpha_(false)
|
||||
, fill_(typename TString::value_type(' '))
|
||||
{
|
||||
|
||||
@ -111,10 +113,11 @@ namespace etl
|
||||
base(16);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the base.
|
||||
//***************************************************************************
|
||||
uint32_t base() const
|
||||
uint32_t get_base() const
|
||||
{
|
||||
return base_;
|
||||
}
|
||||
@ -132,11 +135,29 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Gets the width.
|
||||
//***************************************************************************
|
||||
uint32_t width() const
|
||||
uint32_t get_width() const
|
||||
{
|
||||
return width_;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the precision.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
basic_format_spec& precision(const uint32_t w)
|
||||
{
|
||||
precision_ = static_cast<uint_least8_t>(w);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the precision.
|
||||
//***************************************************************************
|
||||
uint32_t get_precision() const
|
||||
{
|
||||
return precision_;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the upper case flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
@ -150,7 +171,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Gets the upper case flag.
|
||||
//***************************************************************************
|
||||
bool upper_case() const
|
||||
bool is_upper_case() const
|
||||
{
|
||||
return upper_case_;
|
||||
}
|
||||
@ -168,7 +189,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Gets the fill character.
|
||||
//***************************************************************************
|
||||
typename TString::value_type fill() const
|
||||
typename TString::value_type get_fill() const
|
||||
{
|
||||
return fill_;
|
||||
}
|
||||
@ -177,26 +198,64 @@ namespace etl
|
||||
/// Sets the left justify flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
basic_format_spec& left_justified(const bool l)
|
||||
basic_format_spec& left()
|
||||
{
|
||||
left_justified_ = l;
|
||||
left_justified_ = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the left justify flag.
|
||||
//***************************************************************************
|
||||
bool left_justified() const
|
||||
bool is_left() const
|
||||
{
|
||||
return left_justified_;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the right justify flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
basic_format_spec& right()
|
||||
{
|
||||
left_justified_ = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the right justify flag.
|
||||
//***************************************************************************
|
||||
bool is_right() const
|
||||
{
|
||||
return !left_justified_;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the bool alpha flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
basic_format_spec& boolalpha(bool b)
|
||||
{
|
||||
boolalpha_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the boolalpha flag.
|
||||
//***************************************************************************
|
||||
bool is_boolalpha() const
|
||||
{
|
||||
return boolalpha_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
uint_least8_t base_;
|
||||
uint_least8_t width_;
|
||||
uint_least8_t precision_;
|
||||
bool upper_case_;
|
||||
bool left_justified_;
|
||||
bool boolalpha_;
|
||||
typename TString::value_type fill_;
|
||||
};
|
||||
}
|
||||
|
||||
@ -33,87 +33,461 @@ SOFTWARE.
|
||||
|
||||
///\ingroup private
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../platform.h"
|
||||
#include "../absolute.h"
|
||||
#include "../negative.h"
|
||||
#include "../basic_format_spec.h"
|
||||
#include "../type_traits.h"
|
||||
#include "../container.h"
|
||||
|
||||
#include "../stl/algorithm.h"
|
||||
#include "../stl/iterator.h"
|
||||
#include "../stl/limits.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// Helper function for integrals.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value, TIString&>::type
|
||||
to_string_helper(T value,
|
||||
TIString& str,
|
||||
const etl::basic_format_spec<TIString>& format,
|
||||
const bool append)
|
||||
namespace private_to_string
|
||||
{
|
||||
typedef typename TIString::value_type type;
|
||||
typedef typename TIString::iterator iterator;
|
||||
|
||||
const bool negative = etl::is_negative(value);
|
||||
|
||||
if (!append)
|
||||
//***************************************************************************
|
||||
/// Helper function for left/right alignment.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void add_alignment(TIString& str, typename TIString::iterator position, const etl::basic_format_spec<TIString>& format)
|
||||
{
|
||||
str.clear();
|
||||
}
|
||||
uint32_t length = static_cast<uint32_t>(std::distance(position, str.end()));
|
||||
|
||||
iterator start = str.end();
|
||||
|
||||
if (value == 0)
|
||||
{
|
||||
str.push_back(type('0'));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Extract the digits, in reverse order.
|
||||
while (value != 0)
|
||||
if (length < format.get_width())
|
||||
{
|
||||
T remainder = etl::absolute(value % T(format.base()));
|
||||
str.push_back((remainder > 9) ? (format.upper_case() ? type('A' + (remainder - 10)) : type('a' + (remainder - 10))) : type('0' + remainder));
|
||||
value = value / T(format.base());
|
||||
}
|
||||
uint32_t fill_length = format.get_width() - length;
|
||||
|
||||
// If number is negative, append '-'
|
||||
if ((format.base() == 10) && negative)
|
||||
{
|
||||
str.push_back(type('-'));
|
||||
}
|
||||
|
||||
// Reverse the string we appended.
|
||||
std::reverse(start, str.end());
|
||||
}
|
||||
|
||||
// Do we have a width specification?
|
||||
if (format.width() != 0)
|
||||
{
|
||||
uint32_t length = static_cast<uint32_t>(std::distance(start, str.end()));
|
||||
|
||||
// Is the length of the string less than the width?
|
||||
if (length < format.width())
|
||||
{
|
||||
uint32_t fill_length = format.width() - length;
|
||||
|
||||
if (format.left_justified())
|
||||
if (format.is_left())
|
||||
{
|
||||
// Insert fill characters on the right.
|
||||
str.insert(str.end(), fill_length, format.fill());
|
||||
str.insert(str.end(), fill_length, format.get_fill());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Insert fill characters on the left.
|
||||
str.insert(start, fill_length, format.fill());
|
||||
str.insert(position, fill_length, format.get_fill());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
//***************************************************************************
|
||||
/// Helper function for booleans.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void add_boolean(const bool value,
|
||||
TIString& str,
|
||||
const etl::basic_format_spec<TIString>& format,
|
||||
const bool append)
|
||||
{
|
||||
typedef typename TIString::value_type type;
|
||||
typedef typename TIString::iterator iterator;
|
||||
|
||||
static const type t[] = { 't', 'r', 'u', 'e' };
|
||||
static const type f[] = { 'f', 'a', 'l', 's', 'e' };
|
||||
|
||||
if (!append)
|
||||
{
|
||||
str.clear();
|
||||
}
|
||||
|
||||
iterator start = str.end();
|
||||
|
||||
if (format.is_boolalpha())
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
str.insert(str.end(), etl::begin(t), etl::end(t));
|
||||
}
|
||||
else
|
||||
{
|
||||
str.insert(str.end(), etl::begin(f), etl::end(f));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
str.push_back(type('1'));
|
||||
}
|
||||
else
|
||||
{
|
||||
str.push_back(type('0'));
|
||||
}
|
||||
}
|
||||
|
||||
etl::private_to_string::add_alignment(str, start, format);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Helper function for integrals.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
void add_integral(T value,
|
||||
TIString& str,
|
||||
const etl::basic_format_spec<TIString>& format,
|
||||
const bool append)
|
||||
{
|
||||
typedef typename TIString::value_type type;
|
||||
typedef typename TIString::iterator iterator;
|
||||
|
||||
const bool negative = etl::is_negative(value);
|
||||
|
||||
if (!append)
|
||||
{
|
||||
str.clear();
|
||||
}
|
||||
|
||||
iterator start = str.end();
|
||||
|
||||
if (value == 0)
|
||||
{
|
||||
str.push_back(type('0'));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Extract the digits, in reverse order.
|
||||
while (value != 0)
|
||||
{
|
||||
T remainder = etl::absolute(value % T(format.get_base()));
|
||||
str.push_back((remainder > 9) ? (format.is_upper_case() ? type('A' + (remainder - 10)) : type('a' + (remainder - 10))) : type('0' + remainder));
|
||||
value = value / T(format.get_base());
|
||||
}
|
||||
|
||||
// If number is negative, append '-'
|
||||
if ((format.get_base() == 10) && negative)
|
||||
{
|
||||
str.push_back(type('-'));
|
||||
}
|
||||
|
||||
// Reverse the string we appended.
|
||||
std::reverse(start, str.end());
|
||||
}
|
||||
|
||||
etl::private_to_string::add_alignment(str, start, format);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Helper function for floating point nan and inf.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void add_nan_inf(const bool not_a_number,
|
||||
const bool infinity,
|
||||
TIString& str)
|
||||
{
|
||||
typedef typename TIString::value_type type;
|
||||
|
||||
static const type n[] = { 'n', 'a', 'n' };
|
||||
static const type i[] = { 'i', 'n', 'f' };
|
||||
|
||||
if (not_a_number)
|
||||
{
|
||||
str.insert(str.end(), etl::begin(n), etl::end(n));
|
||||
}
|
||||
else if (infinity)
|
||||
{
|
||||
str.insert(str.end(), etl::begin(i), etl::end(i));
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Helper function for floating point integral and fractional.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void add_integral_fractional(const int64_t integral,
|
||||
const int64_t fractional,
|
||||
TIString& str,
|
||||
const etl::basic_format_spec<TIString>& format)
|
||||
{
|
||||
typedef typename TIString::value_type type;
|
||||
|
||||
etl::private_to_string::add_integral(integral, str, format, true);
|
||||
|
||||
if (format.get_precision() > 0)
|
||||
{
|
||||
str.push_back(type('.'));
|
||||
etl::private_to_string::add_integral(fractional, str, format, true);
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Helper function for floating point.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
void add_floating_point(T value,
|
||||
TIString& str,
|
||||
const etl::basic_format_spec<TIString>& format,
|
||||
const bool append)
|
||||
{
|
||||
typedef typename TIString::iterator iterator;
|
||||
|
||||
if (!append)
|
||||
{
|
||||
str.clear();
|
||||
}
|
||||
|
||||
iterator start = str.end();
|
||||
|
||||
if (isnan(value) || isinf(value))
|
||||
{
|
||||
etl::private_to_string::add_nan_inf(isnan(value), isinf(value), str);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make sure we format the two halves correctly.
|
||||
uint32_t max_precision = std::numeric_limits<T>::digits10;
|
||||
|
||||
etl::basic_format_spec<TIString> local_format = format;
|
||||
local_format.decimal().width(0).precision(format.get_precision() > max_precision ? max_precision : format.get_precision());
|
||||
|
||||
int64_t multiplier = 1;
|
||||
|
||||
for (uint32_t i = 0; i < local_format.get_precision(); ++i)
|
||||
{
|
||||
multiplier *= 10U;
|
||||
}
|
||||
|
||||
T f_integral = (value < T(0.0) ? ceil(value) : floor(value));
|
||||
int64_t integral = static_cast<int64_t>(f_integral);
|
||||
int64_t fractional = static_cast<int64_t>(round((value - f_integral) * multiplier));
|
||||
|
||||
etl::private_to_string::add_integral_fractional(integral, fractional, str, local_format);
|
||||
}
|
||||
|
||||
etl::private_to_string::add_alignment(str, start, format);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Helper function for pointers.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void add_pointer(const volatile void* value,
|
||||
TIString& str,
|
||||
const etl::basic_format_spec<TIString>& format,
|
||||
const bool append)
|
||||
{
|
||||
uintptr_t p = reinterpret_cast<uintptr_t>(value);
|
||||
|
||||
return etl::private_to_string::add_integral(p, str, format, append);
|
||||
}
|
||||
|
||||
//*********************************************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
/// For booleans. Default format spec.
|
||||
//***************************************************************************etl::basic_format_spec<TIString>
|
||||
template <typename TIString>
|
||||
const TIString& to_string(const bool value,
|
||||
TIString& str,
|
||||
const bool append = false)
|
||||
{
|
||||
etl::basic_format_spec<TIString> format;
|
||||
|
||||
etl::private_to_string::add_boolean(value, str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For booleans. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
const TIString& to_string(const bool value,
|
||||
TIString& str,
|
||||
const etl::basic_format_spec<TIString>& format,
|
||||
const bool append = false)
|
||||
{
|
||||
etl::private_to_string::add_boolean(value, str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For pointers. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
const TIString& to_string(const volatile void* value,
|
||||
TIString& str,
|
||||
const bool append = false)
|
||||
{
|
||||
etl::basic_format_spec<TIString> format;
|
||||
|
||||
etl::private_to_string::add_pointer(value, str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For pointers. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
const TIString& to_string(const volatile void* value,
|
||||
TIString& str,
|
||||
const etl::basic_format_spec<TIString>& format,
|
||||
const bool append = false)
|
||||
{
|
||||
etl::private_to_string::add_pointer(value, str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, bool>::value &&
|
||||
!etl::is_same<T, int64_t>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const bool append = false)
|
||||
{
|
||||
etl::basic_format_spec<TIString> format;
|
||||
|
||||
etl::private_to_string::add_integral(int32_t(value), str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, bool>::value &&
|
||||
!etl::is_same<T, int64_t>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
|
||||
{
|
||||
etl::private_to_string::add_integral(int32_t(value), str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less then 64 bits. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, bool>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const bool append = false)
|
||||
{
|
||||
etl::basic_format_spec<TIString> format;
|
||||
|
||||
etl::private_to_string::add_integral(uint32_t(value), str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less than 64 bits. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, bool>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
|
||||
{
|
||||
etl::private_to_string::add_integral(uint32_t(value), str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, bool>::value &&
|
||||
etl::is_same<T, int64_t>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const bool append = false)
|
||||
{
|
||||
etl::basic_format_spec<TIString> format;
|
||||
|
||||
etl::private_to_string::add_integral(int64_t(value), str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, bool>::value &&
|
||||
etl::is_same<T, int64_t>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
|
||||
{
|
||||
etl::private_to_string::add_integral(int64_t(value), str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, bool>::value &&
|
||||
etl::is_same<T, uint64_t>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const bool append = false)
|
||||
{
|
||||
etl::basic_format_spec<TIString> format;
|
||||
|
||||
etl::private_to_string::add_integral(uint64_t(value), str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, bool>::value &&
|
||||
etl::is_same<T, uint64_t>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
|
||||
{
|
||||
etl::private_to_string::add_integral(uint64_t(value), str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For floating point. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_floating_point<T>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const bool append = false)
|
||||
{
|
||||
etl::basic_format_spec<TIString> format;
|
||||
|
||||
etl::private_to_string::add_floating_point(value, str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For floating point. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TIString>
|
||||
typename etl::enable_if<etl::is_floating_point<T>::value, const TIString&>::type
|
||||
to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
|
||||
{
|
||||
etl::private_to_string::add_floating_point(value, str, format, append);
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -39,110 +39,28 @@ SOFTWARE.
|
||||
#include "format_spec.h"
|
||||
#include "private/to_string_helper.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Default format spec.
|
||||
/// Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, int64_t>::value, const etl::istring&>::type
|
||||
to_string(const T value, etl::istring& str, const bool append = false)
|
||||
const etl::istring& to_string(const T value, etl::istring& str, const bool append = false)
|
||||
{
|
||||
etl::format_spec format;
|
||||
|
||||
return to_string_helper(int32_t(value), str, format, append);
|
||||
return private_to_string::to_string(value, str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Supplied format spec.
|
||||
/// Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, int64_t>::value, const etl::istring&>::type
|
||||
to_string(const T value, etl::istring& str, const etl::format_spec& format, const bool append = false)
|
||||
const etl::istring& to_string(const T value, etl::istring& str, const etl::format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(int32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less then 64 bits. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, const etl::istring&>::type
|
||||
to_string(const T value, etl::istring& str, const bool append = false)
|
||||
{
|
||||
etl::format_spec format;
|
||||
|
||||
return to_string_helper(uint32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less than 64 bits. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, const etl::istring&>::type
|
||||
to_string(const T value, etl::istring& str, const etl::format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(uint32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
etl::is_same<T, int64_t>::value, const etl::istring&>::type
|
||||
to_string(const T value, etl::istring& str, const bool append = false)
|
||||
{
|
||||
etl::format_spec format;
|
||||
|
||||
return to_string_helper(int64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
etl::is_same<T, int64_t>::value, const etl::istring&>::type
|
||||
to_string(const T value, etl::istring& str, const etl::format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(int64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
etl::is_same<T, uint64_t>::value, const etl::istring&>::type
|
||||
to_string(const T value, etl::istring& str, const bool append = false)
|
||||
{
|
||||
etl::format_spec format;
|
||||
|
||||
return to_string_helper(uint64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
etl::is_same<T, uint64_t>::value, const etl::istring&>::type
|
||||
to_string(const T value, etl::istring& str, const etl::format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(uint64_t(value), str, format, append);
|
||||
return private_to_string::to_string(value, str, format, append);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,107 +42,23 @@ SOFTWARE.
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Default format spec.
|
||||
/// Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, int64_t>::value, etl::iu16string&>::type
|
||||
to_u16string(const T value, etl::iu16string& str, const bool append = false)
|
||||
const etl::iu16string& to_u16string(const T value, etl::iu16string& str, const bool append = false)
|
||||
{
|
||||
etl::u16format_spec format;
|
||||
|
||||
return to_string_helper(int32_t(value), str, format, append);
|
||||
return etl::private_to_string::to_string(value, str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Supplied format spec.
|
||||
/// Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, int64_t>::value, etl::iu16string&>::type
|
||||
to_u16string(const T value, etl::iu16string& str, const etl::u16format_spec& format, const bool append = false)
|
||||
const etl::iu16string& to_u16string(const T value, etl::iu16string& str, const etl::u16format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(int32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less then 64 bits. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, etl::iu16string&>::type
|
||||
to_u16string(const T value, etl::iu16string& str, const bool append = false)
|
||||
{
|
||||
etl::u16format_spec format;
|
||||
|
||||
return to_string_helper(uint32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less than 64 bits. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, etl::iu16string&>::type
|
||||
to_u16string(const T value, etl::iu16string& str, const etl::u16format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(uint32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
etl::is_same<T, int64_t>::value, etl::iu16string&>::type
|
||||
to_u16string(const T value, etl::iu16string& str, const bool append = false)
|
||||
{
|
||||
etl::u16format_spec format;
|
||||
|
||||
return to_string_helper(int64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
etl::is_same<T, int64_t>::value, etl::iu16string&>::type
|
||||
to_u16string(const T value, etl::iu16string& str, const etl::u16format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(int64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
etl::is_same<T, uint64_t>::value, etl::iu16string&>::type
|
||||
to_u16string(const T value, etl::iu16string& str, const bool append = false)
|
||||
{
|
||||
etl::u16format_spec format;
|
||||
|
||||
return to_string_helper(uint64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
etl::is_same<T, uint64_t>::value, etl::iu16string&>::type
|
||||
to_u16string(const T value, etl::iu16string& str, const etl::u16format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(uint64_t(value), str, format, append);
|
||||
return etl::private_to_string::to_string(value, str, format, append);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,107 +42,23 @@ SOFTWARE.
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Default format spec.
|
||||
/// Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, int64_t>::value, etl::iu32string&>::type
|
||||
to_u32string(const T value, etl::iu32string& str, const bool append = false)
|
||||
const etl::iu32string& to_u32string(const T value, etl::iu32string& str, const bool append = false)
|
||||
{
|
||||
etl::u32format_spec format;
|
||||
|
||||
return to_string_helper(int32_t(value), str, format, append);
|
||||
return etl::private_to_string::to_string(value, str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Supplied format spec.
|
||||
/// Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, int64_t>::value, etl::iu32string&>::type
|
||||
to_u32string(const T value, etl::iu32string& str, const etl::u32format_spec& format, const bool append = false)
|
||||
const etl::iu32string& to_u32string(const T value, etl::iu32string& str, const etl::u32format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(int32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less then 64 bits. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, etl::iu32string&>::type
|
||||
to_u32string(const T value, etl::iu32string& str, const bool append = false)
|
||||
{
|
||||
etl::u32format_spec format;
|
||||
|
||||
return to_string_helper(uint32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less than 64 bits. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, etl::iu32string&>::type
|
||||
to_u32string(const T value, etl::iu32string& str, const etl::u32format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(uint32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
etl::is_same<T, int64_t>::value, etl::iu32string&>::type
|
||||
to_u32string(const T value, etl::iu32string& str, const bool append = false)
|
||||
{
|
||||
etl::u32format_spec format;
|
||||
|
||||
return to_string_helper(int64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
etl::is_same<T, int64_t>::value, etl::iu32string&>::type
|
||||
to_u32string(const T value, etl::iu32string& str, const etl::u32format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(int64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
etl::is_same<T, uint64_t>::value, etl::iu32string&>::type
|
||||
to_u32string(const T value, etl::iu32string& str, const bool append = false)
|
||||
{
|
||||
etl::u32format_spec format;
|
||||
|
||||
return to_string_helper(uint64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
etl::is_same<T, uint64_t>::value, etl::iu32string&>::type
|
||||
to_u32string(const T value, etl::iu32string& str, const etl::u32format_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(uint64_t(value), str, format, append);
|
||||
return etl::private_to_string::to_string(value, str, format, append);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,107 +42,23 @@ SOFTWARE.
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Default format spec.
|
||||
/// Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, int64_t>::value, etl::iwstring&>::type
|
||||
to_wstring(const T value, etl::iwstring& str, const bool append = false)
|
||||
const etl::iwstring& to_wstring(const T value, etl::iwstring& str, const bool append = false)
|
||||
{
|
||||
etl::wformat_spec format;
|
||||
|
||||
return to_string_helper(int32_t(value), str, format, append);
|
||||
return etl::private_to_string::to_string(value, str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed integrals less than 64 bits. Supplied format spec.
|
||||
/// Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
!etl::is_same<T, int64_t>::value, etl::iwstring&>::type
|
||||
to_wstring(const T value, etl::iwstring& str, const etl::wformat_spec& format, const bool append = false)
|
||||
const etl::iwstring& to_wstring(const T value, etl::iwstring& str, const etl::wformat_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(int32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less then 64 bits. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, etl::iwstring&>::type
|
||||
to_wstring(const T value, etl::iwstring& str, const bool append = false)
|
||||
{
|
||||
etl::wformat_spec format;
|
||||
|
||||
return to_string_helper(uint32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned integrals less than 64 bits. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
!etl::is_same<T, uint64_t>::value, etl::iwstring&>::type
|
||||
to_wstring(const T value, etl::iwstring& str, const etl::wformat_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(uint32_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
etl::is_same<T, int64_t>::value, etl::iwstring&>::type
|
||||
to_wstring(const T value, etl::iwstring& str, const bool append = false)
|
||||
{
|
||||
etl::wformat_spec format;
|
||||
|
||||
return to_string_helper(int64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For signed 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_signed<T>::value &&
|
||||
etl::is_same<T, int64_t>::value, etl::iwstring&>::type
|
||||
to_wstring(const T value, etl::iwstring& str, const etl::wformat_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(int64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Default format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
etl::is_same<T, uint64_t>::value, etl::iwstring&>::type
|
||||
to_wstring(const T value, etl::iwstring& str, const bool append = false)
|
||||
{
|
||||
etl::wformat_spec format;
|
||||
|
||||
return to_string_helper(uint64_t(value), str, format, append);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For unsigned 64 bit integrals. Supplied format spec.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value &&
|
||||
etl::is_unsigned<T>::value &&
|
||||
etl::is_same<T, uint64_t>::value, etl::iwstring&>::type
|
||||
to_wstring(const T value, etl::iwstring& str, const etl::wformat_spec& format, const bool append = false)
|
||||
{
|
||||
return to_string_helper(uint64_t(value), str, format, append);
|
||||
return etl::private_to_string::to_string(value, str, format, append);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -29,6 +29,8 @@ SOFTWARE.
|
||||
#include "UnitTest++.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "etl/to_string.h"
|
||||
#include "etl/cstring.h"
|
||||
@ -112,6 +114,8 @@ namespace
|
||||
|
||||
Format format = Format().base(10).width(20).fill(STR('#'));
|
||||
|
||||
etl::to_string(uint8_t(0), str, format);
|
||||
|
||||
CHECK_EQUAL(etl::string<20>(STR("###################0")), etl::to_string(uint8_t(0), str, format));
|
||||
CHECK_EQUAL(etl::string<20>(STR("###################0")), etl::to_string(uint16_t(0), str, format));
|
||||
CHECK_EQUAL(etl::string<20>(STR("###################0")), etl::to_string(uint32_t(0), str, format));
|
||||
@ -138,7 +142,7 @@ namespace
|
||||
{
|
||||
etl::string<20> str;
|
||||
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left_justified(true);
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left();
|
||||
|
||||
CHECK_EQUAL(etl::string<20>(STR("0###################")), etl::to_string(uint8_t(0), str, format));
|
||||
CHECK_EQUAL(etl::string<20>(STR("0###################")), etl::to_string(uint16_t(0), str, format));
|
||||
@ -249,5 +253,134 @@ namespace
|
||||
CHECK_EQUAL(etl::string<17>(STR("123456")), etl::to_string(123456, str, Format().decimal()));
|
||||
CHECK_EQUAL(etl::string<17>(STR("1E240")), etl::to_string(123456, str, Format().hex()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
|
||||
CHECK_EQUAL(etl::string<20>(STR(" 12.345678")), etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK_EQUAL(etl::string<20>(STR("12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result 12.345678")), etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result 12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
|
||||
CHECK_EQUAL(etl::string<20>(STR(" 0")), to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::string<20>(STR(" 1")), to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::string<20>(STR("0 ")), to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::string<20>(STR("1 ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK_EQUAL(etl::string<20>(STR(" false")), to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::string<20>(STR(" true")), to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::string<20>(STR("false ")), to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::string<20>(STR("true ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result 0")), to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result 1")), to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result 0 ")), to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result 1 ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result false")), to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result true")), to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result false ")), to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::string<20>(STR("Result true ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
|
||||
static const volatile int cvi = 0;
|
||||
|
||||
std::ostringstream oss;
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::uppercase << std::right << uintptr_t(&cvi);
|
||||
std::string temp(oss.str());
|
||||
etl::string<20> compare(temp.begin(), temp.end());
|
||||
|
||||
to_string(&cvi, str, Format().hex().width(10).right().fill(STR('0')));
|
||||
CHECK_EQUAL(compare, str);
|
||||
|
||||
oss.clear();
|
||||
oss.str(STR(""));
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::uppercase << std::left << uintptr_t(&cvi);
|
||||
temp = oss.str();
|
||||
compare.assign(temp.begin(), temp.end());
|
||||
|
||||
to_string(&cvi, str, Format().hex().width(10).left().fill(STR('0')));
|
||||
CHECK_EQUAL(compare, str);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
|
||||
static const volatile int cvi = 0;
|
||||
|
||||
std::ostringstream oss;
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::uppercase << std::right << uintptr_t(&cvi);
|
||||
std::string temp(STR("Result "));
|
||||
temp.append(oss.str());
|
||||
etl::string<20> compare(temp.begin(), temp.end());
|
||||
|
||||
str.assign(STR("Result "));
|
||||
to_string(&cvi, str, Format().hex().width(10).right().fill(STR('0')), true);
|
||||
CHECK_EQUAL(compare, str);
|
||||
|
||||
oss.clear();
|
||||
oss.str(STR(""));
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::uppercase << std::left << uintptr_t(&cvi);
|
||||
temp = STR("Result ");
|
||||
temp.append(oss.str());
|
||||
compare.assign(temp.begin(), temp.end());
|
||||
|
||||
str.assign(STR("Result "));
|
||||
to_string(&cvi, str, Format().hex().width(10).left().fill(STR('0')), true);
|
||||
CHECK_EQUAL(compare, str);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -29,6 +29,8 @@ SOFTWARE.
|
||||
#include "UnitTest++.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "etl/to_u16string.h"
|
||||
#include "etl/u16string.h"
|
||||
@ -41,6 +43,8 @@ namespace
|
||||
{
|
||||
typedef etl::u16format_spec Format;
|
||||
|
||||
typedef std::basic_ostringstream<char16_t> u16stringstream;
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const etl::iu16string& str)
|
||||
{
|
||||
for (auto c : str)
|
||||
@ -138,7 +142,7 @@ namespace
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left_justified(true);
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left();
|
||||
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("0###################")), etl::to_u16string(uint8_t(0), str, format));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("0###################")), etl::to_u16string(uint16_t(0), str, format));
|
||||
@ -249,5 +253,72 @@ namespace
|
||||
CHECK_EQUAL(etl::u16string<17>(STR("123456")), etl::to_u16string(123456, str, Format().decimal()));
|
||||
CHECK_EQUAL(etl::u16string<17>(STR("1E240")), etl::to_u16string(123456, str, Format().hex()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
|
||||
CHECK_EQUAL(etl::u16string<20>(STR(" 12.345678")), etl::to_u16string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("12.345678 ")), etl::to_u16string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result 12.345678")), etl::to_u16string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result 12.345678 ")), etl::to_u16string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
|
||||
CHECK_EQUAL(etl::u16string<20>(STR(" 0")), to_u16string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR(" 1")), to_u16string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("0 ")), to_u16string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("1 ")), to_u16string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK_EQUAL(etl::u16string<20>(STR(" false")), to_u16string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR(" true")), to_u16string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("false ")), to_u16string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("true ")), to_u16string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result 0")), to_u16string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result 1")), to_u16string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result 0 ")), to_u16string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result 1 ")), to_u16string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result false")), to_u16string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result true")), to_u16string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result false ")), to_u16string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u16string<20>(STR("Result true ")), to_u16string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ namespace
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left_justified(true);
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left();
|
||||
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("0###################")), etl::to_u32string(uint8_t(0), str, format));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("0###################")), etl::to_u32string(uint16_t(0), str, format));
|
||||
@ -250,5 +250,72 @@ namespace
|
||||
CHECK_EQUAL(etl::u32string<17>(STR("123456")), etl::to_u32string(123456, str, Format().decimal()));
|
||||
CHECK_EQUAL(etl::u32string<17>(STR("1E240")), etl::to_u32string(123456, str, Format().hex()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
|
||||
CHECK_EQUAL(etl::u32string<20>(STR(" 12.345678")), etl::to_u32string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("12.345678 ")), etl::to_u32string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result 12.345678")), etl::to_u32string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result 12.345678 ")), etl::to_u32string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
|
||||
CHECK_EQUAL(etl::u32string<20>(STR(" 0")), to_u32string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR(" 1")), to_u32string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("0 ")), to_u32string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("1 ")), to_u32string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK_EQUAL(etl::u32string<20>(STR(" false")), to_u32string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR(" true")), to_u32string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("false ")), to_u32string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("true ")), to_u32string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result 0")), to_u32string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result 1")), to_u32string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result 0 ")), to_u32string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result 1 ")), to_u32string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result false")), to_u32string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result true")), to_u32string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result false ")), to_u32string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::u32string<20>(STR("Result true ")), to_u32string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -29,6 +29,8 @@ SOFTWARE.
|
||||
#include "UnitTest++.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "etl/to_wstring.h"
|
||||
#include "etl/wstring.h"
|
||||
@ -138,7 +140,7 @@ namespace
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left_justified(true);
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left();
|
||||
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("0###################")), etl::to_wstring(uint8_t(0), str, format));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("0###################")), etl::to_wstring(uint16_t(0), str, format));
|
||||
@ -249,5 +251,134 @@ namespace
|
||||
CHECK_EQUAL(etl::wstring<17>(STR("123456")), etl::to_wstring(123456, str, Format().decimal()));
|
||||
CHECK_EQUAL(etl::wstring<17>(STR("1E240")), etl::to_wstring(123456, str, Format().hex()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
|
||||
CHECK_EQUAL(etl::wstring<20>(STR(" 12.345678")), etl::to_wstring(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("12.345678 ")), etl::to_wstring(12.345678, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result 12.345678")), etl::to_wstring(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result 12.345678 ")), etl::to_wstring(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
|
||||
CHECK_EQUAL(etl::wstring<20>(STR(" 0")), to_wstring(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR(" 1")), to_wstring(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("0 ")), to_wstring(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("1 ")), to_wstring(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK_EQUAL(etl::wstring<20>(STR(" false")), to_wstring(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR(" true")), to_wstring(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("false ")), to_wstring(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("true ")), to_wstring(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result 0")), to_wstring(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result 1")), to_wstring(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result 0 ")), to_wstring(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result 1 ")), to_wstring(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result false")), to_wstring(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result true")), to_wstring(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result false ")), to_wstring(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK_EQUAL(etl::wstring<20>(STR("Result true ")), to_wstring(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
|
||||
static const volatile int cvi = 0;
|
||||
|
||||
std::wostringstream oss;
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::uppercase << std::right << uintptr_t(&cvi);
|
||||
std::wstring temp(oss.str());
|
||||
etl::wstring<20> compare(temp.begin(), temp.end());
|
||||
|
||||
to_wstring(&cvi, str, Format().hex().width(10).right().fill(STR('0')));
|
||||
CHECK_EQUAL(compare, str);
|
||||
|
||||
oss.clear();
|
||||
oss.str(STR(""));
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::uppercase << std::left << uintptr_t(&cvi);
|
||||
temp = oss.str();
|
||||
compare.assign(temp.begin(), temp.end());
|
||||
|
||||
to_wstring(&cvi, str, Format().hex().width(10).left().fill(STR('0')));
|
||||
CHECK_EQUAL(compare, str);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
|
||||
static const volatile int cvi = 0;
|
||||
|
||||
std::wostringstream oss;
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::uppercase << std::right << uintptr_t(&cvi);
|
||||
std::wstring temp(STR("Result "));
|
||||
temp.append(oss.str());
|
||||
etl::wstring<20> compare(temp.begin(), temp.end());
|
||||
|
||||
str.assign(STR("Result "));
|
||||
to_wstring(&cvi, str, Format().hex().width(10).right().fill(STR('0')), true);
|
||||
CHECK_EQUAL(compare, str);
|
||||
|
||||
oss.clear();
|
||||
oss.str(STR(""));
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::uppercase << std::left << uintptr_t(&cvi);
|
||||
temp = STR("Result ");
|
||||
temp.append(oss.str());
|
||||
compare.assign(temp.begin(), temp.end());
|
||||
|
||||
str.assign(STR("Result "));
|
||||
to_wstring(&cvi, str, Format().hex().width(10).left().fill(STR('0')), true);
|
||||
CHECK_EQUAL(compare, str);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user