static int ft_modlen(const char *s, int (*is_x)(char)) { int i; i = 0; while (!is_x(s[i]) && s[i] != 0) i++; return (i); }
static int ft_todo(const char *s, int (*is_x)(char)) { int i; int cp; i = 0; cp = 0; while (s[i] != 0) { if (!is_x(s[i])) { cp++; while (!is_x(s[i]) && s[i] != 0) i++; } if (s[i] != 0) i++; } return (cp); }
int regex_parser::process_escape(const char *re, int ptr, int_set *chars){ if (ptr==strlen(re)){ return (++ptr); //fatal("regex_parser:: process_escape: \\ in last position."); } char c=re[ptr]; int next; if(is_x(c)){ if(ptr>strlen(re)-3) fatal("regex_parser::process_escape: invalid hex escape sequence."); else if (!is_hex_digit(re[ptr+1]) || !is_hex_digit(re[ptr+2])) fatal("regex_parser::process_escape: invalid hex escape sequence."); else{ char tmp[5]; tmp[0]='0';tmp[1]=c;tmp[2]=re[ptr+1];tmp[3]=re[ptr+2]; tmp[4]='\0'; sscanf(tmp,"0x%x", &next); chars->insert(next); ptr=ptr+3; } }else if (is_oct_digit(c)){ if(ptr>strlen(re)-3) {next=escaped(c);ptr++;chars->insert(next);} //normal escape sequence else if (!is_oct_digit(re[ptr+1]) || !is_oct_digit(re[ptr+2])) {next=escaped(c);ptr++;chars->insert(next);} //normal escape sequence else{ //really an octal sequence! char tmp[5]; tmp[0]='0';tmp[1]=c;tmp[2]=re[ptr+1];tmp[3]=re[ptr+2]; tmp[4]='\0'; sscanf(tmp,"0%o", &next); chars->insert(next); ptr=ptr+3; } }else if(c=='s'){ chars->insert('\t'); chars->insert('\n'); chars->insert('\r'); chars->insert('\x0C'); chars->insert('\x20'); ptr++; }else if(c=='S'){ chars->insert('\t'); chars->insert('\n'); chars->insert('\r'); chars->insert('\x0C'); chars->insert('\x20'); chars->negate(); ptr++; }else if(c=='d'){ chars->insert('0');chars->insert('1');chars->insert('2'); chars->insert('3');chars->insert('4');chars->insert('5'); chars->insert('6');chars->insert('7');chars->insert('8'); chars->insert('9'); ptr++; }else if(c=='D'){ chars->insert('0');chars->insert('1');chars->insert('2'); chars->insert('3');chars->insert('4');chars->insert('5'); chars->insert('6');chars->insert('7');chars->insert('8'); chars->insert('9'); chars->negate(); ptr++; }else if(c=='w'){ chars->insert('_'); chars->insert('0');chars->insert('1');chars->insert('2'); chars->insert('3');chars->insert('4');chars->insert('5'); chars->insert('6');chars->insert('7');chars->insert('8'); chars->insert('9'); chars->insert('a');chars->insert('b');chars->insert('c'); chars->insert('d');chars->insert('e');chars->insert('f'); chars->insert('g');chars->insert('h');chars->insert('i'); chars->insert('j');chars->insert('k');chars->insert('l'); chars->insert('m');chars->insert('n');chars->insert('o'); chars->insert('p');chars->insert('q');chars->insert('r'); chars->insert('s');chars->insert('t');chars->insert('u'); chars->insert('v');chars->insert('w');chars->insert('x'); chars->insert('y');chars->insert('z'); chars->insert('A');chars->insert('B');chars->insert('C'); chars->insert('D');chars->insert('E');chars->insert('F'); chars->insert('G');chars->insert('H');chars->insert('I'); chars->insert('J');chars->insert('K');chars->insert('L'); chars->insert('M');chars->insert('N');chars->insert('O'); chars->insert('P');chars->insert('Q');chars->insert('R'); chars->insert('S');chars->insert('T');chars->insert('U'); chars->insert('V');chars->insert('W');chars->insert('X'); chars->insert('Y');chars->insert('Z'); ptr++; }else if(c=='W'){ chars->insert('_'); chars->insert('0');chars->insert('1');chars->insert('2'); chars->insert('3');chars->insert('4');chars->insert('5'); chars->insert('6');chars->insert('7');chars->insert('8'); chars->insert('9'); chars->insert('a');chars->insert('b');chars->insert('c'); chars->insert('d');chars->insert('e');chars->insert('f'); chars->insert('g');chars->insert('h');chars->insert('i'); chars->insert('j');chars->insert('k');chars->insert('l'); chars->insert('m');chars->insert('n');chars->insert('o'); chars->insert('p');chars->insert('q');chars->insert('r'); chars->insert('s');chars->insert('t');chars->insert('u'); chars->insert('v');chars->insert('w');chars->insert('x'); chars->insert('y');chars->insert('z'); chars->insert('A');chars->insert('B');chars->insert('C'); chars->insert('D');chars->insert('E');chars->insert('F'); chars->insert('G');chars->insert('H');chars->insert('I'); chars->insert('J');chars->insert('K');chars->insert('L'); chars->insert('M');chars->insert('N');chars->insert('O'); chars->insert('P');chars->insert('Q');chars->insert('R'); chars->insert('S');chars->insert('T');chars->insert('U'); chars->insert('V');chars->insert('W');chars->insert('X'); chars->insert('Y');chars->insert('Z'); chars->negate(); ptr++; }else{ next=escaped(c); chars->insert(next); ptr++; } return ptr; }