Add case sensitivity support to sse conversion
This commit is contained in:
parent
094f7fc679
commit
a675624cab
2 changed files with 63 additions and 7 deletions
|
@ -29,6 +29,17 @@ template <typename T> using int_info_16 = dhandy::implem::int_info<T, 16>;
|
|||
template <typename T> using int_info_2 = dhandy::implem::int_info<T, 2>;
|
||||
|
||||
namespace {
|
||||
template <unsigned int Base>
|
||||
struct ASCIITranslatorIns : public dhandy::ASCIITranslator<char> {
|
||||
static const constexpr char AltLetter = 'A';
|
||||
static constexpr int from_digit (char dig) {
|
||||
if (dig >= FirstLetter and dig <= FirstLetter + Base - 10 - 1)
|
||||
return dig - FirstLetter + 10;
|
||||
else
|
||||
return dig - AltLetter + 10;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, unsigned int Base>
|
||||
void AryConversionTestHelper (const std::string_view& s, T expected, bool expect_sse) {
|
||||
using AryConversion = dhandy::implem::AryConversion<T, Base, dhandy::ASCIITranslator<char>, false>;
|
||||
|
@ -42,6 +53,13 @@ namespace {
|
|||
CHECK(AryConversion::is_sse == expect_sse);
|
||||
CHECK(AryConversion::from_ary(s.data(), s.data() + s.size()) == expected);
|
||||
}
|
||||
|
||||
template <typename T, unsigned int Base>
|
||||
void AryConversionTestHelperIns (const std::string_view& s, T expected, bool expect_sse) {
|
||||
using AryConversion = dhandy::implem::AryConversion<T, Base, ASCIITranslatorIns<Base>, false>;
|
||||
CHECK(AryConversion::is_sse == expect_sse);
|
||||
CHECK(AryConversion::from_ary(s.data(), s.data() + s.size()) == expected);
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
TEST_CASE ("Check int to char array conversions", "[s2i][int_conv]") {
|
||||
|
@ -170,6 +188,15 @@ TEST_CASE ("Check char array to int conversions", "[i2s][int_conv]") {
|
|||
AryConversionTestHelper<signed int, 10>("-50000", -50000, sizeof(signed int) <= sizeof(std::uint32_t));
|
||||
AryConversionTestHelper<std::int64_t, 10>("-1", -1, false);
|
||||
AryConversionTestHelper<std::int64_t, 10>("-510123123123", -510123123123, false);
|
||||
|
||||
//case insensitive SSE conversions
|
||||
AryConversionTestHelperIns<std::int32_t, 16>("7FfFfFfF", 0x7fffffff, true);
|
||||
AryConversionTestHelperIns<std::int32_t, 16>("AbCdEf01", 0xabcdef01, true);
|
||||
AryConversionTestHelperIns<std::int32_t, 16>("aBcDeF01", 0xabcdef01, true);
|
||||
AryConversionTestHelperIns<std::uint8_t, 16>("Ff", 0xff, true);
|
||||
AryConversionTestHelperIns<std::int16_t, 16>("AfBe", 0xafbe, true);
|
||||
AryConversionTestHelperIns<std::int32_t, 16>("aAb", 0xaab, true);
|
||||
AryConversionTestHelperIns<std::int32_t, 16>("aAbBc", 0xaabbc, true);
|
||||
}
|
||||
|
||||
TEST_CASE ("Check upcase/downcase int to array conversions", "[i2s][int_conv]") {
|
||||
|
@ -195,3 +222,12 @@ TEST_CASE ("Check upcase/downcase int to array conversions", "[i2s][int_conv]")
|
|||
constexpr auto int4 = int_conv<string_view>(integral_constant<short int, -256>{});
|
||||
CHECK("-256" == int4);
|
||||
}
|
||||
|
||||
TEST_CASE ("Try int conv with non-char", "[i2s][int_conv]") {
|
||||
using dhandy::int_to_ary;
|
||||
using dhandy::ASCIITranslator;
|
||||
|
||||
std::wstring_view exp1(L"235713");
|
||||
auto val1 = int_to_ary<int, 10, ASCIITranslator<wchar_t>>(235713).to_string_view();
|
||||
CHECK(exp1 == val1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue