Internal matching routine.
440 DBG(
"%d:matchAt(tokenPos=%zu, str='%s', pos=%zu)\n",level,tokenPos,str.c_str(),pos);
441 auto isStartIdChar = [](
char c) {
return isalpha(c) || c==
'_'; };
443 auto matchCharClass = [
this,isStartIdChar,
isIdChar](
size_t tp,
char c) ->
bool
445 PToken tok =
data[tp];
447 uint16_t numFields = tok.value();
449 for (uint16_t i=0;i<numFields;i++)
464 uint16_t v =
static_cast<uint16_t
>(c);
465 if (tok.from()<=v && v<=tok.to())
472 DBG(
"matchCharClass(tp=%zu,c=%c (x%02x))=%d\n",tp,c,c,negate?!found:found);
473 return negate ? !found : found;
476 enum SequenceType { Star, Optional };
477 auto processSequence = [
this,&tokenPos,&index,&str,&matchCharClass,
478 &isStartIdChar,&
isIdChar,&
match,&level,&pos](SequenceType type) ->
bool
480 size_t startIndex = index;
481 PToken tok =
data[++tokenPos];
484 char c_tok = tok.asciiValue();
485 while (index<=str.length() && str[index]==c_tok) { index++;
if (type==Optional)
break; }
488 else if (tok.isCharClass())
490 while (index<=str.length() && matchCharClass(tokenPos,str[index])) { index++;
if (type==Optional)
break; }
491 tokenPos+=tok.value()+1;
495 while (index<=str.length() && isStartIdChar(str[index])) { index++;
if (type==Optional)
break; }
500 while (index<=str.length() &&
isIdChar(str[index])) { index++;
if (type==Optional)
break; }
505 while (index<=str.length() &&
isspace(str[index])) { index++;
if (type==Optional)
break; }
510 while (index<=str.length() &&
isdigit(str[index])) { index++;
if (type==Optional)
break; }
515 if (type==Optional) index++;
else index = str.length();
519 while ((
int)index>=(int)startIndex)
533 while (tokenPos<
data.size())
535 PToken tok =
data[tokenPos];
539 char c_tok = tok.asciiValue();
540 if (index>=str.length() || str[index]!=c_tok)
return false;
543 else if (tok.isCharClass())
545 if (index>=str.length() || !matchCharClass(tokenPos,str[index]))
return false;
546 index++,tokenPos+=tok.value()+1;
553 if (index>=str.length() || !isStartIdChar(str[index]))
return false;
557 if (index>=str.length() || !
isIdChar(str[index]))
return false;
561 if (index>=str.length() || !
isspace(str[index]))
return false;
565 if (index>=str.length() || !
isdigit(str[index]))
return false;
569 if (index!=pos)
return false;
572 if (index<str.length())
return false;
575 DBG(
"BeginOfWord: index=%zu isIdChar(%c)=%d prev.isIdChar(%c)=%d\n",
576 index,str[index],
isIdChar(str[index]),
577 index>0?str[index]-1:0,
579 if (index>=str.length() ||
581 (index>0 &&
isIdChar(str[index-1])))
return false;
584 DBG(
"EndOfWord: index=%zu pos=%zu idIdChar(%c)=%d prev.isIsChar(%c)=%d\n",
585 index,pos,str[index],
isIdChar(str[index]),
586 index==0 ? 0 : str[index-1],
587 index==0 ? -1 :
isIdChar(str[index-1]));
588 if (index<str.length() &&
589 (
isIdChar(str[index]) || index==0 || !
isIdChar(str[index-1])))
return false;
592 DBG(
"BeginCapture(%zu)\n",index);
593 match.startCapture(index);
596 DBG(
"EndCapture(%zu)\n",index);
597 match.endCapture(index);
600 if (index>=str.length())
return false;
604 return processSequence(Star);
606 return processSequence(Optional);
613 match.setMatch(pos,index-pos);