Quote:
> Does anyone know of source code for matching templates against input strings
> like "AAA-AAA-####" against a string, etc. Thanks for any pointers.
User interface toolkits sometimes have stuff like this, to
validate the input as the user is typing it (the best place to do
it, IMHO), but for simple templates like the one you have there,
it should be fairly easy to write your own. For example...
int jeff(sp,tp) /*======================================*/
char *sp;
char *tp;
{
while (*tp && *sp) {
switch (*tp) {
case ('A'):
if (!isalpha(*sp)) return(0);
break;
case ('#'):
if (!isdigit(*sp)) return(0);
break;
default:
if (*tp != *sp) return(0);
}
tp++;
sp++;
}
if (*tp || *sp) return(0);
return(1);
}
You don't have to test for *sp in the loop condition, or for *tp
in the last if statement, if you can trust the code in each case
statement to do the right thing when *sp is zero.
--
*** "Puppet Boy, it's the little things that count" - DEVO ***