Added named base settings

This commit is contained in:
John Wellbelove 2019-04-08 13:58:48 +01:00
parent 5220837979
commit e122b380a3
5 changed files with 84 additions and 0 deletions

View File

@ -72,6 +72,45 @@ namespace etl
return *this;
}
//***************************************************************************
/// Sets the base to binary.
/// \return A reference to the format_spec.
//***************************************************************************
format_spec& binary()
{
base(2);
return *this;
}
//***************************************************************************
/// Sets the base to octal.
/// \return A reference to the format_spec.
//***************************************************************************
format_spec& octal()
{
base(8);
return *this;
}
//***************************************************************************
/// Sets the base to decimal.
/// \return A reference to the format_spec.
//***************************************************************************
format_spec& decimal()
{
base(10);
return *this;
}
//***************************************************************************
/// Sets the base to hex.
/// \return A reference to the format_spec.
//***************************************************************************
format_spec& hex()
{
base(16);
return *this;
}
//***************************************************************************
/// Gets the base.
//***************************************************************************

View File

@ -238,5 +238,16 @@ namespace
CHECK_EQUAL(etl::string<16>(STR("80000000")), etl::to_string(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::string<16>(STR("8000000000000000")), etl::to_string(int64_t(-9223372036854775808ll), str, Format().base(16).width(16).fill(STR('0'))));
}
//*************************************************************************
TEST(test_named_format_no_append)
{
etl::string<17> str;
CHECK_EQUAL(etl::string<17>(STR("11110001001000000")), etl::to_string(123456, str, Format().binary()));
CHECK_EQUAL(etl::string<17>(STR("361100")), etl::to_string(123456, str, Format().octal()));
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()));
}
};
}

View File

@ -238,5 +238,16 @@ namespace
CHECK_EQUAL(etl::u16string<16>(STR("80000000")), etl::to_u16string(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::u16string<16>(STR("8000000000000000")), etl::to_u16string(int64_t(-9223372036854775808ll), str, Format().base(16).width(16).fill(STR('0'))));
}
//*************************************************************************
TEST(test_named_format_no_append)
{
etl::u16string<17> str;
CHECK_EQUAL(etl::u16string<17>(STR("11110001001000000")), etl::to_u16string(123456, str, Format().binary()));
CHECK_EQUAL(etl::u16string<17>(STR("361100")), etl::to_u16string(123456, str, Format().octal()));
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()));
}
};
}

View File

@ -238,5 +238,17 @@ namespace
CHECK_EQUAL(etl::u32string<16>(STR("80000000")), etl::to_u32string(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::u32string<16>(STR("8000000000000000")), etl::to_u32string(int64_t(-9223372036854775808ll), str, Format().base(16).width(16).fill(STR('0'))));
}
//*************************************************************************
TEST(test_named_format_no_append)
{
etl::u32string<17> str;
CHECK_EQUAL(etl::u32string<17>(STR("11110001001000000")), etl::to_u32string(123456, str, Format().binary()));
CHECK_EQUAL(etl::u32string<17>(STR("361100")), etl::to_u32string(123456, str, Format().octal()));
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()));
}
};
}

View File

@ -238,5 +238,16 @@ namespace
CHECK_EQUAL(etl::wstring<16>(STR("80000000")), etl::to_wstring(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("8000000000000000")), etl::to_wstring(int64_t(-9223372036854775808ll), str, Format().base(16).width(16).fill(STR('0'))));
}
//*************************************************************************
TEST(test_named_format_no_append)
{
etl::wstring<17> str;
CHECK_EQUAL(etl::wstring<17>(STR("11110001001000000")), etl::to_wstring(123456, str, Format().binary()));
CHECK_EQUAL(etl::wstring<17>(STR("361100")), etl::to_wstring(123456, str, Format().octal()));
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()));
}
};
}