| 256 | |
| 257 | |
| 258 | static const char *classend (MatchState *ms, const char *p) { |
| 259 | switch (*p++) { |
| 260 | case L_ESC: { |
| 261 | if (p == ms->p_end) |
| 262 | luaL_error(ms->L, "malformed pattern (ends with '%%')"); |
| 263 | return p+1; |
| 264 | } |
| 265 | case '[': { |
| 266 | if (*p == '^') p++; |
| 267 | do { /* look for a ']' */ |
| 268 | if (p == ms->p_end) |
| 269 | luaL_error(ms->L, "malformed pattern (missing ']')"); |
| 270 | if (*(p++) == L_ESC && p < ms->p_end) |
| 271 | p++; /* skip escapes (e.g. '%]') */ |
| 272 | } while (*p != ']'); |
| 273 | return p+1; |
| 274 | } |
| 275 | default: { |
| 276 | return p; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | |
| 282 | static int match_class (int c, int cl) { |