Back to index

glibc  2.9
bug-regex17.c
Go to the documentation of this file.
00001 /* Turkish regular expression tests.
00002    Copyright (C) 2002, 2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <sys/types.h>
00022 #include <mcheck.h>
00023 #include <regex.h>
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <locale.h>
00027 
00028 /* Tests supposed to match.  */
00029 struct
00030 {
00031   const char *pattern;
00032   const char *string;
00033   int flags, nmatch;
00034   regmatch_t rm[5];
00035 } tests[] = {
00036   /* \xc3\x84 LATIN CAPITAL LETTER A WITH DIAERESIS
00037      \xc3\x96 LATIN CAPITAL LETTER O WITH DIAERESIS
00038      \xc3\xa4 LATIN SMALL LETTER A WITH DIAERESIS
00039      \xc3\xb6 LATIN SMALL LETTER O WITH DIAERESIS  */
00040   { "\xc3\x84\xc3\x96*\xc3\xb6$", "aB\xc3\xa4\xc3\xb6\xc3\xb6\xc3\x96", REG_ICASE, 2,
00041     { { 2, 10 }, { -1, -1 } } },
00042   { "[\xc3\x84x]\xc3\x96*\xc3\xb6$", "aB\xc3\x84\xc3\xb6\xc3\xb6\xc3\x96", REG_ICASE, 2,
00043     { { 2, 10 }, { -1, -1 } } },
00044   { "[\xc3\x84x]\xc3\x96*\xc3\xb6$", "aB\xc3\xa4\xc3\xb6\xc3\xb6\xc3\x96", REG_ICASE, 2,
00045     { { 2, 10 }, { -1, -1 } } },
00046   { "[^x]\xc3\x96*\xc3\xb6$", "aB\xc3\xa4\xc3\xb6\xc3\xb6\xc3\x96", REG_ICASE, 2,
00047     { { 2, 10 }, { -1, -1 } } },
00048 };
00049 
00050 int
00051 main (void)
00052 {
00053   regex_t re;
00054   regmatch_t rm[5];
00055   size_t i;
00056   int n, ret = 0;
00057 
00058   setlocale (LC_ALL, "de_DE.UTF-8");
00059   for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
00060     {
00061       n = regcomp (&re, tests[i].pattern, tests[i].flags);
00062       if (n != 0)
00063        {
00064          char buf[500];
00065          regerror (n, &re, buf, sizeof (buf));
00066          printf ("regcomp %zd failed: %s\n", i, buf);
00067          ret = 1;
00068          continue;
00069        }
00070 
00071       if (regexec (&re, tests[i].string, tests[i].nmatch, rm, 0))
00072        {
00073          printf ("regexec %zd failed\n", i);
00074          ret = 1;
00075          regfree (&re);
00076          continue;
00077        }
00078 
00079       for (n = 0; n < tests[i].nmatch; ++n)
00080        if (rm[n].rm_so != tests[i].rm[n].rm_so
00081               || rm[n].rm_eo != tests[i].rm[n].rm_eo)
00082          {
00083            if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
00084              break;
00085            printf ("regexec match failure rm[%d] %d..%d\n",
00086                   n, rm[n].rm_so, rm[n].rm_eo);
00087            ret = 1;
00088            break;
00089          }
00090 
00091       regfree (&re);
00092     }
00093 
00094   return ret;
00095 }