cooperative-computing-lab/cctools — pull request #520 by batrick (2014-07-31 22:07:27+00:00)
Title: Add advanced pattern matching facilities.

This commit some much more advanced pattern matching facilities to CCTools. The
pattern matcher is pulled from Lua 5.2 source code. Lua's pattern matching is
documented in [1]. Lua is distributed under the MIT license which is GPLv2
compatible.

The total lines of code are:

$ wc -l dttools/src/pattern.c dttools/src/luapatt.c dttools/src/pattern.h
78 dttools/src/pattern.c
329 dttools/src/luapatt.c
25 dttools/src/pattern.h
432 total

Which is a pretty small price for what it gives us. For example, we can now do:

char *number;
ptrdiff_t where = string_match(subject, "^option%s*=%s*(%d+)$", &number);
int i = atoi(number);
free(number);

[1] http://www.lua.org/manual/5.2/manual.html#6.4.1