Back to index

glibc  2.9
bug-regex18.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   /* \xc4\xb0        LATIN CAPITAL LETTER I WITH DOT ABOVE
00037      \xc4\xb1        LATIN SMALL LETTER DOTLESS I
00038      \xe2\x80\x94    EM DASH  */
00039   { "\xc4\xb0I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
00040     { { 2, 8 }, { -1, -1 } } },
00041   { "[\xc4\xb0x]I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
00042     { { 2, 8 }, { -1, -1 } } },
00043   { "[^x]I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
00044     { { 2, 8 }, { -1, -1 } } },
00045   { "([[:alpha:]]i[[:xdigit:]])(\xc4\xb1*)(\xc4\xb0{2})",
00046     "\xe2\x80\x94\xc4\xb1\xc4\xb0""fIi\xc4\xb0ii", REG_ICASE | REG_EXTENDED,
00047     4, { { 3, 12 }, { 3, 8 }, { 8, 9 }, { 9, 12 } } },
00048   { "\xc4\xb1i(i)*()(\\s\xc4\xb0|\\SI)", "SIi\xc4\xb0\xc4\xb0 is",
00049     REG_ICASE | REG_EXTENDED, 4, { { 1, 9 }, { 5, 7 }, { 7, 7 }, { 7, 9 } } },
00050   { "\xc4\xb1i(i)*()(\\s\xc4\xb0|\\SI)", "\xc4\xb1\xc4\xb0\xc4\xb0iJ\xc4\xb1",
00051     REG_ICASE | REG_EXTENDED, 4,
00052     { { 0, 10 }, { 6, 7 }, { 7, 7 }, { 7, 10 } } },
00053 };
00054 
00055 int
00056 main (void)
00057 {
00058   regex_t re;
00059   regmatch_t rm[5];
00060   size_t i;
00061   int n, ret = 0;
00062 
00063   setlocale (LC_ALL, "tr_TR.UTF-8");
00064   for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
00065     {
00066       n = regcomp (&re, tests[i].pattern, tests[i].flags);
00067       if (n != 0)
00068        {
00069          char buf[500];
00070          regerror (n, &re, buf, sizeof (buf));
00071          printf ("regcomp %zd failed: %s\n", i, buf);
00072          ret = 1;
00073          continue;
00074        }
00075 
00076       if (regexec (&re, tests[i].string, tests[i].nmatch, rm, 0))
00077        {
00078          printf ("regexec %zd failed\n", i);
00079          ret = 1;
00080          regfree (&re);
00081          continue;
00082        }
00083 
00084       for (n = 0; n < tests[i].nmatch; ++n)
00085        if (rm[n].rm_so != tests[i].rm[n].rm_so
00086               || rm[n].rm_eo != tests[i].rm[n].rm_eo)
00087          {
00088            if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
00089              break;
00090            printf ("regexec match failure rm[%d] %d..%d\n",
00091                   n, rm[n].rm_so, rm[n].rm_eo);
00092            ret = 1;
00093            break;
00094          }
00095 
00096       regfree (&re);
00097     }
00098 
00099   return ret;
00100 }