mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 00:46:03 +08:00
Added ""_sv string view operators
This commit is contained in:
parent
2b96628850
commit
eb3593d2ef
@ -43,6 +43,19 @@ SOFTWARE.
|
||||
|
||||
namespace etl
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
inline namespace literals
|
||||
{
|
||||
inline namespace string_literals
|
||||
{
|
||||
constexpr etl::string_view operator ""_sv(const char* str, size_t length) noexcept
|
||||
{
|
||||
return etl::string_view{ str, length };
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef etl::ibasic_string<char> istring;
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -41,6 +41,19 @@ SOFTWARE.
|
||||
|
||||
namespace etl
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
inline namespace literals
|
||||
{
|
||||
inline namespace string_literals
|
||||
{
|
||||
constexpr etl::u16string_view operator ""_sv(const char16_t* str, size_t length) noexcept
|
||||
{
|
||||
return etl::u16string_view{ str, length };
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef ibasic_string<char16_t> iu16string;
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -41,6 +41,19 @@ SOFTWARE.
|
||||
|
||||
namespace etl
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
inline namespace literals
|
||||
{
|
||||
inline namespace string_literals
|
||||
{
|
||||
constexpr etl::u32string_view operator ""_sv(const char32_t* str, size_t length) noexcept
|
||||
{
|
||||
return etl::u32string_view{ str, length };
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef ibasic_string<char32_t> iu32string;
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -41,6 +41,19 @@ SOFTWARE.
|
||||
|
||||
namespace etl
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
inline namespace literals
|
||||
{
|
||||
inline namespace string_literals
|
||||
{
|
||||
constexpr etl::wstring_view operator ""_sv(const wchar_t* str, size_t length) noexcept
|
||||
{
|
||||
return etl::wstring_view{ str, length };
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef ibasic_string<wchar_t> iwstring;
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -1013,5 +1013,26 @@ namespace
|
||||
CHECK(etl::hash<U16Text>()(u16text) == etl::hash<U16View>()(u16view));
|
||||
CHECK(etl::hash<U32Text>()(u32text) == etl::hash<U32View>()(u32view));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(string_view_literal)
|
||||
{
|
||||
typedef etl::string_view View;
|
||||
typedef etl::wstring_view WView;
|
||||
typedef etl::u16string_view U16View;
|
||||
typedef etl::u32string_view U32View;
|
||||
|
||||
using namespace etl::literals::string_literals;
|
||||
|
||||
View view = "Hello World"_sv;
|
||||
WView wview = L"Hello World"_sv;
|
||||
U16View u16view = u"Hello World"_sv;
|
||||
U32View u32view = U"Hello World"_sv;
|
||||
|
||||
CHECK_TRUE((view == View{ "Hello World", etl::strlen("Hello World") }));
|
||||
CHECK_TRUE((wview == WView{ L"Hello World", etl::strlen(L"Hello World") }));
|
||||
CHECK_TRUE((u16view == U16View{ u"Hello World", etl::strlen(u"Hello World") }));
|
||||
CHECK_TRUE((u32view == U32View{ U"Hello World", etl::strlen(U"Hello World") }));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user