2 * Copyright (C) 2004 Jesus Gimenez, Lluis Marquez and Senen Moya
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /*****************************************************************
24 *****************************************************************/
26 regex_t erCard
,erCardPunct
,erCardSeps
,erCardSuffix
;
27 regex_t erMultiWord
,erContainNum
,erStartCap
,erStartLower
,erStartNumber
,
28 erAllUp
,erAllLow
,erContainCap
,erContainCaps
,erContainPeriod
,erContainComma
;
30 /**************************************************/
32 #define ER_STARTCAP "^[A-Z\307\321\301\311\315\323\332\300\310\314\322\331\304\313\317\326\334].*$"
33 #define ER_STARTLOWER "^[a-z\347\361\341\351\355\363\372\340\350\354\362\371\344\353\357\366\374].*$"
34 #define ER_STARTNUMBER "^[0-9].*$"
35 #define ER_ALLUP "^[A-Z\307\321\301\311\315\323\332\300\310\314\322\331\304\313\317\326\334]+$"
36 #define ER_ALLLOW "^[a-z\347\361\341\351\355\363\372\340\350\354\362\371\344\353\357\366\374]+$"
37 #define ER_CONTAINCAP "^.+[A-Z\307\321\301\311\315\323\332\300\310\314\322\331\304\313\317\326\334].*$"
38 #define ER_CONTAINCAPS "^.*[A-Z\307\321\301\311\315\323\332\300\310\314\322\331\304\313\317\326\334].*[A-Z\307\321\301\311\315\323\332\300\310\314\322\331\304\313\317\326\334].*$"
39 #define ER_CONTAINPERIOD "^.*[.].*$"
40 #define ER_CONTAINCOMMA "^.*[,].*$"
41 #define ER_CONTAINNUM "^.*[0-9].*$"
42 #define ER_MULTIWORD "^.*[-].*$"
43 #define ER_CARD "^[0-9]+$"
44 #define ER_CARDPUNCT "^[0-9]+[,!?:.]+$"
45 #define ER_CARDSEPS "^[0-9]+[-,:\\/.][0-9,:\\/.-]+$"
46 #define ER_CARDSUFFIX "^[0-9]+[^0-9]+.*$"
48 /**************************************************/
52 regcomp (&erCard
,ER_CARD
,REG_EXTENDED
);
53 regcomp (&erCardPunct
,ER_CARDPUNCT
,REG_EXTENDED
);
54 regcomp (&erCardSeps
,ER_CARDSEPS
,REG_EXTENDED
);
55 regcomp (&erCardSuffix
,ER_CARDSUFFIX
,REG_EXTENDED
);
57 regcomp (&erStartCap
,ER_STARTCAP
,REG_EXTENDED
);
58 regcomp (&erStartNumber
,ER_STARTNUMBER
,REG_EXTENDED
);
59 regcomp (&erStartLower
,ER_STARTLOWER
,REG_EXTENDED
);
60 regcomp (&erAllUp
,ER_ALLUP
,REG_EXTENDED
);
61 regcomp (&erAllLow
,ER_ALLLOW
,REG_EXTENDED
);
62 regcomp (&erContainCap
,ER_CONTAINCAP
,REG_EXTENDED
);
63 regcomp (&erContainCaps
,ER_CONTAINCAPS
,REG_EXTENDED
);
64 regcomp (&erContainPeriod
,ER_CONTAINPERIOD
,REG_EXTENDED
);
65 regcomp (&erContainComma
,ER_CONTAINCOMMA
,REG_EXTENDED
);
66 regcomp (&erContainNum
,ER_CONTAINNUM
,REG_EXTENDED
);
67 regcomp (&erMultiWord
,ER_MULTIWORD
,REG_EXTENDED
);
71 /**************************************************/
76 regfree(&erCardSuffix
);
78 regfree(&erCardPunct
);
81 regfree(&erStartLower
);
82 regfree(&erStartNumber
);
85 regfree(&erContainCap
);
86 regfree(&erContainCaps
);
87 regfree(&erContainComma
);
88 regfree(&erContainPeriod
);
89 regfree(&erContainNum
);
90 regfree(&erMultiWord
);
94 /**************************************************/
97 * return 1 if str is like the regular expression
98 * in other case return 0
100 int erLookRegExp2(void *er
,char * str
)
104 if (!regexec ((regex_t
*)er
,str
,0,NULL
,0)) return 1;
110 /**************************************************/
112 int erLookRegExp(char *m
)
116 if (!regexec (&erCardPunct
,m
,0,NULL
,0)) ret
=CARDPUNCT
;
117 else if (!regexec (&erCardSeps
,m
,0,NULL
,0)) ret
=CARDSEPS
;
118 else if (!regexec (&erCardSuffix
,m
,0,NULL
,0)) ret
=CARDSUFFIX
;
119 else if (!regexec (&erCard
,m
,0,NULL
,0)) ret
=CARD
;