Skip to content

Commit

Permalink
Remove regex in CFGNormalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
TalbenXu committed Dec 20, 2024
1 parent 0f3f2c6 commit b87cf59
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions svf/lib/CFL/CFGNormalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,20 @@ void CFGNormalizer::ebnfSignReplace(char sign, CFGrammar *grammar)

void CFGNormalizer::strTrans(std::string LHS, CFGrammar *grammar, GrammarBase::Production& normalProd)
{
std::smatch matches;
std::regex LHSReg("\\s*(.*)");
// Find the position of the first non-whitespace character
size_t start = LHS.find_first_not_of(" \t\n\r");
// If the string contains non-whitespace characters, remove leading spaces
if (start != std::string::npos) {
LHS = LHS.substr(start);
} else {
// If the string contains only spaces, clear it
LHS.clear();
}

std::string delimiter;
size_t pos;
std::string word;
std::regex_search(LHS, matches, LHSReg);
LHS = matches.str(1);

delimiter = " ";
while ((pos = LHS.find(delimiter)) != std::string::npos)
{
Expand All @@ -454,6 +461,7 @@ void CFGNormalizer::strTrans(std::string LHS, CFGrammar *grammar, GrammarBase::P
normalProd.push_back(grammar->strToSymbol(LHS));
}


GrammarBase::Symbol CFGNormalizer::check_head(GrammarBase::SymbolMap<GrammarBase::Symbol, GrammarBase::Productions> &grammar, GrammarBase::Production &rule)
{
for(auto symProdPair: grammar)
Expand Down

0 comments on commit b87cf59

Please sign in to comment.