Rolf Meyer
/
slre
slre - Super Light Regular Expression library URL: http://slre.sourceforge.net/ Just ported to mbed.
main.cpp
- Committer:
- rolf
- Date:
- 2009-11-18
- Revision:
- 0:e0b85a04e7e5
File content as of revision 0:e0b85a04e7e5:
#include "mbed.h" #include "slre.h" DigitalOut led(LED1); /* class RegEx { RegEx(char *ex); match(char *str, Groups *) } */ int main() { char *buf = "GET /foo.bar?query=moo HTTP/1.5\r\n"; struct slre slre; struct cap captures[4 + 1]; if (!slre_compile(&slre, "^(GET|POST) (\\S+) HTTP/(\\S+?)\r\n")) { printf("Error compiling RE: %s\n", slre.err_str); } else if (!slre_match(&slre, buf, strlen(buf), captures)) { printf("Not a valid HTTP request\n" ); } else { printf("Request line length: %d\n", captures[0].len); printf("Method: %.*s\n", captures[1].len, captures[1].ptr); printf("URI: %.*s\n", captures[2].len, captures[2].ptr); } while(1) { led = !led; wait(0.2); } }