Debian Codegraph @

3rdparty/flite_hts_engine/flite/src/utils/cst_string.c

raw symbols SCIP
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 ([email protected]) */
34 /* Date: December 1999 */
35 /*************************************************************************/
36 /* */
37 /* String manipulation functions */
38 /* */
39 /*************************************************************************/
40 #include <stdlib.h>
41 #include <string.h>
42 #include <ctype.h>
43 #include "cst_alloc.h"
44 #include "cst_string.h"
45
46 #ifdef UNDER_CE /* WinCE does not fully implement ANSI C */
47
48 cst_string *cst_strrchr(const cst_string *str, int c)
49 {
50 cst_string *p = (const cst_string *)str + cst_strlen(str);
51 while (p >= str) {
52 if (*p == c)
53 return p;
54 --p;
55 }
56 return NULL;
57 }
58
59 double cst_atof(const char *str)
60 {
61 /* double f = 0.0; */
62
63 /* sscanf(str, "%f", &f); */
64 return atof(str);
65 }
66
67 #else /* Sane operating system */
68
69 cst_string *cst_strrchr(const cst_string *str, int c)
70 {
71 return (cst_string *)strrchr((const char *)str, c);
72 }
73
74 double cst_atof(const char *str)
75 {
76 return atof(str);
77 }
78 #endif /* WinCE */
79
80 cst_string *cst_strdup(const cst_string *str)
81 {
82 cst_string *nstr = NULL;
83
84 if (str)
85 {
86 nstr = cst_alloc(cst_string,cst_strlen((const char *)str)+1);
87 memmove(nstr,str,cst_strlen((const char *)str)+1);
88 }
89 return nstr;
90 }
91
92 cst_string *cst_strchr(const cst_string *s, int c)
93 {
94 return (cst_string *)strchr((const char *)s,c);
95 }
96
97 char *cst_substr(const char *str,int start, int length)
98 {
99 char *nstr = NULL;
100
101 if (str)
102 {
103 nstr = cst_alloc(char,length+1);
104 strncpy(nstr,str+start,length);
105 nstr[length] = '\0';
106 }
107 return nstr;
108 }
109
110 char *cst_string_before(const char *s,const char *c)
111 {
112 char *p;
113 char *q;
114
115 p = (char *)cst_strstr(s,c);
116 if (p == NULL)
117 return NULL;
118 q = (char *)cst_strdup((cst_string *)s);
119 q[cst_strlen(s)-cst_strlen(p)] = '\0';
120 return q;
121 }
122
123 cst_string *cst_downcase(const cst_string *str)
124 {
125 cst_string *dc;
126 int i;
127
128 dc = cst_strdup(str);
129 for (i=0; str[i] != '\0'; i++)
130 {
131 if (isupper((int)str[i]))
132 dc[i] = tolower((int)str[i]);
133 }
134 return dc;
135 }
136
137 cst_string *cst_upcase(const cst_string *str)
138 {
139 cst_string *uc;
140 int i;
141
142 uc = cst_strdup(str);
143 for (i=0; str[i] != '\0'; i++)
144 {
145 if (islower((int)str[i]))
146 uc[i] = toupper((int)str[i]);
147 }
148 return uc;
149 }
150
151 int cst_member_string(const char *str, const char * const *slist)
152 {
153 const char * const *p;
154
155 for (p = slist; *p; ++p)
156 if (cst_streq(*p, str))
157 break;
158
159 return *p != NULL;
160 }