kokke / tiny-regex-c

Small portable regex in C
The Unlicense
1.23k stars 175 forks source link

Fix GH79 (on top of PR#78 fixes) #80

Closed rurban closed 1 year ago

rurban commented 2 years ago

fix ranges with ending -

Fixes GH #79 and the exreg failures with [1-5-]+[-1-2]-[-]

torstenvl commented 2 years ago

Please merge, this fixes a large number of failing tests.

static int matchcharclass(char c, const char* str)
{
  do
  {
    if (matchrange(c, str))
    {
      return 1;
    }
    else if (str[0] == '\\')
    {
      /* Escape-char: increment str-ptr and match on next char */
      str += 1;
      if (matchmetachar(c, str))
      {
        return 1;
      }
      else if ((c == str[0]) && !ismetachar(c))
      {
        return 1;
      }
    }
    else if (c == str[0])
    {
      if (c == '-')
      {
        if ((str[-1] == '\0') || (str[1] == '\0')) return 1; else continue;
      }
      else
      {
        return 1;
      }
    }
  }
  while (*str++ != '\0');

  return 0;
}