Added strings::IsHTML(string const & s) to correctly render bookmarks descriptions

This commit is contained in:
Alex Zolotarev 2014-11-03 15:38:48 +01:00 committed by Alex Zolotarev
parent 798a3157d6
commit 8f23494fb3
3 changed files with 30 additions and 0 deletions

View file

@ -511,3 +511,14 @@ UNIT_TEST(CountNormLowerSymbols)
TEST_EQUAL(res, results[i], ());
}
}
UNIT_TEST(IsHTML)
{
using namespace strings;
TEST(IsHTML("<a href=\"link\">some link</a>"), ());
TEST(IsHTML("This is: ---> a <b>broken</b> html"), ());
TEST(!IsHTML("This is not html"), ());
TEST(!IsHTML("This is not html < too!"), ());
TEST(!IsHTML("I am > not html"), ());
}

View file

@ -206,4 +206,20 @@ string to_string_dac(double d, int dac)
return ss.str();
}
bool IsHTML(string const & utf8)
{
string::const_iterator it = utf8.begin();
size_t ltCount = 0;
size_t gtCount = 0;
while (it != utf8.end())
{
UniChar const c = utf8::unchecked::next(it);
if (c == '<')
++ltCount;
else if (c == '>')
++gtCount;
}
return (ltCount > 0 && gtCount > 0);
}
} // namespace strings

View file

@ -255,6 +255,9 @@ string to_string_dac(double d, int dac);
bool StartsWith(string const & s1, char const * s2);
/// Try to guess if it's HTML or not. No guarantee.
bool IsHTML(string const & utf8);
/*
template <typename ItT, typename DelimiterT>
typename ItT::value_type JoinStrings(ItT begin, ItT end, DelimiterT const & delimiter)