mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Fix make_string for zero length literals
Remove redundant test support code
This commit is contained in:
parent
39a3f77ed4
commit
9eaa3e1178
@ -451,6 +451,13 @@ namespace etl
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//*************************************************************************
|
||||
/// Deleted.
|
||||
//*************************************************************************
|
||||
string(const string& other) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
@ -478,41 +485,13 @@ namespace etl
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace private_string_char
|
||||
{
|
||||
//***********************************
|
||||
template<size_t ARRAY_SIZE = 1U>
|
||||
struct make_string_helper
|
||||
{
|
||||
typedef etl::string<ARRAY_SIZE> type;
|
||||
|
||||
static type make(const char(&text)[ARRAY_SIZE])
|
||||
{
|
||||
return etl::string<ARRAY_SIZE - 1>(text, ARRAY_SIZE - 1);
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
template<>
|
||||
struct make_string_helper<1U>
|
||||
{
|
||||
typedef etl::string<0> type;
|
||||
|
||||
static type make(const char(&text)[1U])
|
||||
{
|
||||
static char c;
|
||||
return etl::string<0U>(text, &c, 1U);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Make string from string literal or array
|
||||
//***************************************************************************
|
||||
template<size_t ARRAY_SIZE>
|
||||
etl::string<ARRAY_SIZE - 1> make_string(const char(&text)[ARRAY_SIZE])
|
||||
etl::string<ARRAY_SIZE == 1 ? 1 : ARRAY_SIZE - 1> make_string(const char(&text)[ARRAY_SIZE])
|
||||
{
|
||||
return private_string_char::make_string_helper<ARRAY_SIZE>::make(text);
|
||||
return etl::string<ARRAY_SIZE == 1 ? 1 : ARRAY_SIZE - 1>(text, ARRAY_SIZE - 1);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -434,6 +434,13 @@ namespace etl
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//*************************************************************************
|
||||
/// Deleted.
|
||||
//*************************************************************************
|
||||
u16string(const u16string& other) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
@ -461,41 +468,13 @@ namespace etl
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace private_u16string
|
||||
{
|
||||
//***********************************
|
||||
template<size_t ARRAY_SIZE = 1U>
|
||||
struct make_string_helper
|
||||
{
|
||||
typedef etl::u16string<ARRAY_SIZE> type;
|
||||
|
||||
static type make(const char16_t(&text)[ARRAY_SIZE])
|
||||
{
|
||||
return etl::u16string<ARRAY_SIZE - 1>(text, ARRAY_SIZE - 1);
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
template<>
|
||||
struct make_string_helper<1U>
|
||||
{
|
||||
typedef etl::u16string<0> type;
|
||||
|
||||
static type make(const char16_t(&text)[1U])
|
||||
{
|
||||
static char16_t c;
|
||||
return etl::u16string<0U>(text, &c, 1U);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Make string from string literal or array
|
||||
//***************************************************************************
|
||||
template<size_t ARRAY_SIZE>
|
||||
etl::u16string<ARRAY_SIZE - 1> make_string(const char16_t(&text)[ARRAY_SIZE])
|
||||
etl::u16string<ARRAY_SIZE == 1 ? 1 : ARRAY_SIZE - 1> make_string(const char16_t(&text)[ARRAY_SIZE])
|
||||
{
|
||||
return private_u16string::make_string_helper<ARRAY_SIZE>::make(text);
|
||||
return etl::u16string<ARRAY_SIZE == 1 ? 1 : ARRAY_SIZE - 1>(text, ARRAY_SIZE - 1);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -434,6 +434,13 @@ namespace etl
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//*************************************************************************
|
||||
/// Deleted.
|
||||
//*************************************************************************
|
||||
u32string(const u32string& other) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
@ -461,41 +468,13 @@ namespace etl
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace private_u32string
|
||||
{
|
||||
//***********************************
|
||||
template<size_t ARRAY_SIZE = 1U>
|
||||
struct make_string_helper
|
||||
{
|
||||
typedef etl::u32string<ARRAY_SIZE> type;
|
||||
|
||||
static type make(const char32_t(&text)[ARRAY_SIZE])
|
||||
{
|
||||
return etl::u32string<ARRAY_SIZE - 1>(text, ARRAY_SIZE - 1);
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
template<>
|
||||
struct make_string_helper<1U>
|
||||
{
|
||||
typedef etl::u32string<0> type;
|
||||
|
||||
static type make(const char32_t(&text)[1U])
|
||||
{
|
||||
static char32_t c;
|
||||
return etl::u32string<0U>(text, &c, 1U);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Make string from string literal or array
|
||||
//***************************************************************************
|
||||
template<size_t ARRAY_SIZE>
|
||||
etl::u32string<ARRAY_SIZE - 1> make_string(const char32_t(&text)[ARRAY_SIZE])
|
||||
etl::u32string<ARRAY_SIZE == 1 ? 1 : ARRAY_SIZE - 1> make_string(const char32_t(&text)[ARRAY_SIZE])
|
||||
{
|
||||
return private_u32string::make_string_helper<ARRAY_SIZE>::make(text);
|
||||
return etl::u32string<ARRAY_SIZE == 1 ? 1 : ARRAY_SIZE - 1>(text, ARRAY_SIZE - 1);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -434,6 +434,13 @@ namespace etl
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//*************************************************************************
|
||||
/// Deleted.
|
||||
//*************************************************************************
|
||||
wstring(const wstring& other) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
@ -461,41 +468,13 @@ namespace etl
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace private_wstring
|
||||
{
|
||||
//***********************************
|
||||
template<size_t ARRAY_SIZE = 1U>
|
||||
struct make_string_helper
|
||||
{
|
||||
typedef etl::wstring<ARRAY_SIZE> type;
|
||||
|
||||
static type make(const wchar_t(&text)[ARRAY_SIZE])
|
||||
{
|
||||
return etl::wstring<ARRAY_SIZE - 1>(text, ARRAY_SIZE - 1);
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
template<>
|
||||
struct make_string_helper<1U>
|
||||
{
|
||||
typedef etl::wstring<0> type;
|
||||
|
||||
static type make(const wchar_t(&text)[1U])
|
||||
{
|
||||
static wchar_t c;
|
||||
return etl::wstring<0U>(text, &c, 1U);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Make string from string literal or array
|
||||
//***************************************************************************
|
||||
template<size_t ARRAY_SIZE>
|
||||
etl::wstring<ARRAY_SIZE - 1> make_string(const wchar_t(&text)[ARRAY_SIZE])
|
||||
etl::wstring<ARRAY_SIZE == 1 ? 1 : ARRAY_SIZE - 1> make_string(const wchar_t(&text)[ARRAY_SIZE])
|
||||
{
|
||||
return private_wstring::make_string_helper<ARRAY_SIZE>::make(text);
|
||||
return etl::wstring<ARRAY_SIZE == 1 ? 1 : ARRAY_SIZE - 1>(text, ARRAY_SIZE - 1);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -60,22 +60,6 @@ namespace
|
||||
typedef std::set<DC> Compare_DataDC;
|
||||
typedef std::set<NDC> Compare_DataNDC;
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator <<(std::ostream& os, const DataNDC::iterator& itr)
|
||||
{
|
||||
os << itr->value;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator <<(std::ostream& os, const DataNDC::const_iterator& itr)
|
||||
{
|
||||
os << itr->value;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
SUITE(test_flat_set)
|
||||
{
|
||||
NDC NX = NDC("@");
|
||||
|
||||
@ -63,10 +63,10 @@ namespace
|
||||
auto u16text = etl::make_string(u"");
|
||||
auto u32text = etl::make_string(U"");
|
||||
|
||||
CHECK_EQUAL(length, ctext.max_size());
|
||||
CHECK_EQUAL(length, wtext.max_size());
|
||||
CHECK_EQUAL(length, u16text.max_size());
|
||||
CHECK_EQUAL(length, u32text.max_size());
|
||||
CHECK_EQUAL(length, ctext.size());
|
||||
CHECK_EQUAL(length, wtext.size());
|
||||
CHECK_EQUAL(length, u16text.size());
|
||||
CHECK_EQUAL(length, u32text.size());
|
||||
|
||||
CHECK(Equal(std::string(""), ctext));
|
||||
CHECK(Equal(std::wstring(L""), wtext));
|
||||
|
||||
@ -61,38 +61,6 @@ using Data_const_iterator = Data::const_iterator;
|
||||
using Compare_Data_iterator = Compare_Data::iterator;
|
||||
using Compare_Data_const_iterator = Compare_Data::const_iterator;
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_const_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_const_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_map)
|
||||
|
||||
@ -61,38 +61,6 @@ using Data_const_iterator = Data::const_iterator;
|
||||
using Compare_Data_iterator = Compare_Data::iterator;
|
||||
using Compare_Data_const_iterator = Compare_Data::const_iterator;
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_const_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_const_iterator& it)
|
||||
{
|
||||
os << (*it).first << " " << (*it).second;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_multimap)
|
||||
|
||||
@ -78,22 +78,6 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator <<(std::ostream& os, const DataNDC::iterator& itr)
|
||||
{
|
||||
os << itr->first;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator <<(std::ostream& os, const DataNDC::const_iterator& itr)
|
||||
{
|
||||
os << itr->first;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
SUITE(test_reference_flat_map)
|
||||
{
|
||||
NDC N0 = NDC("A");
|
||||
|
||||
@ -58,21 +58,6 @@ namespace
|
||||
typedef std::multimap<int, DC> Compare_DataDC;
|
||||
typedef std::multimap<int, NDC> Compare_DataNDC;
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator <<(std::ostream& os, const DataNDC::iterator& itr)
|
||||
{
|
||||
os << itr->first;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator <<(std::ostream& os, const DataNDC::const_iterator& itr)
|
||||
{
|
||||
os << itr->first;
|
||||
|
||||
return os;
|
||||
}
|
||||
SUITE(test_reference_flat_multimap)
|
||||
{
|
||||
NDC N0 = NDC("A");
|
||||
|
||||
@ -83,22 +83,6 @@ namespace
|
||||
std::vector<NDC> different_data;
|
||||
std::vector<NDC> multi_data;
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator <<(std::ostream& os, const DataNDC::iterator& itr)
|
||||
{
|
||||
os << itr->value;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
std::ostream& operator <<(std::ostream& os, const DataNDC::const_iterator& itr)
|
||||
{
|
||||
os << itr->value;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
SUITE(test_flat_multiset)
|
||||
{
|
||||
//*************************************************************************
|
||||
|
||||
@ -75,30 +75,6 @@ using Data_const_iterator = Data::const_iterator;
|
||||
using Compare_Data_iterator = Compare_Data::iterator;
|
||||
using Compare_Data_const_iterator = Compare_Data::const_iterator;
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_iterator& it)
|
||||
{
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Data_const_iterator& it)
|
||||
{
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it)
|
||||
{
|
||||
os << (*it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_set)
|
||||
|
||||
@ -54,7 +54,6 @@ namespace
|
||||
StlVData stlvdata = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
EtlData etldatasmaller = { 0, 1, 2, 3, 4, 5, 5, 7, 8, 9 };
|
||||
EtlData etldatashorter = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
|
||||
EtlData etloriginal = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
EtlData etlmodified = { 0, 1, 10, 10, 10, 10, 10, 10, 8, 9 };
|
||||
|
||||
@ -42,8 +42,6 @@ namespace
|
||||
{
|
||||
SUITE(test_string_utilities_std_char)
|
||||
{
|
||||
static const size_t SIZE = 50;
|
||||
|
||||
using String = std::string;
|
||||
using IString = std::string;
|
||||
using StringView = std::string_view;
|
||||
|
||||
@ -42,8 +42,6 @@ namespace
|
||||
{
|
||||
SUITE(test_string_utilities_std_u16)
|
||||
{
|
||||
static const size_t SIZE = 50;
|
||||
|
||||
using String = std::wstring;
|
||||
using IString = std::wstring;
|
||||
using StringView = std::wstring_view;
|
||||
|
||||
@ -42,8 +42,6 @@ namespace
|
||||
{
|
||||
SUITE(test_string_utilities_std_u32)
|
||||
{
|
||||
static const size_t SIZE = 50;
|
||||
|
||||
using String = std::u32string;
|
||||
using IString = std::u32string;
|
||||
using StringView = std::u32string_view;
|
||||
|
||||
@ -42,8 +42,6 @@ namespace
|
||||
{
|
||||
SUITE(test_string_utilities_std_wchar_t)
|
||||
{
|
||||
static const size_t SIZE = 50;
|
||||
|
||||
using String = std::wstring;
|
||||
using IString = std::wstring;
|
||||
using StringView = std::wstring_view;
|
||||
|
||||
@ -57,12 +57,6 @@ namespace
|
||||
char ctext[] = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '\0' };
|
||||
char* pctext = ctext;
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const View& view)
|
||||
{
|
||||
os << uintptr_t(view.begin()) << " " << uintptr_t(view.end());
|
||||
return os;
|
||||
}
|
||||
|
||||
SUITE(test_string_view)
|
||||
{
|
||||
//*************************************************************************
|
||||
@ -143,11 +137,6 @@ namespace
|
||||
auto u16view = etl::make_string_view(u"Hello World");
|
||||
auto u32view = etl::make_string_view(U"Hello World");
|
||||
|
||||
size_t l1 = text.size();
|
||||
size_t l2 = cview.size();
|
||||
|
||||
ptrdiff_t d = std::distance(cview.begin(), cview.end());
|
||||
|
||||
CHECK(std::equal(cview.begin(), cview.end(), text.begin()));
|
||||
CHECK(std::equal(wview.begin(), wview.end(), text.begin()));
|
||||
CHECK(std::equal(u16view.begin(), u16view.end(), text.begin()));
|
||||
|
||||
@ -43,16 +43,6 @@ namespace
|
||||
{
|
||||
typedef etl::format_spec Format;
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const etl::istring& str)
|
||||
{
|
||||
for (auto c : str)
|
||||
{
|
||||
os << c;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
SUITE(test_to_string)
|
||||
{
|
||||
//*************************************************************************
|
||||
|
||||
@ -39,16 +39,6 @@ namespace
|
||||
{
|
||||
typedef etl::u16format_spec Format;
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const etl::iu16string& str)
|
||||
{
|
||||
for (auto c : str)
|
||||
{
|
||||
os << c;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
SUITE(test_to_u16string)
|
||||
{
|
||||
//*************************************************************************
|
||||
|
||||
@ -41,16 +41,6 @@ namespace
|
||||
{
|
||||
typedef etl::u32format_spec Format;
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const etl::iu32string& str)
|
||||
{
|
||||
for (auto c : str)
|
||||
{
|
||||
os << c;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
SUITE(test_to_u32string)
|
||||
{
|
||||
//*************************************************************************
|
||||
|
||||
@ -43,16 +43,6 @@ namespace
|
||||
{
|
||||
typedef etl::wformat_spec Format;
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const etl::iwstring& str)
|
||||
{
|
||||
for (auto c : str)
|
||||
{
|
||||
os << c;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
SUITE(test_to_wstring)
|
||||
{
|
||||
//*************************************************************************
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user