Merge branch 'hotfixes-1.0.1' of https://github.com/qPCR4vir/nana into qPCR4vir-hotfixes-1.0.1
This commit is contained in:
commit
92da2725c2
@ -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,53 +1162,48 @@ 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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (cistr.empty())
|
||||||
|
cistr.append(text.data(), text.size());
|
||||||
|
|
||||||
begin = text.data() + pos;
|
pos = cistr.find(ds.text.data(), pos);
|
||||||
end = begin + ds.text.size();
|
if (pos == cistr.npos)
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
|
||||||
if (cistr.empty())
|
|
||||||
cistr.append(text.data(), text.size());
|
|
||||||
|
|
||||||
pos = cistr.find(ds.text.data());
|
if (ds.whole_word_matched)
|
||||||
if (pos == cistr.npos)
|
{
|
||||||
continue;
|
if (!test_whole_word(pos, ds.text.size()))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ds.whole_word_matched)
|
auto ki = kwptr->schemes.find(ds.scheme);
|
||||||
{
|
if (ki != kwptr->schemes.end() && ki->second)
|
||||||
if (!test_whole_word(pos, ds.text.size()))
|
{
|
||||||
continue;
|
schemes_.emplace(ds.scheme, ki->second);
|
||||||
}
|
entities.emplace_back();
|
||||||
|
auto & last = entities.back();
|
||||||
begin = text.data() + pos;
|
last.begin = text.data() + pos;
|
||||||
end = begin + ds.text.size();
|
last.end = last.begin + ds.text.size();
|
||||||
}
|
last.scheme = ki->second.get();
|
||||||
|
}
|
||||||
auto ki = kwptr->schemes.find(ds.scheme);
|
}
|
||||||
if (ki != kwptr->schemes.end() && ki->second)
|
|
||||||
{
|
|
||||||
schemes_.emplace(ds.scheme, ki->second);
|
|
||||||
entities.emplace_back();
|
|
||||||
auto & last = entities.back();
|
|
||||||
last.begin = begin;
|
|
||||||
last.end = end;
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user