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