Skip to content

Commit

Permalink
Ruby parser: refactored advanceWhile
Browse files Browse the repository at this point in the history
  • Loading branch information
tambeta committed Apr 10, 2018
1 parent ce85524 commit ceaa167
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions parsers/ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,19 @@ static bool isWhitespace (int c)
*/
static bool advanceWhile (const unsigned char** s, bool (*predicate) (int))
{
const int s_length = strlen ((const char *)*s);
unsigned char this_char;
int i = 0;
const unsigned char* original_pos = *s;

for (i = 0; i < s_length; ++i)
while (**s != '\0')
{
this_char = **s;

if (! predicate (this_char))
if (! predicate (**s))
{
return i > 0;
return *s != original_pos;
}

(*s)++;
}

return i > 0;
return *s != original_pos;
}

static bool canMatchKeyword (const unsigned char** s, const char* literal)
Expand Down Expand Up @@ -235,7 +231,7 @@ static bool parseRubyOperator (vString* name, const unsigned char** cp)
{
if (canMatch (cp, RUBY_OPERATORS[i], notOperatorChar))
{
vStringCatS (name, RUBY_OPERATORS[i]);
vStringCatS (name, RUBY_OPERATORS[i]);
return true;
}
}
Expand Down

0 comments on commit ceaa167

Please sign in to comment.