| 1 |
/*************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* Language Technologies Institute */ |
| 4 |
/* Carnegie Mellon University */ |
| 5 |
/* Copyright (c) 1999 */ |
| 6 |
/* All Rights Reserved. */ |
| 7 |
/* */ |
| 8 |
/* Permission is hereby granted, free of charge, to use and distribute */ |
| 9 |
/* this software and its documentation without restriction, including */ |
| 10 |
/* without limitation the rights to use, copy, modify, merge, publish, */ |
| 11 |
/* distribute, sublicense, and/or sell copies of this work, and to */ |
| 12 |
/* permit persons to whom this work is furnished to do so, subject to */ |
| 13 |
/* the following conditions: */ |
| 14 |
/* 1. The code must retain the above copyright notice, this list of */ |
| 15 |
/* conditions and the following disclaimer. */ |
| 16 |
/* 2. Any modifications must be clearly marked as such. */ |
| 17 |
/* 3. Original authors' names are not deleted. */ |
| 18 |
/* 4. The authors' names are not used to endorse or promote products */ |
| 19 |
/* derived from this software without specific prior written */ |
| 20 |
/* permission. */ |
| 21 |
/* */ |
| 22 |
/* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */ |
| 23 |
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ |
| 24 |
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ |
| 25 |
/* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */ |
| 26 |
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ |
| 27 |
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ |
| 28 |
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ |
| 29 |
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ |
| 30 |
/* THIS SOFTWARE. */ |
| 31 |
/* */ |
| 32 |
/*************************************************************************/ |
| 33 |
/* Author: Alan W Black ([email protected]) */ |
| 34 |
/* Date: January 2000 */ |
| 35 |
/*************************************************************************/ |
| 36 |
/* */ |
| 37 |
/* Various regex tests */ |
| 38 |
/* */ |
| 39 |
/*************************************************************************/ |
| 40 |
#include <stdio.h> |
| 41 |
#include "cst_regex.h" |
| 42 |
|
| 43 |
char *rtests[] = { |
| 44 |
"1", |
| 45 |
" \n ", |
| 46 |
"hello", |
| 47 |
"Hello", |
| 48 |
"1and2", |
| 49 |
"oneandtwo", |
| 50 |
"-1.34", |
| 51 |
"235", |
| 52 |
"034", |
| 53 |
"1,234,235", |
| 54 |
"1,2345", |
| 55 |
NULL }; |
| 56 |
|
| 57 |
int main(int argc, char **argv) |
| 58 |
{ |
| 59 |
int i; |
| 60 |
cst_regex *commaint; |
| 61 |
|
| 62 |
commaint = new_cst_regex("[0-9][0-9]?[0-9]?,\\([0-9][0-9][0-9],\\)*[0-9][0-9][0-9]\\(\\.[0-9]+\\)?"); |
| 63 |
|
| 64 |
for (i=0; rtests[i]; i++) |
| 65 |
{ |
| 66 |
printf("\"%s\"\n",rtests[i]); |
| 67 |
printf(" %.8s %c\n", |
| 68 |
"white",(cst_regex_match(cst_rx_white,rtests[i]) ? 't' : 'f')); |
| 69 |
printf(" %.8s %c\n", |
| 70 |
"alpha",(cst_regex_match(cst_rx_alpha,rtests[i]) ? 't' : 'f')); |
| 71 |
printf(" %.8s %c\n", |
| 72 |
"upper", |
| 73 |
(cst_regex_match(cst_rx_uppercase,rtests[i]) ? 't' : 'f')); |
| 74 |
printf(" %.8s %c\n", |
| 75 |
"lower", |
| 76 |
(cst_regex_match(cst_rx_lowercase,rtests[i]) ? 't' : 'f')); |
| 77 |
printf(" %.8s %c\n", |
| 78 |
"alphanum", |
| 79 |
(cst_regex_match(cst_rx_alphanum,rtests[i]) ? 't' : 'f')); |
| 80 |
printf(" %.8s %c\n", |
| 81 |
"ident", |
| 82 |
(cst_regex_match(cst_rx_identifier,rtests[i]) ? 't' : 'f')); |
| 83 |
printf(" %.8s %c\n", |
| 84 |
"int", |
| 85 |
(cst_regex_match(cst_rx_int,rtests[i]) ? 't' : 'f')); |
| 86 |
printf(" %.8s %c\n", |
| 87 |
"double", |
| 88 |
(cst_regex_match(cst_rx_double,rtests[i]) ? 't' : 'f')); |
| 89 |
printf(" %.8s %c\n", |
| 90 |
"commaint", |
| 91 |
(cst_regex_match(commaint,rtests[i]) ? 't' : 'f')); |
| 92 |
} |
| 93 |
|
| 94 |
delete_cst_regex(commaint); |
| 95 |
|
| 96 |
return 0; |
| 97 |
} |