]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c
MdeModulePkg/EbcDebugger: Use AsciiCharToUpper and CharToUpper
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbSupportString.c
CommitLineData
e8a5ac7c 1/** @file\r
748edcd5 2\r
cecbecb7 3Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r
e8a5ac7c 4This program and the accompanying materials\r
748edcd5
PB
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
748edcd5 12\r
e8a5ac7c 13**/\r
748edcd5 14\r
e8a5ac7c 15#include "Edb.h"\r
748edcd5 16\r
e8a5ac7c 17/**\r
748edcd5 18\r
e8a5ac7c 19 Convert hex string to uint.\r
748edcd5 20\r
3e118ea8 21 @param Str - The string\r
748edcd5 22\r
e8a5ac7c 23**/\r
748edcd5
PB
24UINTN\r
25EFIAPI\r
26Xtoi (\r
3e118ea8 27 CHAR16 *Str\r
748edcd5 28 )\r
748edcd5 29{\r
3e118ea8
DB
30 UINTN RetVal;\r
31 CHAR16 TempChar;\r
32 UINTN MaxVal;\r
748edcd5 33\r
3e118ea8 34 ASSERT (Str != NULL);\r
748edcd5 35\r
3e118ea8 36 MaxVal = (UINTN) -1 >> 4;\r
748edcd5
PB
37 //\r
38 // skip preceeding white space\r
39 //\r
532daaed 40 while (*Str != '\0' && *Str == ' ') {\r
3e118ea8 41 Str += 1;\r
748edcd5
PB
42 }\r
43 //\r
44 // skip preceeding zeros\r
45 //\r
532daaed 46 while (*Str != '\0' && *Str == '0') {\r
3e118ea8 47 Str += 1;\r
748edcd5
PB
48 }\r
49 //\r
50 // skip preceeding white space\r
51 //\r
532daaed 52 if (*Str != '\0' && (*Str == 'x' || *Str == 'X')) {\r
3e118ea8 53 Str += 1;\r
748edcd5
PB
54 }\r
55 //\r
56 // convert hex digits\r
57 //\r
3e118ea8
DB
58 RetVal = 0;\r
59 TempChar = *(Str++);\r
532daaed 60 while (TempChar != '\0') {\r
3e118ea8
DB
61 if (TempChar >= 'a' && TempChar <= 'f') {\r
62 TempChar -= 'a' - 'A';\r
748edcd5
PB
63 }\r
64\r
3e118ea8
DB
65 if ((TempChar >= '0' && TempChar <= '9') || (TempChar >= 'A' && TempChar <= 'F')) {\r
66 if (RetVal > MaxVal) {\r
748edcd5
PB
67 return (UINTN) -1;\r
68 }\r
69\r
3e118ea8 70 RetVal = (RetVal << 4) | (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));\r
748edcd5
PB
71 } else {\r
72 break;\r
73 }\r
74\r
3e118ea8 75 TempChar = *(Str++);\r
748edcd5
PB
76 }\r
77\r
3e118ea8 78 return RetVal;\r
748edcd5
PB
79}\r
80\r
e8a5ac7c
DB
81/**\r
82\r
83 Convert hex string to uint.\r
84\r
3e118ea8 85 @param Str - The string\r
e8a5ac7c
DB
86\r
87**/\r
748edcd5
PB
88UINT64\r
89EFIAPI\r
90LXtoi (\r
3e118ea8 91 CHAR16 *Str\r
748edcd5 92 )\r
748edcd5 93{\r
3e118ea8
DB
94 UINT64 RetVal;\r
95 CHAR16 TempChar;\r
96 UINT64 MaxVal;\r
748edcd5 97\r
3e118ea8 98 ASSERT (Str != NULL);\r
748edcd5 99\r
3e118ea8 100 MaxVal = RShiftU64 ((UINT64) -1, 4);\r
748edcd5
PB
101 //\r
102 // skip preceeding white space\r
103 //\r
532daaed 104 while (*Str != '\0' && *Str == ' ') {\r
3e118ea8 105 Str += 1;\r
748edcd5
PB
106 }\r
107 //\r
108 // skip preceeding zeros\r
109 //\r
532daaed 110 while (*Str != '\0' && *Str == '0') {\r
3e118ea8 111 Str += 1;\r
748edcd5
PB
112 }\r
113 //\r
114 // skip preceeding white space\r
115 //\r
532daaed 116 if (*Str != '\0' && (*Str == 'x' || *Str == 'X')) {\r
3e118ea8 117 Str += 1;\r
748edcd5
PB
118 }\r
119 //\r
120 // convert hex digits\r
121 //\r
3e118ea8
DB
122 RetVal = 0;\r
123 TempChar = *(Str++);\r
532daaed 124 while (TempChar != '\0') {\r
3e118ea8
DB
125 if (TempChar >= 'a' && TempChar <= 'f') {\r
126 TempChar -= 'a' - 'A';\r
748edcd5
PB
127 }\r
128\r
3e118ea8
DB
129 if ((TempChar >= '0' && TempChar <= '9') || (TempChar >= 'A' && TempChar <= 'F')) {\r
130 if (RetVal > MaxVal) {\r
748edcd5
PB
131 return (UINT64) -1;\r
132 }\r
133\r
3e118ea8
DB
134 RetVal = LShiftU64 (RetVal, 4);\r
135 RetVal = RetVal + (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));\r
748edcd5
PB
136 } else {\r
137 break;\r
138 }\r
139\r
3e118ea8 140 TempChar = *(Str++);\r
748edcd5
PB
141 }\r
142\r
3e118ea8 143 return RetVal;\r
748edcd5
PB
144}\r
145\r
e8a5ac7c
DB
146/**\r
147\r
148 Convert hex string to uint.\r
149\r
3e118ea8 150 @param Str - The string\r
e8a5ac7c
DB
151\r
152**/\r
748edcd5
PB
153UINTN\r
154EFIAPI\r
155Atoi (\r
3e118ea8 156 CHAR16 *Str\r
748edcd5 157 )\r
748edcd5 158{\r
3e118ea8
DB
159 UINTN RetVal;\r
160 CHAR16 TempChar;\r
161 UINTN MaxVal;\r
162 UINTN ResteVal;\r
748edcd5 163\r
3e118ea8 164 ASSERT (Str != NULL);\r
748edcd5 165\r
3e118ea8
DB
166 MaxVal = (UINTN) -1 / 10;\r
167 ResteVal = (UINTN) -1 % 10;\r
748edcd5
PB
168 //\r
169 // skip preceeding white space\r
170 //\r
532daaed 171 while (*Str != '\0' && *Str == ' ') {\r
3e118ea8 172 Str += 1;\r
748edcd5
PB
173 }\r
174 //\r
175 // convert digits\r
176 //\r
3e118ea8
DB
177 RetVal = 0;\r
178 TempChar = *(Str++);\r
532daaed 179 while (TempChar != '\0') {\r
3e118ea8
DB
180 if (TempChar >= '0' && TempChar <= '9') {\r
181 if (RetVal > MaxVal || (RetVal == MaxVal && TempChar - '0' > (INTN) ResteVal)) {\r
748edcd5
PB
182 return (UINTN) -1;\r
183 }\r
184\r
3e118ea8 185 RetVal = (RetVal * 10) + TempChar - '0';\r
748edcd5
PB
186 } else {\r
187 break;\r
188 }\r
189\r
3e118ea8 190 TempChar = *(Str++);\r
748edcd5
PB
191 }\r
192\r
3e118ea8 193 return RetVal;\r
748edcd5
PB
194}\r
195\r
e8a5ac7c
DB
196/**\r
197\r
198 Convert hex string to uint.\r
199\r
3e118ea8 200 @param Str - The string\r
e8a5ac7c
DB
201\r
202**/\r
748edcd5
PB
203UINTN\r
204EFIAPI\r
205AsciiXtoi (\r
3e118ea8 206 CHAR8 *Str\r
748edcd5 207 )\r
748edcd5 208{\r
3e118ea8
DB
209 UINTN RetVal;\r
210 CHAR8 TempChar;\r
211 UINTN MaxVal;\r
748edcd5 212\r
3e118ea8 213 ASSERT (Str != NULL);\r
748edcd5 214\r
3e118ea8 215 MaxVal = (UINTN) -1 >> 4;\r
748edcd5
PB
216 //\r
217 // skip preceeding white space\r
218 //\r
532daaed 219 while (*Str != '\0' && *Str == ' ') {\r
3e118ea8 220 Str += 1;\r
748edcd5
PB
221 }\r
222 //\r
223 // skip preceeding zeros\r
224 //\r
532daaed 225 while (*Str != '\0' && *Str == '0') {\r
3e118ea8 226 Str += 1;\r
748edcd5
PB
227 }\r
228 //\r
229 // skip preceeding white space\r
230 //\r
532daaed 231 if (*Str != '\0' && (*Str == 'x' || *Str == 'X')) {\r
3e118ea8 232 Str += 1;\r
748edcd5
PB
233 }\r
234 //\r
235 // convert hex digits\r
236 //\r
3e118ea8
DB
237 RetVal = 0;\r
238 TempChar = *(Str++);\r
532daaed 239 while (TempChar != '\0') {\r
3e118ea8
DB
240 if (TempChar >= 'a' && TempChar <= 'f') {\r
241 TempChar -= 'a' - 'A';\r
748edcd5
PB
242 }\r
243\r
3e118ea8
DB
244 if ((TempChar >= '0' && TempChar <= '9') || (TempChar >= 'A' && TempChar <= 'F')) {\r
245 if (RetVal > MaxVal) {\r
748edcd5
PB
246 return (UINTN) -1;\r
247 }\r
248\r
3e118ea8 249 RetVal = (RetVal << 4) | (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));\r
748edcd5
PB
250 } else {\r
251 break;\r
252 }\r
253\r
3e118ea8 254 TempChar = *(Str++);\r
748edcd5
PB
255 }\r
256\r
3e118ea8 257 return RetVal;\r
748edcd5
PB
258}\r
259\r
e8a5ac7c
DB
260/**\r
261\r
262 Convert hex string to uint.\r
263\r
3e118ea8 264 @param Str - The string\r
e8a5ac7c
DB
265\r
266**/\r
748edcd5
PB
267UINTN\r
268EFIAPI\r
269AsciiAtoi (\r
3e118ea8 270 CHAR8 *Str\r
748edcd5 271 )\r
748edcd5 272{\r
3e118ea8
DB
273 UINTN RetVal;\r
274 CHAR8 TempChar;\r
275 UINTN MaxVal;\r
276 UINTN ResteVal;\r
748edcd5 277\r
3e118ea8 278 ASSERT (Str != NULL);\r
748edcd5 279\r
3e118ea8
DB
280 MaxVal = (UINTN) -1 / 10;\r
281 ResteVal = (UINTN) -1 % 10;\r
748edcd5
PB
282 //\r
283 // skip preceeding white space\r
284 //\r
532daaed 285 while (*Str != '\0' && *Str == ' ') {\r
3e118ea8 286 Str += 1;\r
748edcd5
PB
287 }\r
288 //\r
289 // convert digits\r
290 //\r
3e118ea8
DB
291 RetVal = 0;\r
292 TempChar = *(Str++);\r
532daaed 293 while (TempChar != '\0') {\r
3e118ea8
DB
294 if (TempChar >= '0' && TempChar <= '9') {\r
295 if (RetVal > MaxVal || (RetVal == MaxVal && TempChar - '0' > (INTN) ResteVal)) {\r
748edcd5
PB
296 return (UINTN) -1;\r
297 }\r
298\r
3e118ea8 299 RetVal = (RetVal * 10) + TempChar - '0';\r
748edcd5
PB
300 } else {\r
301 break;\r
302 }\r
303\r
3e118ea8 304 TempChar = *(Str++);\r
748edcd5
PB
305 }\r
306\r
3e118ea8 307 return RetVal;\r
748edcd5
PB
308}\r
309\r
748edcd5 310\r
e8a5ac7c 311/**\r
748edcd5
PB
312 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.\r
313\r
e8a5ac7c 314 @param String - Unicode String to process\r
748edcd5 315\r
e8a5ac7c 316 @param String2 - Ascii string to process\r
748edcd5 317\r
e8a5ac7c 318 @return Return a positive integer if String is lexicall greater than String2; Zero if\r
748edcd5
PB
319 the two strings are identical; and a negative interger if String is lexically\r
320 less than String2.\r
321\r
e8a5ac7c
DB
322**/\r
323INTN\r
324EFIAPI\r
325StrCmpUnicodeAndAscii (\r
326 IN CHAR16 *String,\r
327 IN CHAR8 *String2\r
328 )\r
748edcd5 329{\r
532daaed 330 while (*String != '\0') {\r
748edcd5
PB
331 if (*String != (CHAR16)*String2) {\r
332 break;\r
333 }\r
334\r
335 String += 1;\r
336 String2 += 1;\r
337 }\r
338\r
339 return (*String - (CHAR16)*String2);\r
340}\r
341\r
e8a5ac7c 342/**\r
748edcd5 343\r
748edcd5
PB
344 Compare the Unicode string pointed by String to the string pointed by String2.\r
345\r
e8a5ac7c
DB
346 @param String - Unicode String to process\r
347 @param String2 - Unicode string to process\r
748edcd5 348\r
e8a5ac7c 349 @return Return a positive integer if String is lexically greater than String2; Zero if\r
748edcd5
PB
350 the two strings are identical; and a negative integer if String is lexically\r
351 less than String2.\r
352\r
e8a5ac7c
DB
353**/\r
354INTN\r
355EFIAPI\r
356StriCmp (\r
357 IN CHAR16 *String,\r
358 IN CHAR16 *String2\r
359 )\r
748edcd5
PB
360{\r
361 while ((*String != L'\0') &&\r
357fc11c 362 (CharToUpper (*String) == CharToUpper (*String2))) {\r
748edcd5
PB
363 String++;\r
364 String2++;\r
365 }\r
366\r
357fc11c 367 return CharToUpper (*String) - CharToUpper (*String2);\r
748edcd5
PB
368}\r
369\r
e8a5ac7c 370/**\r
748edcd5 371\r
748edcd5
PB
372 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.\r
373\r
e8a5ac7c
DB
374 @param String - Unicode String to process\r
375 @param String2 - Ascii string to process\r
748edcd5 376\r
e8a5ac7c 377 @return Return a positive integer if String is lexically greater than String2; Zero if\r
748edcd5
PB
378 the two strings are identical; and a negative integer if String is lexically\r
379 less than String2.\r
380\r
e8a5ac7c
DB
381**/\r
382INTN\r
383EFIAPI\r
384StriCmpUnicodeAndAscii (\r
385 IN CHAR16 *String,\r
386 IN CHAR8 *String2\r
387 )\r
748edcd5
PB
388{\r
389 while ((*String != L'\0') &&\r
357fc11c 390 (CharToUpper (*String) == (CHAR16)AsciiCharToUpper (*String2))) {\r
748edcd5
PB
391 String++;\r
392 String2++;\r
393 }\r
394\r
357fc11c 395 return CharToUpper (*String) - (CHAR16)AsciiCharToUpper (*String2);\r
748edcd5
PB
396}\r
397\r
e8a5ac7c
DB
398/**\r
399\r
400 Verify if the string is end with the sub string.\r
401\r
402 @param Str - The string where to search the sub string\r
403 @param SubStr - The substring.\r
404\r
405**/\r
748edcd5
PB
406BOOLEAN\r
407EFIAPI\r
408StrEndWith (\r
409 IN CHAR16 *Str,\r
410 IN CHAR16 *SubStr\r
411 )\r
748edcd5
PB
412{\r
413 CHAR16 *Temp;\r
414\r
415 if ((Str == NULL) || (SubStr == NULL) || (StrLen(Str) < StrLen(SubStr))) {\r
416 return FALSE;\r
417 }\r
418\r
419 Temp = Str + StrLen(Str) - StrLen(SubStr);\r
420\r
421 //\r
422 // Compare\r
423 //\r
424 if (StriCmp (Temp, SubStr) == 0) {\r
425 return TRUE;\r
426 } else {\r
427 return FALSE;\r
428 }\r
429}\r
430\r
e8a5ac7c
DB
431/**\r
432 Duplicate a string.\r
433\r
434 @param Src The string to be duplicated.\r
435\r
436**/\r
748edcd5
PB
437CHAR16 *\r
438EFIAPI\r
439StrDuplicate (\r
440 IN CHAR16 *Src\r
441 )\r
748edcd5
PB
442{\r
443 CHAR16 *Dest;\r
444 UINTN Size;\r
445\r
446 Size = (StrLen(Src) + 1) * sizeof(CHAR16);\r
447 Dest = AllocateZeroPool (Size);\r
532daaed 448 if (Dest != NULL) {\r
748edcd5
PB
449 CopyMem (Dest, Src, Size);\r
450 }\r
451 return Dest;\r
452}\r
453\r
454\r
455CHAR16 *mLineBuffer = NULL;\r
456CHAR16 *mFieldBuffer = NULL;\r
457\r
e8a5ac7c
DB
458/**\r
459\r
460 Find the first substring.\r
461\r
462 @param String Point to the string where to find the substring.\r
463 @param CharSet Point to the string to be found.\r
464\r
465**/\r
748edcd5
PB
466UINTN\r
467EFIAPI\r
468StrSpn (\r
469 IN CHAR16 *String,\r
470 IN CHAR16 *CharSet\r
471 )\r
748edcd5
PB
472{\r
473 UINTN Count;\r
474 CHAR16 *Str1;\r
475 CHAR16 *Str2;\r
476\r
477 Count = 0;\r
478\r
479 for (Str1 = String; *Str1 != L'\0'; Str1 ++) {\r
480 for (Str2 = CharSet; *Str2 != L'\0'; Str2 ++) {\r
481 if (*Str1 == *Str2) {\r
482 break;\r
483 }\r
484 }\r
485\r
486 if (*Str2 == L'\0') {\r
487 return Count;\r
488 }\r
489\r
490 Count ++;\r
491 }\r
492\r
493 return Count;\r
494}\r
495\r
e8a5ac7c
DB
496/**\r
497\r
498 Searches a string for the first occurrence of a character contained in a\r
499 specified buffer.\r
500\r
501 @param String Point to the string where to find the substring.\r
502 @param CharSet Point to the string to be found.\r
503\r
504**/\r
748edcd5
PB
505CHAR16 *\r
506EFIAPI\r
507StrBrk (\r
508 IN CHAR16 *String,\r
509 IN CHAR16 *CharSet\r
510 )\r
748edcd5
PB
511{\r
512 CHAR16 *Str1;\r
513 CHAR16 *Str2;\r
514\r
515 for (Str1 = String; *Str1 != L'\0'; Str1 ++) {\r
516 for (Str2 = CharSet; *Str2 != L'\0'; Str2 ++) {\r
517 if (*Str1 == *Str2) {\r
518 return (CHAR16 *) Str1;\r
519 }\r
520 }\r
521 }\r
522\r
523 return NULL;\r
524}\r
525\r
e8a5ac7c
DB
526/**\r
527\r
528 Find the next token after one or more specified characters.\r
529\r
530 @param String Point to the string where to find the substring.\r
531 @param CharSet Point to the string to be found.\r
532\r
533**/\r
748edcd5
PB
534CHAR16 *\r
535EFIAPI\r
536StrTokenLine (\r
537 IN CHAR16 *String OPTIONAL,\r
538 IN CHAR16 *CharSet\r
539 )\r
748edcd5
PB
540{\r
541 CHAR16 *Begin;\r
542 CHAR16 *End;\r
543\r
544 Begin = (String == NULL) ? mLineBuffer : String;\r
545 if (Begin == NULL) {\r
546 return NULL;\r
547 }\r
548\r
549 Begin += StrSpn (Begin, CharSet);\r
550 if (*Begin == L'\0') {\r
551 mLineBuffer = NULL;\r
552 return NULL;\r
553 }\r
554\r
555 End = StrBrk (Begin, CharSet);\r
556 if ((End != NULL) && (*End != L'\0')) {\r
557 *End = L'\0';\r
558 End ++;\r
559 }\r
560\r
561 mLineBuffer = End;\r
562 return Begin;\r
563}\r
564\r
e8a5ac7c
DB
565/**\r
566\r
567 Find the next token after one specificed characters.\r
568\r
569 @param String Point to the string where to find the substring.\r
570 @param CharSet Point to the string to be found.\r
571\r
572**/\r
748edcd5
PB
573CHAR16 *\r
574EFIAPI\r
575StrTokenField (\r
576 IN CHAR16 *String OPTIONAL,\r
577 IN CHAR16 *CharSet\r
578 )\r
748edcd5
PB
579{\r
580 CHAR16 *Begin;\r
581 CHAR16 *End;\r
582\r
583\r
584 Begin = (String == NULL) ? mFieldBuffer : String;\r
585 if (Begin == NULL) {\r
586 return NULL;\r
587 }\r
588\r
589 if (*Begin == L'\0') {\r
590 mFieldBuffer = NULL;\r
591 return NULL;\r
592 }\r
593\r
594 End = StrBrk (Begin, CharSet);\r
595 if ((End != NULL) && (*End != L'\0')) {\r
596 *End = L'\0';\r
597 End ++;\r
598 }\r
599\r
600 mFieldBuffer = End;\r
601 return Begin;\r
602}\r
603\r
d138a2e9
DB
604/**\r
605\r
606 Find the next token after one or more specified characters.\r
607\r
608 @param String Point to the string where to find the substring.\r
609 @param CharSet Point to the string to be found.\r
610\r
611**/\r
748edcd5
PB
612CHAR16 *\r
613EFIAPI\r
614StrGetNewTokenLine (\r
615 IN CHAR16 *String,\r
616 IN CHAR16 *CharSet\r
617 )\r
618{\r
619 return StrTokenLine (String, CharSet);\r
620}\r
621\r
d138a2e9
DB
622/**\r
623\r
624 Find the next token after one or more specified characters.\r
625\r
626 @param CharSet Point to the string to be found.\r
627\r
628**/\r
748edcd5
PB
629CHAR16 *\r
630EFIAPI\r
631StrGetNextTokenLine (\r
632 IN CHAR16 *CharSet\r
633 )\r
634{\r
635 return StrTokenLine (NULL, CharSet);\r
636}\r
637\r
d138a2e9
DB
638/**\r
639\r
640 Find the next token after one specificed characters.\r
641\r
642 @param String Point to the string where to find the substring.\r
643 @param CharSet Point to the string to be found.\r
644\r
645**/\r
748edcd5
PB
646CHAR16 *\r
647EFIAPI\r
648StrGetNewTokenField (\r
649 IN CHAR16 *String,\r
650 IN CHAR16 *CharSet\r
651 )\r
652{\r
653 return StrTokenField (String, CharSet);\r
654}\r
655\r
d138a2e9
DB
656/**\r
657\r
658 Find the next token after one specificed characters.\r
659\r
660 @param CharSet Point to the string to be found.\r
661\r
662**/\r
748edcd5
PB
663CHAR16 *\r
664EFIAPI\r
665StrGetNextTokenField (\r
666 IN CHAR16 *CharSet\r
667 )\r
668{\r
669 return StrTokenField (NULL, CharSet);\r
670}\r
671\r
d138a2e9
DB
672/**\r
673\r
674 Patch a character to the end of a string.\r
675\r
676 @param Buffer The string to be patched.\r
677 @param Patch The patch character.\r
678\r
679**/\r
748edcd5
PB
680VOID\r
681EFIAPI\r
682PatchForStrTokenAfter (\r
683 IN CHAR16 *Buffer,\r
684 IN CHAR16 Patch\r
685 )\r
686{\r
687 CHAR16 *Str;\r
688\r
689 if (Buffer == NULL) {\r
690 return ;\r
691 }\r
692\r
693 Str = Buffer;\r
694 while (*Str != 0) {\r
695 Str ++;\r
696 }\r
697 *Str = Patch;\r
698\r
532daaed 699 while (*(Str ++) != '\0') {\r
748edcd5
PB
700 if (*Str == 0) {\r
701 *Str = Patch;\r
702 } else {\r
703 break;\r
704 }\r
705 }\r
706\r
707 return ;\r
708}\r
709\r
d138a2e9
DB
710/**\r
711 Patch a character at the beginning of a string.\r
712\r
713 @param Buffer The string to be patched.\r
714 @param Patch The patch character.\r
715\r
716**/\r
748edcd5
PB
717VOID\r
718EFIAPI\r
719PatchForStrTokenBefore (\r
720 IN CHAR16 *Buffer,\r
721 IN CHAR16 Patch\r
722 )\r
723{\r
724 CHAR16 *Str;\r
725\r
726 if (Buffer == NULL) {\r
727 return ;\r
728 }\r
729\r
730 Str = Buffer;\r
532daaed 731 while (*(Str --) != '\0') {\r
748edcd5
PB
732 if ((*Str == 0) || (*Str == Patch)) {\r
733 *Str = Patch;\r
734 } else {\r
735 break;\r
736 }\r
737 }\r
738\r
739 return ;\r
740}\r
741\r
742CHAR8 *mAsciiLineBuffer = NULL;\r
743CHAR8 *mAsciiFieldBuffer = NULL;\r
744\r
e8a5ac7c
DB
745/**\r
746\r
747 Find the first substring.\r
748\r
749 @param String Point to the string where to find the substring.\r
750 @param CharSet Point to the string to be found.\r
751\r
752**/\r
748edcd5
PB
753UINTN\r
754EFIAPI\r
755AsciiStrSpn (\r
756 IN CHAR8 *String,\r
757 IN CHAR8 *CharSet\r
758 )\r
748edcd5
PB
759{\r
760 UINTN Count;\r
761 CHAR8 *Str1;\r
762 CHAR8 *Str2;\r
763\r
764 Count = 0;\r
765\r
766 for (Str1 = String; *Str1 != '\0'; Str1 ++) {\r
767 for (Str2 = CharSet; *Str2 != '\0'; Str2 ++) {\r
768 if (*Str1 == *Str2) {\r
769 break;\r
770 }\r
771 }\r
772\r
773 if (*Str2 == '\0') {\r
774 return Count;\r
775 }\r
776\r
777 Count ++;\r
778 }\r
779\r
780 return Count;\r
781}\r
782\r
e8a5ac7c
DB
783/**\r
784 Searches a string for the first occurrence of a character contained in a\r
785 specified buffer.\r
786\r
787 @param String Point to the string where to find the substring.\r
788 @param CharSet Point to the string to be found.\r
748edcd5 789\r
e8a5ac7c 790**/\r
748edcd5
PB
791CHAR8 *\r
792EFIAPI\r
793AsciiStrBrk (\r
794 IN CHAR8 *String,\r
795 IN CHAR8 *CharSet\r
796 )\r
748edcd5
PB
797{\r
798 CHAR8 *Str1;\r
799 CHAR8 *Str2;\r
800\r
801 for (Str1 = String; *Str1 != '\0'; Str1 ++) {\r
802 for (Str2 = CharSet; *Str2 != '\0'; Str2 ++) {\r
803 if (*Str1 == *Str2) {\r
804 return (CHAR8 *) Str1;\r
805 }\r
806 }\r
807 }\r
808\r
809 return NULL;\r
810}\r
811\r
e8a5ac7c
DB
812/**\r
813\r
814 Find the next token after one or more specified characters.\r
815\r
816 @param String Point to the string where to find the substring.\r
817 @param CharSet Point to the string to be found.\r
818\r
819**/\r
748edcd5
PB
820CHAR8 *\r
821EFIAPI\r
822AsciiStrTokenLine (\r
823 IN CHAR8 *String OPTIONAL,\r
824 IN CHAR8 *CharSet\r
825 )\r
748edcd5
PB
826{\r
827 CHAR8 *Begin;\r
828 CHAR8 *End;\r
829\r
830 Begin = (String == NULL) ? mAsciiLineBuffer : String;\r
831 if (Begin == NULL) {\r
832 return NULL;\r
833 }\r
834\r
835 Begin += AsciiStrSpn (Begin, CharSet);\r
836 if (*Begin == '\0') {\r
837 mAsciiLineBuffer = NULL;\r
838 return NULL;\r
839 }\r
840\r
841 End = AsciiStrBrk (Begin, CharSet);\r
842 if ((End != NULL) && (*End != '\0')) {\r
843 *End = '\0';\r
844 End ++;\r
845 }\r
846\r
847 mAsciiLineBuffer = End;\r
848 return Begin;\r
849}\r
850\r
e8a5ac7c
DB
851/**\r
852\r
853 Find the next token after one specificed characters.\r
854\r
855 @param String Point to the string where to find the substring.\r
856 @param CharSet Point to the string to be found.\r
857\r
858**/\r
748edcd5
PB
859CHAR8 *\r
860EFIAPI\r
861AsciiStrTokenField (\r
862 IN CHAR8 *String OPTIONAL,\r
863 IN CHAR8 *CharSet\r
864 )\r
748edcd5
PB
865{\r
866 CHAR8 *Begin;\r
867 CHAR8 *End;\r
868\r
869\r
870 Begin = (String == NULL) ? mAsciiFieldBuffer : String;\r
871 if (Begin == NULL) {\r
872 return NULL;\r
873 }\r
874\r
45b18ce5 875 if (*Begin == '\0') {\r
748edcd5
PB
876 mAsciiFieldBuffer = NULL;\r
877 return NULL;\r
878 }\r
879\r
880 End = AsciiStrBrk (Begin, CharSet);\r
881 if ((End != NULL) && (*End != '\0')) {\r
882 *End = '\0';\r
883 End ++;\r
884 }\r
885\r
886 mAsciiFieldBuffer = End;\r
887 return Begin;\r
888}\r
889\r
d138a2e9
DB
890/**\r
891\r
892 Find the next token after one or more specified characters.\r
893\r
894 @param String Point to the string where to find the substring.\r
895 @param CharSet Point to the string to be found.\r
896\r
897**/\r
748edcd5
PB
898CHAR8 *\r
899EFIAPI\r
900AsciiStrGetNewTokenLine (\r
901 IN CHAR8 *String,\r
902 IN CHAR8 *CharSet\r
903 )\r
904{\r
905 return AsciiStrTokenLine (String, CharSet);\r
906}\r
907\r
d138a2e9
DB
908/**\r
909\r
910 Find the next token after one or more specified characters.\r
911\r
912 @param CharSet Point to the string to be found.\r
913\r
914**/\r
748edcd5
PB
915CHAR8 *\r
916EFIAPI\r
917AsciiStrGetNextTokenLine (\r
918 IN CHAR8 *CharSet\r
919 )\r
920{\r
921 return AsciiStrTokenLine (NULL, CharSet);\r
922}\r
923\r
d138a2e9
DB
924/**\r
925\r
926 Find the next token after one specificed characters.\r
927\r
928 @param String Point to the string where to find the substring.\r
929 @param CharSet Point to the string to be found.\r
930\r
931**/\r
748edcd5
PB
932CHAR8 *\r
933EFIAPI\r
934AsciiStrGetNewTokenField (\r
935 IN CHAR8 *String,\r
936 IN CHAR8 *CharSet\r
937 )\r
938{\r
939 return AsciiStrTokenField (String, CharSet);\r
940}\r
941\r
d138a2e9
DB
942/**\r
943\r
944 Find the next token after one specificed characters.\r
945\r
946 @param CharSet Point to the string to be found.\r
947\r
948**/\r
748edcd5
PB
949CHAR8 *\r
950EFIAPI\r
951AsciiStrGetNextTokenField (\r
952 IN CHAR8 *CharSet\r
953 )\r
954{\r
955 return AsciiStrTokenField (NULL, CharSet);\r
956}\r
957\r
d138a2e9
DB
958/**\r
959\r
960 Patch a character to the end of a string.\r
961\r
962 @param Buffer The string to be patched.\r
963 @param Patch The patch character.\r
964\r
965**/\r
748edcd5
PB
966VOID\r
967EFIAPI\r
968PatchForAsciiStrTokenAfter (\r
969 IN CHAR8 *Buffer,\r
970 IN CHAR8 Patch\r
971 )\r
972{\r
973 CHAR8 *Str;\r
974\r
975 if (Buffer == NULL) {\r
976 return ;\r
977 }\r
978\r
979 Str = Buffer;\r
980 while (*Str != 0) {\r
981 Str ++;\r
982 }\r
983 *Str = Patch;\r
984\r
532daaed 985 while (*(Str ++) != '\0') {\r
748edcd5
PB
986 if (*Str == 0) {\r
987 *Str = Patch;\r
988 } else {\r
989 break;\r
990 }\r
991 }\r
992\r
993 return ;\r
994}\r
995\r
d138a2e9
DB
996/**\r
997 Patch a character at the beginning of a string.\r
998\r
999 @param Buffer The string to be patched.\r
1000 @param Patch The patch character.\r
1001\r
1002**/\r
748edcd5
PB
1003VOID\r
1004EFIAPI\r
1005PatchForAsciiStrTokenBefore (\r
1006 IN CHAR8 *Buffer,\r
1007 IN CHAR8 Patch\r
1008 )\r
1009{\r
1010 CHAR8 *Str;\r
1011\r
1012 if (Buffer == NULL) {\r
1013 return ;\r
1014 }\r
1015\r
1016 Str = Buffer;\r
532daaed 1017 while (*(Str --) != '\0') {\r
748edcd5
PB
1018 if ((*Str == 0) || (*Str == Patch)) {\r
1019 *Str = Patch;\r
1020 } else {\r
1021 break;\r
1022 }\r
1023 }\r
1024\r
1025 return ;\r
1026}\r