| 1 | #include "re1.5.h" |
| 2 | |
| 3 | int _re1_5_classmatch(const char *pc, const char *sp) |
| 4 | { |
| 5 | // pc points to "cnt" byte after opcode |
| 6 | int is_positive = (pc[-1] == Class); |
| 7 | int cnt = *pc++; |
| 8 | while (cnt--) { |
| 9 | if (*sp >= *pc && *sp <= pc[1]) return is_positive; |
| 10 | pc += 2; |
| 11 | } |
| 12 | return !is_positive; |
| 13 | } |
| 14 | |
| 15 | int _re1_5_namedclassmatch(const char *pc, const char *sp) |
| 16 | { |
| 17 | // pc points to name of class |
| 18 | int off = (*pc >> 5) & 1; |
| 19 | if ((*pc | 0x20) == 'd') { |
| 20 | if (!(*sp >= '0' && *sp <= '9')) { |
| 21 | off ^= 1; |
| 22 | } |
| 23 | } else if ((*pc | 0x20) == 's') { |
| 24 | if (!(*sp == ' ' || (*sp >= '\t' && *sp <= '\r'))) { |
| 25 | off ^= 1; |
| 26 | } |
| 27 | } else { // w |
| 28 | if (!((*sp >= 'A' && *sp <= 'Z') || (*sp >= 'a' && *sp <= 'z') || (*sp >= '0' && *sp <= '9') || *sp == '_')) { |
| 29 | off ^= 1; |
| 30 | } |
| 31 | } |
| 32 | return off; |
| 33 | } |
| 34 | |