Line data Source code
1 : /* Copyright (C) 2000-2002 by George Williams */
2 : /*
3 : * Redistribution and use in source and binary forms, with or without
4 : * modification, are permitted provided that the following conditions are met:
5 :
6 : * Redistributions of source code must retain the above copyright notice, this
7 : * list of conditions and the following disclaimer.
8 :
9 : * Redistributions in binary form must reproduce the above copyright notice,
10 : * this list of conditions and the following disclaimer in the documentation
11 : * and/or other materials provided with the distribution.
12 :
13 : * The name of the author may not be used to endorse or promote products
14 : * derived from this software without specific prior written permission.
15 :
16 : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 : * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 : * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 : * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 : * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 : * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 : * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 : * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 : * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 : */
27 : #include <fontforge-config.h>
28 :
29 : #include <stdlib.h>
30 : #include <string.h>
31 : #include <utype.h>
32 : #include "ustring.h"
33 :
34 0 : char *strstart(const char *initial, const char *full) {
35 : int ch1, ch2;
36 : for (;;) {
37 0 : ch1 = *initial++; ch2 = *full++ ;
38 0 : if ( ch1=='\0' )
39 0 : return( (char *) full );
40 0 : if ( ch1!=ch2 || ch1=='\0' )
41 0 : return(NULL);
42 0 : }
43 : }
44 :
45 0 : char *strstartmatch(const char *initial, const char *full) {
46 : int ch1, ch2;
47 : for (;;) {
48 0 : ch1 = *initial++; ch2 = *full++ ;
49 0 : if ( ch1=='\0' )
50 0 : return( (char *) full );
51 0 : ch1 = tolower(ch1);
52 0 : ch2 = tolower(ch2);
53 0 : if ( ch1!=ch2 || ch1=='\0' )
54 0 : return(NULL);
55 0 : }
56 : }
57 :
58 3616709 : int strmatch(const char *str1, const char *str2) {
59 : int ch1, ch2;
60 : for (;;) {
61 3616709 : ch1 = *str1++; ch2 = *str2++ ;
62 3616709 : ch1 = tolower(ch1);
63 3616709 : ch2 = tolower(ch2);
64 3616709 : if ( ch1!=ch2 || ch1=='\0' )
65 5644110 : return(ch1-ch2);
66 794654 : }
67 : }
68 :
69 421 : int strnmatch(const char *str1, const char *str2, int n) {
70 : int ch1, ch2;
71 1424 : for (;n-->0;) {
72 961 : ch1 = *str1++; ch2 = *str2++ ;
73 961 : ch1 = tolower(ch1);
74 961 : ch2 = tolower(ch2);
75 961 : if ( ch1!=ch2 || ch1=='\0' )
76 379 : return(ch1-ch2);
77 : }
78 42 : return(0);
79 : }
80 :
81 1998 : char *strstrmatch(const char *longer, const char *substr) {
82 : int ch1, ch2;
83 : const char *lpt, *str1, *str2;
84 :
85 16091 : for ( lpt=longer; *lpt!='\0'; ++lpt ) {
86 14199 : str1 = lpt; str2 = substr;
87 : for (;;) {
88 15523 : ch1 = *str1++; ch2 = *str2++ ;
89 15523 : ch1 = tolower(ch1);
90 15523 : ch2 = tolower(ch2);
91 15523 : if ( ch2=='\0' )
92 106 : return((char *) lpt);
93 15417 : if ( ch1!=ch2 )
94 14093 : break;
95 1324 : }
96 : }
97 1892 : return( NULL );
98 : }
|