summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/re1.5/charclass.c
blob: c9df403750b51c559effd850a08ca3855fb3cbe9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "re1.5.h"

int _re1_5_classmatch(const char *pc, const char *sp)
{
    // pc points to "cnt" byte after opcode
    int is_positive = (pc[-1] == Class);
    int cnt = *pc++;
    while (cnt--) {
        if (*sp >= *pc && *sp <= pc[1]) return is_positive;
        pc += 2;
    }
    return !is_positive;
}