fix exact match in find_idstr. (note: removed isalpha, isalnum already performs that check)
This commit is contained in:
parent
818c7459e7
commit
e5c14570cb
@ -2726,25 +2726,26 @@ namespace nana
|
|||||||
|
|
||||||
bool is_idchar(int ch)
|
bool is_idchar(int ch)
|
||||||
{
|
{
|
||||||
return ('_' == ch || isalpha(ch) || isalnum(ch));
|
return ('_' == ch || isalnum(ch));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t find_idstr(const std::string& text, const char* idstr, std::size_t off = 0)
|
std::size_t find_idstr(const std::string& text, const char* idstr, std::size_t off = 0)
|
||||||
{
|
{
|
||||||
const auto len = std::strlen(idstr);
|
const auto len = std::strlen(idstr);
|
||||||
auto pos = text.find(idstr, off);
|
size_t pos;
|
||||||
if (text.npos == pos)
|
while ((pos = text.find(idstr, off)) != text.npos)
|
||||||
return text.npos;
|
{
|
||||||
|
if (!is_idchar(text[pos + len]))
|
||||||
if (pos && is_idchar(text[pos - 1]))
|
{
|
||||||
return text.npos;
|
if (pos == 0 || !is_idchar(text[pos - 1]))
|
||||||
|
|
||||||
if ((pos + len < text.length()) && is_idchar(text[pos + len]))
|
|
||||||
return text.npos;
|
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
off = pos + len; // occurrence not found, advancing the offset and try again
|
||||||
|
}
|
||||||
|
return text.npos;
|
||||||
|
}
|
||||||
|
|
||||||
void update_div(std::string& div, const char* field, const char* attr, div_type insertion)
|
void update_div(std::string& div, const char* field, const char* attr, div_type insertion)
|
||||||
{
|
{
|
||||||
const auto fieldname_pos = find_idstr(div, field);
|
const auto fieldname_pos = find_idstr(div, field);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user