Merge branch 'hotfixes-1.0.1' of https://github.com/qPCR4vir/nana into qPCR4vir-hotfixes-1.0.1

This commit is contained in:
Jinhao 2015-03-27 00:23:31 +08:00
commit 92da2725c2

View File

@ -1133,12 +1133,14 @@ namespace nana{ namespace widgets
public: public:
void parse(const ::nana::string& text, const keywords* kwptr) void parse(const ::nana::string& text, const keywords* kwptr)
{ {
if (text.empty()) if ( kwptr->kwbase.empty() || text.empty() )
return; return;
using index = ::nana::string::size_type;
std::vector<entity> entities; std::vector<entity> entities;
auto test_whole_word = [&text](std::size_t pos, std::size_t len) auto test_whole_word = [&text](index pos, index len)
{ {
if (pos) if (pos)
{ {
@ -1160,41 +1162,35 @@ namespace nana{ namespace widgets
::nana::cistring cistr; ::nana::cistring cistr;
for (auto & ds : kwptr->kwbase) for (auto & ds : kwptr->kwbase)
{ {
std::size_t pos; index pos{0} ;
const ::nana::char_t* begin; for (index rest{text.size()}; rest >= ds.text.size() ; ++pos, rest = text.size() - pos)
const ::nana::char_t* end; {
if (ds.case_sensitive) if (ds.case_sensitive)
{ {
pos = text.find(ds.text); pos = text.find(ds.text, pos);
if (pos == text.npos) if (pos == text.npos)
continue; break;
if (ds.whole_word_matched) if (ds.whole_word_matched)
{ {
if (!test_whole_word(pos, ds.text.size())) if (!test_whole_word(pos, ds.text.size()))
continue; continue;
} }
begin = text.data() + pos;
end = begin + ds.text.size();
} }
else else
{ {
if (cistr.empty()) if (cistr.empty())
cistr.append(text.data(), text.size()); cistr.append(text.data(), text.size());
pos = cistr.find(ds.text.data()); pos = cistr.find(ds.text.data(), pos);
if (pos == cistr.npos) if (pos == cistr.npos)
continue; break;
if (ds.whole_word_matched) if (ds.whole_word_matched)
{ {
if (!test_whole_word(pos, ds.text.size())) if (!test_whole_word(pos, ds.text.size()))
continue; continue;
} }
begin = text.data() + pos;
end = begin + ds.text.size();
} }
auto ki = kwptr->schemes.find(ds.scheme); auto ki = kwptr->schemes.find(ds.scheme);
@ -1203,10 +1199,11 @@ namespace nana{ namespace widgets
schemes_.emplace(ds.scheme, ki->second); schemes_.emplace(ds.scheme, ki->second);
entities.emplace_back(); entities.emplace_back();
auto & last = entities.back(); auto & last = entities.back();
last.begin = begin; last.begin = text.data() + pos;
last.end = end; last.end = last.begin + ds.text.size();
last.scheme = ki->second.get(); last.scheme = ki->second.get();
} }
}
} }
if (!entities.empty()) if (!entities.empty())
@ -1221,7 +1218,7 @@ namespace nana{ namespace widgets
while(i != entities.end()) while(i != entities.end())
{ {
if (previous->end > i->begin) if (previous->end > i->begin)
i = entities.erase(i); i = entities.erase(i); // erase overlaping. Left only the first.
else else
++i; ++i;
} }