regex_test_main.c 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 (awb@cs.cmu.edu) */
  34. /* Date: January 2000 */
  35. /*************************************************************************/
  36. /* */
  37. /* Various regex tests */
  38. /* */
  39. /*************************************************************************/
  40. #include <stdio.h>
  41. #include "cst_regex.h"
  42. char *rtests[] = {
  43. "1",
  44. " \n ",
  45. "hello",
  46. "Hello",
  47. "1and2",
  48. "oneandtwo",
  49. "-1.34",
  50. "235",
  51. "034",
  52. "1,234,235",
  53. "1,2345",
  54. NULL };
  55. int main(int argc, char **argv)
  56. {
  57. int i;
  58. cst_regex *commaint;
  59. commaint = new_cst_regex("[0-9][0-9]?[0-9]?,\\([0-9][0-9][0-9],\\)*[0-9][0-9][0-9]\\(\\.[0-9]+\\)?");
  60. for (i=0; rtests[i]; i++)
  61. {
  62. printf("\"%s\"\n",rtests[i]);
  63. printf(" %.8s %c\n",
  64. "white",(cst_regex_match(cst_rx_white,rtests[i]) ? 't' : 'f'));
  65. printf(" %.8s %c\n",
  66. "alpha",(cst_regex_match(cst_rx_alpha,rtests[i]) ? 't' : 'f'));
  67. printf(" %.8s %c\n",
  68. "upper",
  69. (cst_regex_match(cst_rx_uppercase,rtests[i]) ? 't' : 'f'));
  70. printf(" %.8s %c\n",
  71. "lower",
  72. (cst_regex_match(cst_rx_lowercase,rtests[i]) ? 't' : 'f'));
  73. printf(" %.8s %c\n",
  74. "alphanum",
  75. (cst_regex_match(cst_rx_alphanum,rtests[i]) ? 't' : 'f'));
  76. printf(" %.8s %c\n",
  77. "ident",
  78. (cst_regex_match(cst_rx_identifier,rtests[i]) ? 't' : 'f'));
  79. printf(" %.8s %c\n",
  80. "int",
  81. (cst_regex_match(cst_rx_int,rtests[i]) ? 't' : 'f'));
  82. printf(" %.8s %c\n",
  83. "double",
  84. (cst_regex_match(cst_rx_double,rtests[i]) ? 't' : 'f'));
  85. printf(" %.8s %c\n",
  86. "commaint",
  87. (cst_regex_match(commaint,rtests[i]) ? 't' : 'f'));
  88. }
  89. delete_cst_regex(commaint);
  90. return 0;
  91. }