mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Optimisation of strings
This commit is contained in:
parent
f178cde02d
commit
155050b816
@ -139,17 +139,19 @@ namespace etl
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR14 size_t length(const char_type* begin)
|
||||
{
|
||||
const char_type* end = begin;
|
||||
|
||||
if (end != 0)
|
||||
if (begin == ETL_NULLPTR)
|
||||
{
|
||||
while (*end++ != 0)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size_t(end - begin);
|
||||
const char_type* end = begin;
|
||||
|
||||
while (*end++ != 0)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
return size_t(end - begin) - 1;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -55,6 +55,16 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_strlen)
|
||||
{
|
||||
CHECK_EQUAL(0U, etl::strlen((const char*)0));
|
||||
CHECK_EQUAL(0U, etl::strlen((const wchar_t*)0));
|
||||
CHECK_EQUAL(0U, etl::strlen((const char16_t*)0));
|
||||
CHECK_EQUAL(0U, etl::strlen((const char32_t*)0));
|
||||
|
||||
CHECK_EQUAL(0U, etl::strlen(""));
|
||||
CHECK_EQUAL(0U, etl::strlen(L""));
|
||||
CHECK_EQUAL(0U, etl::strlen(u""));
|
||||
CHECK_EQUAL(0U, etl::strlen(U""));
|
||||
|
||||
CHECK_EQUAL(6U, etl::strlen("qwerty"));
|
||||
CHECK_EQUAL(6U, etl::strlen(L"qwerty"));
|
||||
CHECK_EQUAL(6U, etl::strlen(u"qwerty"));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user