Skip to content

Commit

Permalink
Turns out single quoted text is allowed too in D3 GUIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 19, 2017
1 parent 94d890c commit 0739f21
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions libs/parser/CodeTokeniser.h
Expand Up @@ -89,10 +89,18 @@ class CodeTokeniserFunc
// Clear out the token, no guarantee that it is empty
tok = "";

while (next != end) {
enum class QuoteType
{
Single = 0,
Double = 1,
};

switch (_state) {
QuoteType quoteType = QuoteType::Single;

while (next != end)
{
switch (_state)
{
case SEARCHING:

// If we have a delimiter, just advance to the next character
Expand Down Expand Up @@ -128,8 +136,8 @@ class CodeTokeniserFunc

// Now next is pointing at a non-delimiter. Switch on this
// character.
switch (*next) {

switch (*next)
{
// Found a quote, enter QUOTED state, or return the
// current token if we are in the process of building
// one.
Expand All @@ -138,11 +146,23 @@ class CodeTokeniserFunc
return true;
}
else {
quoteType = QuoteType::Double;
_state = QUOTED;
++next;
continue; // skip the quote
}

case '\'':
if (tok != "") {
return true;
}
else {
quoteType = QuoteType::Single;
_state = QUOTED;
++next;
continue; // skip the quote
}

// Found a slash, possibly start of comment
case '/':
_state = FORWARDSLASH;
Expand Down Expand Up @@ -241,7 +261,9 @@ class CodeTokeniserFunc

// In the quoted state, just advance until the closing
// quote. No delimiter splitting is required.
if (*next == '\"') {
if (*next == '\"' && quoteType == QuoteType::Double ||
*next == '\'' && quoteType == QuoteType::Single)
{
++next;

// greebo: We've found a closing quote, but there might be a backslash indicating
Expand All @@ -264,7 +286,11 @@ class CodeTokeniserFunc
{
tok += '\t';
}
else if (*next == '"') // Quote
else if (*next == '"' && quoteType == QuoteType::Double) // Escape Double Quote
{
tok += '"';
}
else if (*next == '\'' && quoteType == QuoteType::Single) // Escaped Single Quote
{
tok += '"';
}
Expand Down Expand Up @@ -321,7 +347,9 @@ class CodeTokeniserFunc
continue;
}

if (*next == '\"') {
if (*next == '\"' && quoteType == QuoteType::Double ||
*next == '\'' && quoteType == QuoteType::Single)
{
// Found the desired opening quote, switch to QUOTED
++next;
_state = QUOTED;
Expand Down

0 comments on commit 0739f21

Please sign in to comment.