Rev 2726 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2726 | Rev 2927 | ||
---|---|---|---|
1 | /*++ |
1 | /*++ |
2 | 2 | ||
3 | Copyright (c) 1998 Intel Corporation |
3 | Copyright (c) 1998 Intel Corporation |
4 | 4 | ||
5 | Module Name: |
5 | Module Name: |
6 | 6 | ||
7 | str.c |
7 | str.c |
8 | 8 | ||
9 | Abstract: |
9 | Abstract: |
10 | 10 | ||
11 | 11 | ||
12 | 12 | ||
13 | 13 | ||
14 | Revision History |
14 | Revision History |
15 | 15 | ||
16 | --*/ |
16 | --*/ |
17 | 17 | ||
18 | #include "lib.h" |
18 | #include "lib.h" |
19 | 19 | ||
20 | 20 | ||
21 | INTN |
21 | INTN |
22 | StrCmp ( |
22 | StrCmp ( |
23 | IN CHAR16 *s1, |
23 | IN CHAR16 *s1, |
24 | IN CHAR16 *s2 |
24 | IN CHAR16 *s2 |
25 | ) |
25 | ) |
26 | // compare strings |
26 | // compare strings |
27 | { |
27 | { |
28 | return RtStrCmp(s1, s2); |
28 | return RtStrCmp(s1, s2); |
29 | } |
29 | } |
30 | 30 | ||
31 | INTN |
31 | INTN |
32 | StrnCmp ( |
32 | StrnCmp ( |
33 | IN CHAR16 *s1, |
33 | IN CHAR16 *s1, |
34 | IN CHAR16 *s2, |
34 | IN CHAR16 *s2, |
35 | IN UINTN len |
35 | IN UINTN len |
36 | ) |
36 | ) |
37 | // compare strings |
37 | // compare strings |
38 | { |
38 | { |
39 | while (*s1 && len) { |
39 | while (*s1 && len) { |
40 | if (*s1 != *s2) { |
40 | if (*s1 != *s2) { |
41 | break; |
41 | break; |
42 | } |
42 | } |
43 | 43 | ||
44 | s1 += 1; |
44 | s1 += 1; |
45 | s2 += 1; |
45 | s2 += 1; |
46 | len -= 1; |
46 | len -= 1; |
47 | } |
47 | } |
48 | 48 | ||
49 | return len ? *s1 - *s2 : 0; |
49 | return len ? *s1 - *s2 : 0; |
50 | } |
50 | } |
51 | 51 | ||
52 | 52 | ||
53 | INTN |
53 | INTN |
54 | LibStubStriCmp ( |
54 | LibStubStriCmp ( |
55 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
55 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
56 | IN CHAR16 *s1, |
56 | IN CHAR16 *s1, |
57 | IN CHAR16 *s2 |
57 | IN CHAR16 *s2 |
58 | ) |
58 | ) |
59 | { |
59 | { |
60 | return StrCmp (s1, s2); |
60 | return StrCmp (s1, s2); |
61 | } |
61 | } |
62 | 62 | ||
63 | VOID |
63 | VOID |
64 | LibStubStrLwrUpr ( |
64 | LibStubStrLwrUpr ( |
65 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
65 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
66 | IN CHAR16 *Str |
66 | IN CHAR16 *Str |
67 | ) |
67 | ) |
68 | { |
68 | { |
69 | } |
69 | } |
70 | 70 | ||
71 | INTN |
71 | INTN |
72 | StriCmp ( |
72 | StriCmp ( |
73 | IN CHAR16 *s1, |
73 | IN CHAR16 *s1, |
74 | IN CHAR16 *s2 |
74 | IN CHAR16 *s2 |
75 | ) |
75 | ) |
76 | // compare strings |
76 | // compare strings |
77 | { |
77 | { |
78 | return UnicodeInterface->StriColl(UnicodeInterface, s1, s2); |
78 | return UnicodeInterface->StriColl(UnicodeInterface, s1, s2); |
79 | } |
79 | } |
80 | 80 | ||
81 | VOID |
81 | VOID |
82 | StrLwr ( |
82 | StrLwr ( |
83 | IN CHAR16 *Str |
83 | IN CHAR16 *Str |
84 | ) |
84 | ) |
85 | // lwoer case string |
85 | // lwoer case string |
86 | { |
86 | { |
87 | UnicodeInterface->StrLwr(UnicodeInterface, Str); |
87 | UnicodeInterface->StrLwr(UnicodeInterface, Str); |
88 | } |
88 | } |
89 | 89 | ||
90 | VOID |
90 | VOID |
91 | StrUpr ( |
91 | StrUpr ( |
92 | IN CHAR16 *Str |
92 | IN CHAR16 *Str |
93 | ) |
93 | ) |
94 | // upper case string |
94 | // upper case string |
95 | { |
95 | { |
96 | UnicodeInterface->StrUpr(UnicodeInterface, Str); |
96 | UnicodeInterface->StrUpr(UnicodeInterface, Str); |
97 | } |
97 | } |
98 | 98 | ||
99 | VOID |
99 | VOID |
100 | StrCpy ( |
100 | StrCpy ( |
101 | IN CHAR16 *Dest, |
101 | IN CHAR16 *Dest, |
102 | IN CHAR16 *Src |
102 | IN CHAR16 *Src |
103 | ) |
103 | ) |
104 | // copy strings |
104 | // copy strings |
105 | { |
105 | { |
106 | RtStrCpy (Dest, Src); |
106 | RtStrCpy (Dest, Src); |
107 | } |
107 | } |
108 | 108 | ||
109 | VOID |
109 | VOID |
110 | StrCat ( |
110 | StrCat ( |
111 | IN CHAR16 *Dest, |
111 | IN CHAR16 *Dest, |
112 | IN CHAR16 *Src |
112 | IN CHAR16 *Src |
113 | ) |
113 | ) |
114 | { |
114 | { |
115 | RtStrCat(Dest, Src); |
115 | RtStrCat(Dest, Src); |
116 | } |
116 | } |
117 | 117 | ||
118 | UINTN |
118 | UINTN |
119 | StrLen ( |
119 | StrLen ( |
120 | IN CHAR16 *s1 |
120 | IN CHAR16 *s1 |
121 | ) |
121 | ) |
122 | // string length |
122 | // string length |
123 | { |
123 | { |
124 | return RtStrLen(s1); |
124 | return RtStrLen(s1); |
125 | } |
125 | } |
126 | 126 | ||
127 | UINTN |
127 | UINTN |
128 | StrSize ( |
128 | StrSize ( |
129 | IN CHAR16 *s1 |
129 | IN CHAR16 *s1 |
130 | ) |
130 | ) |
131 | // string size |
131 | // string size |
132 | { |
132 | { |
133 | return RtStrSize(s1); |
133 | return RtStrSize(s1); |
134 | } |
134 | } |
135 | 135 | ||
136 | CHAR16 * |
136 | CHAR16 * |
137 | StrDuplicate ( |
137 | StrDuplicate ( |
138 | IN CHAR16 *Src |
138 | IN CHAR16 *Src |
139 | ) |
139 | ) |
140 | // duplicate a string |
140 | // duplicate a string |
141 | { |
141 | { |
142 | CHAR16 *Dest; |
142 | CHAR16 *Dest; |
143 | UINTN Size; |
143 | UINTN Size; |
144 | 144 | ||
145 | Size = StrSize(Src); |
145 | Size = StrSize(Src); |
146 | Dest = AllocatePool (Size); |
146 | Dest = AllocatePool (Size); |
147 | if (Dest) { |
147 | if (Dest) { |
148 | CopyMem (Dest, Src, Size); |
148 | CopyMem (Dest, Src, Size); |
149 | } |
149 | } |
150 | return Dest; |
150 | return Dest; |
151 | } |
151 | } |
152 | 152 | ||
153 | UINTN |
153 | UINTN |
154 | strlena ( |
154 | strlena ( |
155 | IN CHAR8 *s1 |
155 | IN CHAR8 *s1 |
156 | ) |
156 | ) |
157 | // string length |
157 | // string length |
158 | { |
158 | { |
159 | UINTN len; |
159 | UINTN len; |
160 | 160 | ||
161 | for (len=0; *s1; s1+=1, len+=1) ; |
161 | for (len=0; *s1; s1+=1, len+=1) ; |
162 | return len; |
162 | return len; |
163 | } |
163 | } |
164 | 164 | ||
165 | UINTN |
165 | UINTN |
166 | strcmpa ( |
166 | strcmpa ( |
167 | IN CHAR8 *s1, |
167 | IN CHAR8 *s1, |
168 | IN CHAR8 *s2 |
168 | IN CHAR8 *s2 |
169 | ) |
169 | ) |
170 | // compare strings |
170 | // compare strings |
171 | { |
171 | { |
172 | while (*s1) { |
172 | while (*s1) { |
173 | if (*s1 != *s2) { |
173 | if (*s1 != *s2) { |
174 | break; |
174 | break; |
175 | } |
175 | } |
176 | 176 | ||
177 | s1 += 1; |
177 | s1 += 1; |
178 | s2 += 1; |
178 | s2 += 1; |
179 | } |
179 | } |
180 | 180 | ||
181 | return *s1 - *s2; |
181 | return *s1 - *s2; |
182 | } |
182 | } |
183 | 183 | ||
184 | UINTN |
184 | UINTN |
185 | strncmpa ( |
185 | strncmpa ( |
186 | IN CHAR8 *s1, |
186 | IN CHAR8 *s1, |
187 | IN CHAR8 *s2, |
187 | IN CHAR8 *s2, |
188 | IN UINTN len |
188 | IN UINTN len |
189 | ) |
189 | ) |
190 | // compare strings |
190 | // compare strings |
191 | { |
191 | { |
192 | while (*s1 && len) { |
192 | while (*s1 && len) { |
193 | if (*s1 != *s2) { |
193 | if (*s1 != *s2) { |
194 | break; |
194 | break; |
195 | } |
195 | } |
196 | 196 | ||
197 | s1 += 1; |
197 | s1 += 1; |
198 | s2 += 1; |
198 | s2 += 1; |
199 | len -= 1; |
199 | len -= 1; |
200 | } |
200 | } |
201 | 201 | ||
202 | return len ? *s1 - *s2 : 0; |
202 | return len ? *s1 - *s2 : 0; |
203 | } |
203 | } |
204 | 204 | ||
205 | 205 | ||
206 | 206 | ||
207 | UINTN |
207 | UINTN |
208 | xtoi ( |
208 | xtoi ( |
209 | CHAR16 *str |
209 | CHAR16 *str |
210 | ) |
210 | ) |
211 | // convert hex string to uint |
211 | // convert hex string to uint |
212 | { |
212 | { |
213 | UINTN u; |
213 | UINTN u; |
214 | CHAR16 c; |
214 | CHAR16 c; |
215 | 215 | ||
216 | // skip preceeding white space |
216 | // skip preceeding white space |
217 | while (*str && *str == ' ') { |
217 | while (*str && *str == ' ') { |
218 | str += 1; |
218 | str += 1; |
219 | } |
219 | } |
220 | 220 | ||
221 | // convert hex digits |
221 | // convert hex digits |
222 | u = 0; |
222 | u = 0; |
223 | while ((c = *(str++))) { |
223 | while ((c = *(str++))) { |
224 | if (c >= 'a' && c <= 'f') { |
224 | if (c >= 'a' && c <= 'f') { |
225 | c -= 'a' - 'A'; |
225 | c -= 'a' - 'A'; |
226 | } |
226 | } |
227 | 227 | ||
228 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) { |
228 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) { |
229 | u = (u << 4) | (c - (c >= 'A' ? 'A'-10 : '0')); |
229 | u = (u << 4) | (c - (c >= 'A' ? 'A'-10 : '0')); |
230 | } else { |
230 | } else { |
231 | break; |
231 | break; |
232 | } |
232 | } |
233 | } |
233 | } |
234 | 234 | ||
235 | return u; |
235 | return u; |
236 | } |
236 | } |
237 | 237 | ||
238 | UINTN |
238 | UINTN |
239 | Atoi ( |
239 | Atoi ( |
240 | CHAR16 *str |
240 | CHAR16 *str |
241 | ) |
241 | ) |
242 | // convert hex string to uint |
242 | // convert hex string to uint |
243 | { |
243 | { |
244 | UINTN u; |
244 | UINTN u; |
245 | CHAR16 c; |
245 | CHAR16 c; |
246 | 246 | ||
247 | // skip preceeding white space |
247 | // skip preceeding white space |
248 | while (*str && *str == ' ') { |
248 | while (*str && *str == ' ') { |
249 | str += 1; |
249 | str += 1; |
250 | } |
250 | } |
251 | 251 | ||
252 | // convert digits |
252 | // convert digits |
253 | u = 0; |
253 | u = 0; |
254 | while ((c = *(str++))) { |
254 | while ((c = *(str++))) { |
255 | if (c >= '0' && c <= '9') { |
255 | if (c >= '0' && c <= '9') { |
256 | u = (u * 10) + c - '0'; |
256 | u = (u * 10) + c - '0'; |
257 | } else { |
257 | } else { |
258 | break; |
258 | break; |
259 | } |
259 | } |
260 | } |
260 | } |
261 | 261 | ||
262 | return u; |
262 | return u; |
263 | } |
263 | } |
264 | 264 | ||
265 | BOOLEAN |
265 | BOOLEAN |
266 | MetaMatch ( |
266 | MetaMatch ( |
267 | IN CHAR16 *String, |
267 | IN CHAR16 *String, |
268 | IN CHAR16 *Pattern |
268 | IN CHAR16 *Pattern |
269 | ) |
269 | ) |
270 | { |
270 | { |
271 | CHAR16 c, p, l; |
271 | CHAR16 c, p, l; |
272 | 272 | ||
273 | for (; ;) { |
273 | for (; ;) { |
274 | p = *Pattern; |
274 | p = *Pattern; |
275 | Pattern += 1; |
275 | Pattern += 1; |
276 | 276 | ||
277 | switch (p) { |
277 | switch (p) { |
278 | case 0: |
278 | case 0: |
279 | // End of pattern. If end of string, TRUE match |
279 | // End of pattern. If end of string, TRUE match |
280 | return *String ? FALSE : TRUE; |
280 | return *String ? FALSE : TRUE; |
281 | 281 | ||
282 | case '*': |
282 | case '*': |
283 | // Match zero or more chars |
283 | // Match zero or more chars |
284 | while (*String) { |
284 | while (*String) { |
285 | if (MetaMatch (String, Pattern)) { |
285 | if (MetaMatch (String, Pattern)) { |
286 | return TRUE; |
286 | return TRUE; |
287 | } |
287 | } |
288 | String += 1; |
288 | String += 1; |
289 | } |
289 | } |
290 | return MetaMatch (String, Pattern); |
290 | return MetaMatch (String, Pattern); |
291 | 291 | ||
292 | case '?': |
292 | case '?': |
293 | // Match any one char |
293 | // Match any one char |
294 | if (!*String) { |
294 | if (!*String) { |
295 | return FALSE; |
295 | return FALSE; |
296 | } |
296 | } |
297 | String += 1; |
297 | String += 1; |
298 | break; |
298 | break; |
299 | 299 | ||
300 | case '[': |
300 | case '[': |
301 | // Match char set |
301 | // Match char set |
302 | c = *String; |
302 | c = *String; |
303 | if (!c) { |
303 | if (!c) { |
304 | return FALSE; // syntax problem |
304 | return FALSE; // syntax problem |
305 | } |
305 | } |
306 | 306 | ||
307 | l = 0; |
307 | l = 0; |
308 | while ((p = *Pattern++)) { |
308 | while ((p = *Pattern++)) { |
309 | if (p == ']') { |
309 | if (p == ']') { |
310 | return FALSE; |
310 | return FALSE; |
311 | } |
311 | } |
312 | 312 | ||
313 | if (p == '-') { // if range of chars, |
313 | if (p == '-') { // if range of chars, |
314 | p = *Pattern; // get high range |
314 | p = *Pattern; // get high range |
315 | if (p == 0 || p == ']') { |
315 | if (p == 0 || p == ']') { |
316 | return FALSE; // syntax problem |
316 | return FALSE; // syntax problem |
317 | } |
317 | } |
318 | 318 | ||
319 | if (c >= l && c <= p) { // if in range, |
319 | if (c >= l && c <= p) { // if in range, |
320 | break; // it's a match |
320 | break; // it's a match |
321 | } |
321 | } |
322 | } |
322 | } |
323 | 323 | ||
324 | l = p; |
324 | l = p; |
325 | if (c == p) { // if char matches |
325 | if (c == p) { // if char matches |
326 | break; // move on |
326 | break; // move on |
327 | } |
327 | } |
328 | } |
328 | } |
329 | 329 | ||
330 | // skip to end of match char set |
330 | // skip to end of match char set |
331 | while (p && p != ']') { |
331 | while (p && p != ']') { |
332 | p = *Pattern; |
332 | p = *Pattern; |
333 | Pattern += 1; |
333 | Pattern += 1; |
334 | } |
334 | } |
335 | 335 | ||
336 | String += 1; |
336 | String += 1; |
337 | break; |
337 | break; |
338 | 338 | ||
339 | default: |
339 | default: |
340 | c = *String; |
340 | c = *String; |
341 | if (c != p) { |
341 | if (c != p) { |
342 | return FALSE; |
342 | return FALSE; |
343 | } |
343 | } |
344 | 344 | ||
345 | String += 1; |
345 | String += 1; |
346 | break; |
346 | break; |
347 | } |
347 | } |
348 | } |
348 | } |
349 | } |
349 | } |
350 | 350 | ||
351 | 351 | ||
352 | BOOLEAN |
352 | BOOLEAN |
353 | LibStubMetaiMatch ( |
353 | LibStubMetaiMatch ( |
354 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
354 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
355 | IN CHAR16 *String, |
355 | IN CHAR16 *String, |
356 | IN CHAR16 *Pattern |
356 | IN CHAR16 *Pattern |
357 | ) |
357 | ) |
358 | { |
358 | { |
359 | return MetaMatch (String, Pattern); |
359 | return MetaMatch (String, Pattern); |
360 | } |
360 | } |
361 | 361 | ||
362 | 362 | ||
363 | BOOLEAN |
363 | BOOLEAN |
364 | MetaiMatch ( |
364 | MetaiMatch ( |
365 | IN CHAR16 *String, |
365 | IN CHAR16 *String, |
366 | IN CHAR16 *Pattern |
366 | IN CHAR16 *Pattern |
367 | ) |
367 | ) |
368 | { |
368 | { |
369 | return UnicodeInterface->MetaiMatch(UnicodeInterface, String, Pattern); |
369 | return UnicodeInterface->MetaiMatch(UnicodeInterface, String, Pattern); |
370 | } |
370 | } |
371 | 371 |