@@ -1165,7 +1165,7 @@ namespace attributes {
11651165
11661166 // Now read into a list of strings (which we can pass to regexec)
11671167 // First read into a std::deque (which will handle lots of append
1168- // operations efficiently) then copy into an R chracter vector
1168+ // operations efficiently) then copy into an R character vector
11691169 std::deque<std::string> lines;
11701170 readLines (buffer, &lines);
11711171 lines_ = Rcpp::wrap (lines);
@@ -1590,27 +1590,44 @@ namespace attributes {
15901590
15911591 int templateCount = 0 ;
15921592 int parenCount = 0 ;
1593- bool insideQuotes = false ;
15941593 std::string currentArg;
15951594 std::vector<std::string> args;
1596- char prevChar = 0 ;
1597- for (std::string::const_iterator
1598- it = argText. begin (); it != argText. end (); ++it) {
1599- char ch = *it;
1595+ char quote = 0 ;
1596+ bool escaped = false ;
1597+ typedef std::string::const_iterator it_t ;
1598+ for ( it_t it = argText. begin (); it != argText. end (); ++it) {
16001599
1601- if (ch == ' "' && prevChar != ' \\ ' ) {
1602- insideQuotes = !insideQuotes;
1603- }
1600+ // Store current character
1601+ char ch = *it;
16041602
1605- if ((ch == ' ,' ) &&
1603+ // Ignore quoted strings and character values in single quotes
1604+ if ( ! quote && (ch == ' "' || ch == ' \' ' ))
1605+ quote = ch;
1606+ else if (quote && ch == quote && ! escaped)
1607+ quote = 0 ;
1608+
1609+ // Escaped character inside quotes
1610+ if (escaped)
1611+ escaped = false ;
1612+ else if (quote && ch == ' \\ ' )
1613+ escaped = true ;
1614+
1615+ // Detect end of argument declaration
1616+ if ( ! quote &&
1617+ (ch == ' ,' ) &&
16061618 (templateCount == 0 ) &&
1607- (parenCount == 0 ) &&
1608- !insideQuotes) {
1619+ (parenCount == 0 )) {
16091620 args.push_back (currentArg);
16101621 currentArg.clear ();
16111622 continue ;
1612- } else {
1623+ }
1624+
1625+ // Append current character if not a space at start
1626+ if ( ! currentArg.empty () || ch != ' ' )
16131627 currentArg.push_back (ch);
1628+
1629+ // Count use of potentially enclosed brackets
1630+ if ( ! quote) {
16141631 switch (ch) {
16151632 case ' <' :
16161633 templateCount++;
@@ -1626,8 +1643,6 @@ namespace attributes {
16261643 break ; // #nocov
16271644 }
16281645 }
1629-
1630- prevChar = ch;
16311646 }
16321647
16331648 if (!currentArg.empty ())
0 commit comments