]>
Commit | Line | Data |
---|---|---|
d2ec0d9e | 1 | /** @file\r |
2 | Unicode string primatives.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | Module Name: String.c\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include <assert.h>\r | |
ce53a8c3 | 18 | \r |
19 | #include <Common/UefiBaseTypes.h>\r | |
20 | \r | |
21 | #include "CommonLib.h"\r | |
d2ec0d9e | 22 | \r |
23 | /**\r | |
24 | Copies one Null-terminated Unicode string to another Null-terminated Unicode\r | |
25 | string and returns the new Unicode string.\r | |
26 | \r | |
27 | This function copies the contents of the Unicode string Source to the Unicode\r | |
28 | string Destination, and returns Destination. If Source and Destination\r | |
29 | overlap, then the results are undefined.\r | |
30 | \r | |
31 | If Destination is NULL, then ASSERT().\r | |
32 | If Source is NULL, then ASSERT().\r | |
33 | If Source and Destination overlap, then ASSERT().\r | |
d2ec0d9e | 34 | \r |
35 | @param Destination Pointer to a Null-terminated Unicode string.\r | |
36 | @param Source Pointer to a Null-terminated Unicode string.\r | |
37 | \r | |
38 | @return Destiantion\r | |
39 | \r | |
40 | **/\r | |
41 | CHAR16 *\r | |
42 | EFIAPI\r | |
43 | StrCpy (\r | |
44 | OUT CHAR16 *Destination,\r | |
45 | IN CONST CHAR16 *Source\r | |
46 | )\r | |
47 | {\r | |
48 | CHAR16 *ReturnValue;\r | |
49 | \r | |
50 | //\r | |
51 | // Destination cannot be NULL\r | |
52 | //\r | |
53 | ASSERT (Destination != NULL);\r | |
54 | \r | |
55 | //\r | |
56 | // Destination and source cannot overlap\r | |
57 | //\r | |
58 | ASSERT ((UINTN)(Destination - Source) > StrLen (Source));\r | |
59 | ASSERT ((UINTN)(Source - Destination) > StrLen (Source));\r | |
60 | \r | |
61 | ReturnValue = Destination;\r | |
62 | while (*Source) {\r | |
63 | *(Destination++) = *(Source++);\r | |
64 | }\r | |
65 | *Destination = 0;\r | |
66 | return ReturnValue;\r | |
67 | }\r | |
68 | \r | |
69 | /**\r | |
70 | Copies one Null-terminated Unicode string with a maximum length to another\r | |
71 | Null-terminated Unicode string with a maximum length and returns the new\r | |
72 | Unicode string.\r | |
73 | \r | |
74 | This function copies the contents of the Unicode string Source to the Unicode\r | |
75 | string Destination, and returns Destination. At most, Length Unicode\r | |
76 | characters are copied from Source to Destination. If Length is 0, then\r | |
77 | Destination is returned unmodified. If Length is greater that the number of\r | |
78 | Unicode characters in Source, then Destination is padded with Null Unicode\r | |
79 | characters. If Source and Destination overlap, then the results are\r | |
80 | undefined.\r | |
81 | \r | |
82 | If Destination is NULL, then ASSERT().\r | |
83 | If Source is NULL, then ASSERT().\r | |
84 | If Source and Destination overlap, then ASSERT().\r | |
d2ec0d9e | 85 | \r |
86 | @param Destination Pointer to a Null-terminated Unicode string.\r | |
87 | @param Source Pointer to a Null-terminated Unicode string.\r | |
88 | @param Length Maximum number of Unicode characters to copy.\r | |
89 | \r | |
90 | @return Destination\r | |
91 | \r | |
92 | **/\r | |
93 | CHAR16 *\r | |
94 | EFIAPI\r | |
95 | StrnCpy (\r | |
96 | OUT CHAR16 *Destination,\r | |
97 | IN CONST CHAR16 *Source,\r | |
98 | IN UINTN Length\r | |
99 | )\r | |
100 | {\r | |
101 | CHAR16 *ReturnValue;\r | |
102 | \r | |
103 | if (Length == 0) {\r | |
104 | return Destination;\r | |
105 | }\r | |
106 | \r | |
107 | //\r | |
108 | // Destination cannot be NULL if Length is not zero\r | |
109 | //\r | |
110 | ASSERT (Destination != NULL);\r | |
111 | \r | |
112 | //\r | |
113 | // Destination and source cannot overlap\r | |
114 | // Q: Does Source have to be NULL-terminated?\r | |
115 | //\r | |
116 | ASSERT ((UINTN)(Destination - Source) > StrLen (Source));\r | |
117 | ASSERT ((UINTN)(Source - Destination) >= Length);\r | |
118 | \r | |
119 | ReturnValue = Destination;\r | |
120 | \r | |
121 | while ((*Source != L'\0') && (Length > 0)) {\r | |
122 | *(Destination++) = *(Source++);\r | |
123 | Length--;\r | |
124 | }\r | |
125 | \r | |
d2ec0d9e | 126 | memset (Destination, 0, Length * sizeof (*Destination));\r |
127 | return ReturnValue;\r | |
128 | }\r | |
129 | \r | |
130 | /**\r | |
131 | Returns the length of a Null-terminated Unicode string.\r | |
132 | \r | |
133 | This function returns the number of Unicode characters in the Null-terminated\r | |
134 | Unicode string specified by String.\r | |
135 | \r | |
136 | If String is NULL, then ASSERT().\r | |
d2ec0d9e | 137 | \r |
138 | @param String Pointer to a Null-terminated Unicode string.\r | |
139 | \r | |
140 | @return The length of String.\r | |
141 | \r | |
142 | **/\r | |
143 | UINTN\r | |
144 | EFIAPI\r | |
145 | StrLen (\r | |
146 | IN CONST CHAR16 *String\r | |
147 | )\r | |
148 | {\r | |
149 | UINTN Length;\r | |
150 | \r | |
151 | ASSERT (String != NULL);\r | |
152 | \r | |
153 | for (Length = 0; *String != L'\0'; String++, Length++) {\r | |
ce53a8c3 | 154 | ;\r |
d2ec0d9e | 155 | }\r |
156 | return Length;\r | |
157 | }\r | |
158 | \r | |
159 | /**\r | |
160 | Returns the size of a Null-terminated Unicode string in bytes, including the\r | |
161 | Null terminator.\r | |
162 | \r | |
163 | This function returns the size, in bytes, of the Null-terminated Unicode\r | |
164 | string specified by String.\r | |
165 | \r | |
166 | If String is NULL, then ASSERT().\r | |
d2ec0d9e | 167 | \r |
168 | @param String Pointer to a Null-terminated Unicode string.\r | |
169 | \r | |
170 | @return The size of String.\r | |
171 | \r | |
172 | **/\r | |
173 | UINTN\r | |
174 | EFIAPI\r | |
175 | StrSize (\r | |
176 | IN CONST CHAR16 *String\r | |
177 | )\r | |
178 | {\r | |
179 | return (StrLen (String) + 1) * sizeof (*String);\r | |
180 | }\r | |
181 | \r | |
182 | /**\r | |
183 | Compares two Null-terminated Unicode strings, and returns the difference\r | |
184 | between the first mismatched Unicode characters.\r | |
185 | \r | |
186 | This function compares the Null-terminated Unicode string FirstString to the\r | |
187 | Null-terminated Unicode string SecondString. If FirstString is identical to\r | |
188 | SecondString, then 0 is returned. Otherwise, the value returned is the first\r | |
189 | mismatched Unicode character in SecondString subtracted from the first\r | |
190 | mismatched Unicode character in FirstString.\r | |
191 | \r | |
192 | If FirstString is NULL, then ASSERT().\r | |
193 | If SecondString is NULL, then ASSERT().\r | |
d2ec0d9e | 194 | \r |
195 | @param FirstString Pointer to a Null-terminated Unicode string.\r | |
196 | @param SecondString Pointer to a Null-terminated Unicode string.\r | |
197 | \r | |
198 | @retval 0 FirstString is identical to SecondString.\r | |
199 | @retval !=0 FirstString is not identical to SecondString.\r | |
200 | \r | |
201 | **/\r | |
202 | INTN\r | |
203 | EFIAPI\r | |
204 | StrCmp (\r | |
205 | IN CONST CHAR16 *FirstString,\r | |
206 | IN CONST CHAR16 *SecondString\r | |
207 | )\r | |
208 | {\r | |
209 | //\r | |
ce53a8c3 | 210 | // ASSERT both strings should never be zero\r |
d2ec0d9e | 211 | //\r |
212 | ASSERT (StrSize (FirstString) != 0);\r | |
213 | ASSERT (StrSize (SecondString) != 0);\r | |
214 | \r | |
215 | while ((*FirstString != L'\0') && (*FirstString == *SecondString)) {\r | |
216 | FirstString++;\r | |
217 | SecondString++;\r | |
218 | }\r | |
219 | return *FirstString - *SecondString;\r | |
220 | }\r | |
221 | \r | |
222 | /**\r | |
223 | Compares two Null-terminated Unicode strings with maximum lengths, and\r | |
224 | returns the difference between the first mismatched Unicode characters.\r | |
225 | \r | |
226 | This function compares the Null-terminated Unicode string FirstString to the\r | |
227 | Null-terminated Unicode string SecondString. At most, Length Unicode\r | |
228 | characters will be compared. If Length is 0, then 0 is returned. If\r | |
229 | FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r | |
230 | value returned is the first mismatched Unicode character in SecondString\r | |
231 | subtracted from the first mismatched Unicode character in FirstString.\r | |
232 | \r | |
233 | If FirstString is NULL, then ASSERT().\r | |
234 | If SecondString is NULL, then ASSERT().\r | |
d2ec0d9e | 235 | \r |
236 | @param FirstString Pointer to a Null-terminated Unicode string.\r | |
237 | @param SecondString Pointer to a Null-terminated Unicode string.\r | |
238 | @param Length Maximum number of Unicode characters to compare.\r | |
239 | \r | |
240 | @retval 0 FirstString is identical to SecondString.\r | |
241 | @retval !=0 FirstString is not identical to SecondString.\r | |
242 | \r | |
243 | **/\r | |
244 | INTN\r | |
245 | EFIAPI\r | |
246 | StrnCmp (\r | |
247 | IN CONST CHAR16 *FirstString,\r | |
248 | IN CONST CHAR16 *SecondString,\r | |
249 | IN UINTN Length\r | |
250 | )\r | |
251 | {\r | |
252 | if (Length == 0) {\r | |
253 | return 0;\r | |
254 | }\r | |
255 | \r | |
256 | //\r | |
ce53a8c3 | 257 | // ASSERT both strings should never be zero\r |
d2ec0d9e | 258 | //\r |
259 | ASSERT (StrSize (FirstString) != 0);\r | |
260 | ASSERT (StrSize (SecondString) != 0);\r | |
261 | \r | |
262 | while ((*FirstString != L'\0') &&\r | |
263 | (*FirstString == *SecondString) &&\r | |
264 | (Length > 1)) {\r | |
265 | FirstString++;\r | |
266 | SecondString++;\r | |
267 | Length--;\r | |
268 | }\r | |
269 | \r | |
270 | return *FirstString - *SecondString;\r | |
271 | }\r | |
272 | \r | |
273 | /**\r | |
274 | Concatenates one Null-terminated Unicode string to another Null-terminated\r | |
275 | Unicode string, and returns the concatenated Unicode string.\r | |
276 | \r | |
277 | This function concatenates two Null-terminated Unicode strings. The contents\r | |
278 | of Null-terminated Unicode string Source are concatenated to the end of\r | |
279 | Null-terminated Unicode string Destination. The Null-terminated concatenated\r | |
280 | Unicode String is returned. If Source and Destination overlap, then the\r | |
281 | results are undefined.\r | |
282 | \r | |
283 | If Destination is NULL, then ASSERT().\r | |
284 | If Source is NULL, then ASSERT().\r | |
285 | If Source and Destination overlap, then ASSERT().\r | |
d2ec0d9e | 286 | \r |
287 | @param Destination Pointer to a Null-terminated Unicode string.\r | |
288 | @param Source Pointer to a Null-terminated Unicode string.\r | |
289 | \r | |
290 | @return Destination\r | |
291 | \r | |
292 | **/\r | |
293 | CHAR16 *\r | |
294 | EFIAPI\r | |
295 | StrCat (\r | |
296 | IN OUT CHAR16 *Destination,\r | |
297 | IN CONST CHAR16 *Source\r | |
298 | )\r | |
299 | {\r | |
300 | StrCpy (Destination + StrLen (Destination), Source);\r | |
301 | \r | |
302 | //\r | |
303 | // Size of the resulting string should never be zero.\r | |
d2ec0d9e | 304 | //\r |
305 | ASSERT (StrSize (Destination) != 0);\r | |
306 | return Destination;\r | |
307 | }\r | |
308 | \r | |
309 | /**\r | |
310 | Concatenates one Null-terminated Unicode string with a maximum length to the\r | |
311 | end of another Null-terminated Unicode string, and returns the concatenated\r | |
312 | Unicode string.\r | |
313 | \r | |
314 | This function concatenates two Null-terminated Unicode strings. The contents\r | |
315 | of Null-terminated Unicode string Source are concatenated to the end of\r | |
316 | Null-terminated Unicode string Destination, and Destination is returned. At\r | |
317 | most, Length Unicode characters are concatenated from Source to the end of\r | |
318 | Destination, and Destination is always Null-terminated. If Length is 0, then\r | |
319 | Destination is returned unmodified. If Source and Destination overlap, then\r | |
320 | the results are undefined.\r | |
321 | \r | |
322 | If Destination is NULL, then ASSERT().\r | |
323 | If Source is NULL, then ASSERT().\r | |
324 | If Source and Destination overlap, then ASSERT().\r | |
d2ec0d9e | 325 | \r |
326 | @param Destination Pointer to a Null-terminated Unicode string.\r | |
327 | @param Source Pointer to a Null-terminated Unicode string.\r | |
328 | @param Length Maximum number of Unicode characters to concatenate from\r | |
329 | Source.\r | |
330 | \r | |
331 | @return Destination\r | |
332 | \r | |
333 | **/\r | |
334 | CHAR16 *\r | |
335 | EFIAPI\r | |
336 | StrnCat (\r | |
337 | IN OUT CHAR16 *Destination,\r | |
338 | IN CONST CHAR16 *Source,\r | |
339 | IN UINTN Length\r | |
340 | )\r | |
341 | {\r | |
342 | StrnCpy (Destination + StrLen (Destination), Source, Length);\r | |
343 | \r | |
344 | //\r | |
345 | // Size of the resulting string should never be zero.\r | |
d2ec0d9e | 346 | //\r |
347 | ASSERT (StrSize (Destination) != 0);\r | |
348 | return Destination;\r | |
349 | }\r | |
350 | \r | |
351 | /**\r | |
352 | Copies one Null-terminated ASCII string to another Null-terminated ASCII\r | |
353 | string and returns the new ASCII string.\r | |
354 | \r | |
355 | This function copies the contents of the ASCII string Source to the ASCII\r | |
356 | string Destination, and returns Destination. If Source and Destination\r | |
357 | overlap, then the results are undefined.\r | |
358 | \r | |
359 | If Destination is NULL, then ASSERT().\r | |
360 | If Source is NULL, then ASSERT().\r | |
361 | If Source and Destination overlap, then ASSERT().\r | |
d2ec0d9e | 362 | \r |
363 | @param Destination Pointer to a Null-terminated ASCII string.\r | |
364 | @param Source Pointer to a Null-terminated ASCII string.\r | |
365 | \r | |
366 | @return Destination\r | |
367 | \r | |
368 | **/\r | |
369 | CHAR8 *\r | |
370 | EFIAPI\r | |
371 | AsciiStrCpy (\r | |
372 | OUT CHAR8 *Destination,\r | |
373 | IN CONST CHAR8 *Source\r | |
374 | )\r | |
375 | {\r | |
376 | CHAR8 *ReturnValue;\r | |
377 | \r | |
378 | //\r | |
379 | // Destination cannot be NULL\r | |
380 | //\r | |
381 | ASSERT (Destination != NULL);\r | |
382 | \r | |
383 | //\r | |
384 | // Destination and source cannot overlap\r | |
385 | //\r | |
386 | ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));\r | |
387 | ASSERT ((UINTN)(Source - Destination) > AsciiStrLen (Source));\r | |
388 | \r | |
389 | ReturnValue = Destination;\r | |
390 | while (*Source) {\r | |
391 | *(Destination++) = *(Source++);\r | |
392 | }\r | |
393 | *Destination = 0;\r | |
394 | return ReturnValue;\r | |
395 | }\r | |
396 | \r | |
397 | /**\r | |
398 | Copies one Null-terminated ASCII string with a maximum length to another\r | |
399 | Null-terminated ASCII string with a maximum length and returns the new ASCII\r | |
400 | string.\r | |
401 | \r | |
402 | This function copies the contents of the ASCII string Source to the ASCII\r | |
403 | string Destination, and returns Destination. At most, Length ASCII characters\r | |
404 | are copied from Source to Destination. If Length is 0, then Destination is\r | |
405 | returned unmodified. If Length is greater that the number of ASCII characters\r | |
406 | in Source, then Destination is padded with Null ASCII characters. If Source\r | |
407 | and Destination overlap, then the results are undefined.\r | |
408 | \r | |
409 | If Destination is NULL, then ASSERT().\r | |
410 | If Source is NULL, then ASSERT().\r | |
411 | If Source and Destination overlap, then ASSERT().\r | |
d2ec0d9e | 412 | \r |
413 | @param Destination Pointer to a Null-terminated ASCII string.\r | |
414 | @param Source Pointer to a Null-terminated ASCII string.\r | |
415 | @param Length Maximum number of ASCII characters to copy.\r | |
416 | \r | |
417 | @return Destination\r | |
418 | \r | |
419 | **/\r | |
420 | CHAR8 *\r | |
421 | EFIAPI\r | |
422 | AsciiStrnCpy (\r | |
423 | OUT CHAR8 *Destination,\r | |
424 | IN CONST CHAR8 *Source,\r | |
425 | IN UINTN Length\r | |
426 | )\r | |
427 | {\r | |
428 | CHAR8 *ReturnValue;\r | |
429 | \r | |
430 | if (Length == 0) {\r | |
431 | return Destination;\r | |
432 | }\r | |
433 | \r | |
434 | //\r | |
435 | // Destination cannot be NULL\r | |
436 | //\r | |
437 | ASSERT (Destination != NULL);\r | |
438 | \r | |
439 | //\r | |
440 | // Destination and source cannot overlap\r | |
441 | //\r | |
442 | ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));\r | |
443 | ASSERT ((UINTN)(Source - Destination) >= Length);\r | |
444 | \r | |
445 | ReturnValue = Destination;\r | |
446 | \r | |
447 | while (*Source && Length > 0) {\r | |
448 | *(Destination++) = *(Source++);\r | |
449 | Length--;\r | |
450 | }\r | |
451 | \r | |
452 | // ZeroMem (Destination, Length * sizeof (*Destination));\r | |
453 | memset (Destination, 0, Length * sizeof (*Destination));\r | |
454 | return ReturnValue;\r | |
455 | }\r | |
456 | \r | |
457 | /**\r | |
458 | Returns the length of a Null-terminated ASCII string.\r | |
459 | \r | |
460 | This function returns the number of ASCII characters in the Null-terminated\r | |
461 | ASCII string specified by String.\r | |
462 | \r | |
463 | If String is NULL, then ASSERT().\r | |
d2ec0d9e | 464 | \r |
465 | @param String Pointer to a Null-terminated ASCII string.\r | |
466 | \r | |
467 | @return The length of String.\r | |
468 | \r | |
469 | **/\r | |
470 | UINTN\r | |
471 | EFIAPI\r | |
472 | AsciiStrLen (\r | |
473 | IN CONST CHAR8 *String\r | |
474 | )\r | |
475 | {\r | |
476 | UINTN Length;\r | |
477 | \r | |
478 | ASSERT (String != NULL);\r | |
479 | \r | |
480 | for (Length = 0; *String != '\0'; String++, Length++) {\r | |
ce53a8c3 | 481 | ;\r |
d2ec0d9e | 482 | }\r |
483 | return Length;\r | |
484 | }\r | |
485 | \r | |
486 | /**\r | |
487 | Returns the size of a Null-terminated ASCII string in bytes, including the\r | |
488 | Null terminator.\r | |
489 | \r | |
490 | This function returns the size, in bytes, of the Null-terminated ASCII string\r | |
491 | specified by String.\r | |
492 | \r | |
493 | If String is NULL, then ASSERT().\r | |
d2ec0d9e | 494 | \r |
495 | @param String Pointer to a Null-terminated ASCII string.\r | |
496 | \r | |
497 | @return The size of String.\r | |
498 | \r | |
499 | **/\r | |
500 | UINTN\r | |
501 | EFIAPI\r | |
502 | AsciiStrSize (\r | |
503 | IN CONST CHAR8 *String\r | |
504 | )\r | |
505 | {\r | |
506 | return (AsciiStrLen (String) + 1) * sizeof (*String);\r | |
507 | }\r | |
508 | \r | |
509 | /**\r | |
510 | Compares two Null-terminated ASCII strings, and returns the difference\r | |
511 | between the first mismatched ASCII characters.\r | |
512 | \r | |
513 | This function compares the Null-terminated ASCII string FirstString to the\r | |
514 | Null-terminated ASCII string SecondString. If FirstString is identical to\r | |
515 | SecondString, then 0 is returned. Otherwise, the value returned is the first\r | |
516 | mismatched ASCII character in SecondString subtracted from the first\r | |
517 | mismatched ASCII character in FirstString.\r | |
518 | \r | |
519 | If FirstString is NULL, then ASSERT().\r | |
520 | If SecondString is NULL, then ASSERT().\r | |
d2ec0d9e | 521 | \r |
522 | @param FirstString Pointer to a Null-terminated ASCII string.\r | |
523 | @param SecondString Pointer to a Null-terminated ASCII string.\r | |
524 | \r | |
525 | @retval 0 FirstString is identical to SecondString.\r | |
526 | @retval !=0 FirstString is not identical to SecondString.\r | |
527 | \r | |
528 | **/\r | |
529 | INTN\r | |
530 | EFIAPI\r | |
531 | AsciiStrCmp (\r | |
532 | IN CONST CHAR8 *FirstString,\r | |
533 | IN CONST CHAR8 *SecondString\r | |
534 | )\r | |
535 | {\r | |
536 | //\r | |
ce53a8c3 | 537 | // ASSERT both strings should never be zero\r |
d2ec0d9e | 538 | //\r |
539 | ASSERT (AsciiStrSize (FirstString));\r | |
540 | ASSERT (AsciiStrSize (SecondString));\r | |
541 | \r | |
542 | while ((*FirstString != '\0') && (*FirstString == *SecondString)) {\r | |
543 | FirstString++;\r | |
544 | SecondString++;\r | |
545 | }\r | |
546 | \r | |
547 | return *FirstString - *SecondString;\r | |
548 | }\r | |
549 | \r | |
550 | STATIC\r | |
551 | CHAR8\r | |
552 | EFIAPI\r | |
553 | AsciiToUpper (\r | |
554 | IN CHAR8 Chr\r | |
555 | )\r | |
556 | {\r | |
557 | return (Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr;\r | |
558 | }\r | |
559 | \r | |
560 | /**\r | |
561 | Performs a case insensitive comparison of two Null-terminated ASCII strings,\r | |
562 | and returns the difference between the first mismatched ASCII characters.\r | |
563 | \r | |
564 | This function performs a case insensitive comparison of the Null-terminated\r | |
565 | ASCII string FirstString to the Null-terminated ASCII string SecondString. If\r | |
566 | FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r | |
567 | value returned is the first mismatched lower case ASCII character in\r | |
568 | SecondString subtracted from the first mismatched lower case ASCII character\r | |
569 | in FirstString.\r | |
570 | \r | |
571 | If FirstString is NULL, then ASSERT().\r | |
572 | If SecondString is NULL, then ASSERT().\r | |
d2ec0d9e | 573 | \r |
574 | @param FirstString Pointer to a Null-terminated ASCII string.\r | |
575 | @param SecondString Pointer to a Null-terminated ASCII string.\r | |
576 | \r | |
577 | @retval 0 FirstString is identical to SecondString using case insensitive\r | |
578 | comparisons.\r | |
579 | @retval !=0 FirstString is not identical to SecondString using case\r | |
580 | insensitive comparisons.\r | |
581 | \r | |
582 | **/\r | |
583 | INTN\r | |
584 | EFIAPI\r | |
585 | AsciiStriCmp (\r | |
586 | IN CONST CHAR8 *FirstString,\r | |
587 | IN CONST CHAR8 *SecondString\r | |
588 | )\r | |
589 | {\r | |
590 | //\r | |
ce53a8c3 | 591 | // ASSERT both strings should never be zero\r |
d2ec0d9e | 592 | //\r |
593 | ASSERT (AsciiStrSize (FirstString));\r | |
594 | ASSERT (AsciiStrSize (SecondString));\r | |
595 | \r | |
596 | while ((*FirstString != '\0') &&\r | |
597 | (AsciiToUpper (*FirstString) == AsciiToUpper (*SecondString))) {\r | |
598 | FirstString++;\r | |
599 | SecondString++;\r | |
600 | }\r | |
601 | \r | |
602 | return AsciiToUpper (*FirstString) - AsciiToUpper (*SecondString);\r | |
603 | }\r | |
604 | \r | |
605 | /**\r | |
606 | Compares two Null-terminated ASCII strings with maximum lengths, and returns\r | |
607 | the difference between the first mismatched ASCII characters.\r | |
608 | \r | |
609 | This function compares the Null-terminated ASCII string FirstString to the\r | |
610 | Null-terminated ASCII string SecondString. At most, Length ASCII characters\r | |
611 | will be compared. If Length is 0, then 0 is returned. If FirstString is\r | |
612 | identical to SecondString, then 0 is returned. Otherwise, the value returned\r | |
613 | is the first mismatched ASCII character in SecondString subtracted from the\r | |
614 | first mismatched ASCII character in FirstString.\r | |
615 | \r | |
616 | If FirstString is NULL, then ASSERT().\r | |
617 | If SecondString is NULL, then ASSERT().\r | |
d2ec0d9e | 618 | \r |
619 | @param FirstString Pointer to a Null-terminated ASCII string.\r | |
620 | @param SecondString Pointer to a Null-terminated ASCII string.\r | |
621 | \r | |
622 | @retval 0 FirstString is identical to SecondString.\r | |
623 | @retval !=0 FirstString is not identical to SecondString.\r | |
624 | \r | |
625 | **/\r | |
626 | INTN\r | |
627 | EFIAPI\r | |
628 | AsciiStrnCmp (\r | |
629 | IN CONST CHAR8 *FirstString,\r | |
630 | IN CONST CHAR8 *SecondString,\r | |
631 | IN UINTN Length\r | |
632 | )\r | |
633 | {\r | |
634 | //\r | |
ce53a8c3 | 635 | // ASSERT both strings should never be zero\r |
d2ec0d9e | 636 | //\r |
637 | ASSERT (AsciiStrSize (FirstString));\r | |
638 | ASSERT (AsciiStrSize (SecondString));\r | |
639 | \r | |
640 | while ((*FirstString != '\0') &&\r | |
641 | (*FirstString == *SecondString) &&\r | |
642 | (Length > 1)) {\r | |
643 | FirstString++;\r | |
644 | SecondString++;\r | |
645 | Length--;\r | |
646 | }\r | |
647 | return *FirstString - *SecondString;\r | |
648 | }\r | |
649 | \r | |
650 | /**\r | |
651 | Concatenates one Null-terminated ASCII string to another Null-terminated\r | |
652 | ASCII string, and returns the concatenated ASCII string.\r | |
653 | \r | |
654 | This function concatenates two Null-terminated ASCII strings. The contents of\r | |
655 | Null-terminated ASCII string Source are concatenated to the end of Null-\r | |
656 | terminated ASCII string Destination. The Null-terminated concatenated ASCII\r | |
657 | String is returned.\r | |
658 | \r | |
659 | If Destination is NULL, then ASSERT().\r | |
660 | If Source is NULL, then ASSERT().\r | |
d2ec0d9e | 661 | \r |
662 | @param Destination Pointer to a Null-terminated ASCII string.\r | |
663 | @param Source Pointer to a Null-terminated ASCII string.\r | |
664 | \r | |
665 | @return Destination\r | |
666 | \r | |
667 | **/\r | |
668 | CHAR8 *\r | |
669 | EFIAPI\r | |
670 | AsciiStrCat (\r | |
671 | IN OUT CHAR8 *Destination,\r | |
672 | IN CONST CHAR8 *Source\r | |
673 | )\r | |
674 | {\r | |
675 | AsciiStrCpy (Destination + AsciiStrLen (Destination), Source);\r | |
676 | \r | |
677 | //\r | |
678 | // Size of the resulting string should never be zero.\r | |
d2ec0d9e | 679 | //\r |
680 | ASSERT (AsciiStrSize (Destination) != 0);\r | |
681 | return Destination;\r | |
682 | }\r | |
683 | \r | |
684 | /**\r | |
685 | Concatenates one Null-terminated ASCII string with a maximum length to the\r | |
686 | end of another Null-terminated ASCII string, and returns the concatenated\r | |
687 | ASCII string.\r | |
688 | \r | |
689 | This function concatenates two Null-terminated ASCII strings. The contents\r | |
690 | of Null-terminated ASCII string Source are concatenated to the end of Null-\r | |
691 | terminated ASCII string Destination, and Destination is returned. At most,\r | |
692 | Length ASCII characters are concatenated from Source to the end of\r | |
693 | Destination, and Destination is always Null-terminated. If Length is 0, then\r | |
694 | Destination is returned unmodified. If Source and Destination overlap, then\r | |
695 | the results are undefined.\r | |
696 | \r | |
697 | If Destination is NULL, then ASSERT().\r | |
698 | If Source is NULL, then ASSERT().\r | |
699 | If Source and Destination overlap, then ASSERT().\r | |
d2ec0d9e | 700 | \r |
701 | @param Destination Pointer to a Null-terminated ASCII string.\r | |
702 | @param Source Pointer to a Null-terminated ASCII string.\r | |
703 | @param Length Maximum number of ASCII characters to concatenate from\r | |
704 | Source.\r | |
705 | \r | |
706 | @return Destination\r | |
707 | \r | |
708 | **/\r | |
709 | CHAR8 *\r | |
710 | EFIAPI\r | |
711 | AsciiStrnCat (\r | |
712 | IN OUT CHAR8 *Destination,\r | |
713 | IN CONST CHAR8 *Source,\r | |
714 | IN UINTN Length\r | |
715 | )\r | |
716 | {\r | |
717 | AsciiStrnCpy (Destination + AsciiStrLen (Destination), Source, Length);\r | |
718 | \r | |
719 | //\r | |
720 | // Size of the resulting string should never be zero.\r | |
d2ec0d9e | 721 | //\r |
722 | ASSERT (AsciiStrSize (Destination) != 0);\r | |
723 | return Destination;\r | |
724 | }\r |