[core] Check if string contains only ASCII symbols

function and test.
This commit is contained in:
Kirill Zhdanovich 2013-11-25 17:57:47 +03:00 committed by Alex Zolotarev
parent f9531de202
commit db64a4e862
3 changed files with 20 additions and 0 deletions

View file

@ -401,3 +401,14 @@ UNIT_TEST(UniString_LessAndEqualsAndNotEquals)
}
}
}
UNIT_TEST(IsUtf8Test)
{
TEST(!strings::IsASCIIString("Нет"), ());
TEST(!strings::IsASCIIString("Классненькие места в Жодино.kml"), ());
TEST(!strings::IsASCIIString("在Zhodino陰涼處.kml"), ());
TEST(!strings::IsASCIIString("מקום קריר בZhodino.kml"), ());
TEST(strings::IsASCIIString("YES"), ());
TEST(strings::IsASCIIString("Nice places in Zhodino.kml"), ());
}

View file

@ -147,6 +147,14 @@ string ToUtf8(UniString const & s)
return result;
}
bool IsASCIIString(string const & str)
{
for (size_t i = 0; i < str.size(); ++i)
if (str[i] < 0 || str[i] > 127)
return false;
return true;
}
bool StartsWith(string const & s1, char const * s2)
{
return (s1.compare(0, strlen(s2), s2) == 0);

View file

@ -43,6 +43,7 @@ bool EqualNoCase(string const & s1, string const & s2);
UniString MakeUniString(string const & utf8s);
string ToUtf8(UniString const & s);
bool IsASCIIString(string const & str);
inline string DebugPrint(UniString const & s)
{