On Nov 25, 2008, at 3:56 AM, fairesigneaumachiniste wrote:
> As standard C does not come with a regular expressions library (as
> far as I know) so what would be the best way to implement these
> expressions I use in the regexp object:
I could suggest you use the PCRE library (
http://www.pcre.org), which
is what the regexp max object does, but if the max regexp object is
slow, then you will not see any performance improvement in your own
object which uses PCRE. So what would I suggest? A tight string
walking function of your own. or sscanf/strtok/etc might be useful if
you have a decent expectation of what the input is like.
From your simple example you probably can do something along the
lines of the following quicko email client code
void stripnumber(char *dst, const char *src)
{
char c;
// keep numbers, spaces, and periods
// strip everything else
while (c = *src++) {
switch (c) {
case ' ':
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
*dst++ = c; // copy char from input to output
break;
default:
//skip
}
}
*dst = ''; // null terminate output
}
You can also get into finite automata implementations for regular
expressions which can be much faster than the typical backtracking
algorithms like perl and pcre use. Here's one reasonably clear paper
on the subject with code samples if you're feeling really nerdy.
If you get deeper into string processing in C, you'll also need to pay
attention to UTF-8 unicode representation as well if you want to
handle non ASCII characters:
Hope this gets you started. If you have further questions about this
stuff, I'd suggest you search online. Obviously lots of info out there.
-Joshua