]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c
MdeModulePkg/EbcDxe: Fix incorrect Copyright format
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbSupportString.c
CommitLineData
e8a5ac7c 1/** @file\r
748edcd5 2\r
f42f22f5 3Copyright (c) 2007 - 2016, 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
d138a2e9
DB
310/**\r
311\r
312 Convert the character to upper case.\r
313\r
314 @param Chr the character to be converted.\r
315\r
316**/\r
748edcd5
PB
317STATIC\r
318CHAR16\r
319UnicodeToUpper (\r
320 IN CHAR16 Chr\r
321 )\r
322{\r
323 return (Chr >= L'a' && Chr <= L'z') ? Chr - (L'a' - L'A') : Chr;\r
324}\r
325\r
d138a2e9
DB
326/**\r
327\r
328 Convert the character to upper case.\r
329\r
330 @param Chr the character to be converted.\r
331\r
332**/\r
748edcd5
PB
333STATIC\r
334CHAR8\r
335AsciiToUpper (\r
336 IN CHAR8 Chr\r
337 )\r
338{\r
339 return (Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr;\r
340}\r
341\r
e8a5ac7c 342/**\r
748edcd5
PB
343 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.\r
344\r
e8a5ac7c 345 @param String - Unicode String to process\r
748edcd5 346\r
e8a5ac7c 347 @param String2 - Ascii string to process\r
748edcd5 348\r
e8a5ac7c 349 @return Return a positive integer if String is lexicall greater than String2; Zero if\r
748edcd5
PB
350 the two strings are identical; and a negative interger if String is lexically\r
351 less than String2.\r
352\r
e8a5ac7c
DB
353**/\r
354INTN\r
355EFIAPI\r
356StrCmpUnicodeAndAscii (\r
357 IN CHAR16 *String,\r
358 IN CHAR8 *String2\r
359 )\r
748edcd5 360{\r
532daaed 361 while (*String != '\0') {\r
748edcd5
PB
362 if (*String != (CHAR16)*String2) {\r
363 break;\r
364 }\r
365\r
366 String += 1;\r
367 String2 += 1;\r
368 }\r
369\r
370 return (*String - (CHAR16)*String2);\r
371}\r
372\r
e8a5ac7c 373/**\r
748edcd5 374\r
748edcd5
PB
375 Compare the Unicode string pointed by String to the string pointed by String2.\r
376\r
e8a5ac7c
DB
377 @param String - Unicode String to process\r
378 @param String2 - Unicode string to process\r
748edcd5 379\r
e8a5ac7c 380 @return Return a positive integer if String is lexically greater than String2; Zero if\r
748edcd5
PB
381 the two strings are identical; and a negative integer if String is lexically\r
382 less than String2.\r
383\r
e8a5ac7c
DB
384**/\r
385INTN\r
386EFIAPI\r
387StriCmp (\r
388 IN CHAR16 *String,\r
389 IN CHAR16 *String2\r
390 )\r
748edcd5
PB
391{\r
392 while ((*String != L'\0') &&\r
393 (UnicodeToUpper (*String) == UnicodeToUpper (*String2))) {\r
394 String++;\r
395 String2++;\r
396 }\r
397\r
398 return UnicodeToUpper (*String) - UnicodeToUpper (*String2);\r
399}\r
400\r
e8a5ac7c 401/**\r
748edcd5 402\r
748edcd5
PB
403 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.\r
404\r
e8a5ac7c
DB
405 @param String - Unicode String to process\r
406 @param String2 - Ascii string to process\r
748edcd5 407\r
e8a5ac7c 408 @return Return a positive integer if String is lexically greater than String2; Zero if\r
748edcd5
PB
409 the two strings are identical; and a negative integer if String is lexically\r
410 less than String2.\r
411\r
e8a5ac7c
DB
412**/\r
413INTN\r
414EFIAPI\r
415StriCmpUnicodeAndAscii (\r
416 IN CHAR16 *String,\r
417 IN CHAR8 *String2\r
418 )\r
748edcd5
PB
419{\r
420 while ((*String != L'\0') &&\r
421 (UnicodeToUpper (*String) == (CHAR16)AsciiToUpper (*String2))) {\r
422 String++;\r
423 String2++;\r
424 }\r
425\r
426 return UnicodeToUpper (*String) - (CHAR16)AsciiToUpper (*String2);\r
427}\r
428\r
e8a5ac7c
DB
429/**\r
430\r
431 Verify if the string is end with the sub string.\r
432\r
433 @param Str - The string where to search the sub string\r
434 @param SubStr - The substring.\r
435\r
436**/\r
748edcd5
PB
437BOOLEAN\r
438EFIAPI\r
439StrEndWith (\r
440 IN CHAR16 *Str,\r
441 IN CHAR16 *SubStr\r
442 )\r
748edcd5
PB
443{\r
444 CHAR16 *Temp;\r
445\r
446 if ((Str == NULL) || (SubStr == NULL) || (StrLen(Str) < StrLen(SubStr))) {\r
447 return FALSE;\r
448 }\r
449\r
450 Temp = Str + StrLen(Str) - StrLen(SubStr);\r
451\r
452 //\r
453 // Compare\r
454 //\r
455 if (StriCmp (Temp, SubStr) == 0) {\r
456 return TRUE;\r
457 } else {\r
458 return FALSE;\r
459 }\r
460}\r
461\r
e8a5ac7c
DB
462/**\r
463 Duplicate a string.\r
464\r
465 @param Src The string to be duplicated.\r
466\r
467**/\r
748edcd5
PB
468CHAR16 *\r
469EFIAPI\r
470StrDuplicate (\r
471 IN CHAR16 *Src\r
472 )\r
748edcd5
PB
473{\r
474 CHAR16 *Dest;\r
475 UINTN Size;\r
476\r
477 Size = (StrLen(Src) + 1) * sizeof(CHAR16);\r
478 Dest = AllocateZeroPool (Size);\r
532daaed 479 if (Dest != NULL) {\r
748edcd5
PB
480 CopyMem (Dest, Src, Size);\r
481 }\r
482 return Dest;\r
483}\r
484\r
485\r
486CHAR16 *mLineBuffer = NULL;\r
487CHAR16 *mFieldBuffer = NULL;\r
488\r
e8a5ac7c
DB
489/**\r
490\r
491 Find the first substring.\r
492\r
493 @param String Point to the string where to find the substring.\r
494 @param CharSet Point to the string to be found.\r
495\r
496**/\r
748edcd5
PB
497UINTN\r
498EFIAPI\r
499StrSpn (\r
500 IN CHAR16 *String,\r
501 IN CHAR16 *CharSet\r
502 )\r
748edcd5
PB
503{\r
504 UINTN Count;\r
505 CHAR16 *Str1;\r
506 CHAR16 *Str2;\r
507\r
508 Count = 0;\r
509\r
510 for (Str1 = String; *Str1 != L'\0'; Str1 ++) {\r
511 for (Str2 = CharSet; *Str2 != L'\0'; Str2 ++) {\r
512 if (*Str1 == *Str2) {\r
513 break;\r
514 }\r
515 }\r
516\r
517 if (*Str2 == L'\0') {\r
518 return Count;\r
519 }\r
520\r
521 Count ++;\r
522 }\r
523\r
524 return Count;\r
525}\r
526\r
e8a5ac7c
DB
527/**\r
528\r
529 Searches a string for the first occurrence of a character contained in a\r
530 specified buffer.\r
531\r
532 @param String Point to the string where to find the substring.\r
533 @param CharSet Point to the string to be found.\r
534\r
535**/\r
748edcd5
PB
536CHAR16 *\r
537EFIAPI\r
538StrBrk (\r
539 IN CHAR16 *String,\r
540 IN CHAR16 *CharSet\r
541 )\r
748edcd5
PB
542{\r
543 CHAR16 *Str1;\r
544 CHAR16 *Str2;\r
545\r
546 for (Str1 = String; *Str1 != L'\0'; Str1 ++) {\r
547 for (Str2 = CharSet; *Str2 != L'\0'; Str2 ++) {\r
548 if (*Str1 == *Str2) {\r
549 return (CHAR16 *) Str1;\r
550 }\r
551 }\r
552 }\r
553\r
554 return NULL;\r
555}\r
556\r
e8a5ac7c
DB
557/**\r
558\r
559 Find the next token after one or more specified characters.\r
560\r
561 @param String Point to the string where to find the substring.\r
562 @param CharSet Point to the string to be found.\r
563\r
564**/\r
748edcd5
PB
565CHAR16 *\r
566EFIAPI\r
567StrTokenLine (\r
568 IN CHAR16 *String OPTIONAL,\r
569 IN CHAR16 *CharSet\r
570 )\r
748edcd5
PB
571{\r
572 CHAR16 *Begin;\r
573 CHAR16 *End;\r
574\r
575 Begin = (String == NULL) ? mLineBuffer : String;\r
576 if (Begin == NULL) {\r
577 return NULL;\r
578 }\r
579\r
580 Begin += StrSpn (Begin, CharSet);\r
581 if (*Begin == L'\0') {\r
582 mLineBuffer = NULL;\r
583 return NULL;\r
584 }\r
585\r
586 End = StrBrk (Begin, CharSet);\r
587 if ((End != NULL) && (*End != L'\0')) {\r
588 *End = L'\0';\r
589 End ++;\r
590 }\r
591\r
592 mLineBuffer = End;\r
593 return Begin;\r
594}\r
595\r
e8a5ac7c
DB
596/**\r
597\r
598 Find the next token after one specificed characters.\r
599\r
600 @param String Point to the string where to find the substring.\r
601 @param CharSet Point to the string to be found.\r
602\r
603**/\r
748edcd5
PB
604CHAR16 *\r
605EFIAPI\r
606StrTokenField (\r
607 IN CHAR16 *String OPTIONAL,\r
608 IN CHAR16 *CharSet\r
609 )\r
748edcd5
PB
610{\r
611 CHAR16 *Begin;\r
612 CHAR16 *End;\r
613\r
614\r
615 Begin = (String == NULL) ? mFieldBuffer : String;\r
616 if (Begin == NULL) {\r
617 return NULL;\r
618 }\r
619\r
620 if (*Begin == L'\0') {\r
621 mFieldBuffer = NULL;\r
622 return NULL;\r
623 }\r
624\r
625 End = StrBrk (Begin, CharSet);\r
626 if ((End != NULL) && (*End != L'\0')) {\r
627 *End = L'\0';\r
628 End ++;\r
629 }\r
630\r
631 mFieldBuffer = End;\r
632 return Begin;\r
633}\r
634\r
d138a2e9
DB
635/**\r
636\r
637 Find the next token after one or more specified characters.\r
638\r
639 @param String Point to the string where to find the substring.\r
640 @param CharSet Point to the string to be found.\r
641\r
642**/\r
748edcd5
PB
643CHAR16 *\r
644EFIAPI\r
645StrGetNewTokenLine (\r
646 IN CHAR16 *String,\r
647 IN CHAR16 *CharSet\r
648 )\r
649{\r
650 return StrTokenLine (String, CharSet);\r
651}\r
652\r
d138a2e9
DB
653/**\r
654\r
655 Find the next token after one or more specified characters.\r
656\r
657 @param CharSet Point to the string to be found.\r
658\r
659**/\r
748edcd5
PB
660CHAR16 *\r
661EFIAPI\r
662StrGetNextTokenLine (\r
663 IN CHAR16 *CharSet\r
664 )\r
665{\r
666 return StrTokenLine (NULL, CharSet);\r
667}\r
668\r
d138a2e9
DB
669/**\r
670\r
671 Find the next token after one specificed characters.\r
672\r
673 @param String Point to the string where to find the substring.\r
674 @param CharSet Point to the string to be found.\r
675\r
676**/\r
748edcd5
PB
677CHAR16 *\r
678EFIAPI\r
679StrGetNewTokenField (\r
680 IN CHAR16 *String,\r
681 IN CHAR16 *CharSet\r
682 )\r
683{\r
684 return StrTokenField (String, CharSet);\r
685}\r
686\r
d138a2e9
DB
687/**\r
688\r
689 Find the next token after one specificed characters.\r
690\r
691 @param CharSet Point to the string to be found.\r
692\r
693**/\r
748edcd5
PB
694CHAR16 *\r
695EFIAPI\r
696StrGetNextTokenField (\r
697 IN CHAR16 *CharSet\r
698 )\r
699{\r
700 return StrTokenField (NULL, CharSet);\r
701}\r
702\r
d138a2e9
DB
703/**\r
704\r
705 Patch a character to the end of a string.\r
706\r
707 @param Buffer The string to be patched.\r
708 @param Patch The patch character.\r
709\r
710**/\r
748edcd5
PB
711VOID\r
712EFIAPI\r
713PatchForStrTokenAfter (\r
714 IN CHAR16 *Buffer,\r
715 IN CHAR16 Patch\r
716 )\r
717{\r
718 CHAR16 *Str;\r
719\r
720 if (Buffer == NULL) {\r
721 return ;\r
722 }\r
723\r
724 Str = Buffer;\r
725 while (*Str != 0) {\r
726 Str ++;\r
727 }\r
728 *Str = Patch;\r
729\r
532daaed 730 while (*(Str ++) != '\0') {\r
748edcd5
PB
731 if (*Str == 0) {\r
732 *Str = Patch;\r
733 } else {\r
734 break;\r
735 }\r
736 }\r
737\r
738 return ;\r
739}\r
740\r
d138a2e9
DB
741/**\r
742 Patch a character at the beginning of a string.\r
743\r
744 @param Buffer The string to be patched.\r
745 @param Patch The patch character.\r
746\r
747**/\r
748edcd5
PB
748VOID\r
749EFIAPI\r
750PatchForStrTokenBefore (\r
751 IN CHAR16 *Buffer,\r
752 IN CHAR16 Patch\r
753 )\r
754{\r
755 CHAR16 *Str;\r
756\r
757 if (Buffer == NULL) {\r
758 return ;\r
759 }\r
760\r
761 Str = Buffer;\r
532daaed 762 while (*(Str --) != '\0') {\r
748edcd5
PB
763 if ((*Str == 0) || (*Str == Patch)) {\r
764 *Str = Patch;\r
765 } else {\r
766 break;\r
767 }\r
768 }\r
769\r
770 return ;\r
771}\r
772\r
773CHAR8 *mAsciiLineBuffer = NULL;\r
774CHAR8 *mAsciiFieldBuffer = NULL;\r
775\r
e8a5ac7c
DB
776/**\r
777\r
778 Find the first substring.\r
779\r
780 @param String Point to the string where to find the substring.\r
781 @param CharSet Point to the string to be found.\r
782\r
783**/\r
748edcd5
PB
784UINTN\r
785EFIAPI\r
786AsciiStrSpn (\r
787 IN CHAR8 *String,\r
788 IN CHAR8 *CharSet\r
789 )\r
748edcd5
PB
790{\r
791 UINTN Count;\r
792 CHAR8 *Str1;\r
793 CHAR8 *Str2;\r
794\r
795 Count = 0;\r
796\r
797 for (Str1 = String; *Str1 != '\0'; Str1 ++) {\r
798 for (Str2 = CharSet; *Str2 != '\0'; Str2 ++) {\r
799 if (*Str1 == *Str2) {\r
800 break;\r
801 }\r
802 }\r
803\r
804 if (*Str2 == '\0') {\r
805 return Count;\r
806 }\r
807\r
808 Count ++;\r
809 }\r
810\r
811 return Count;\r
812}\r
813\r
e8a5ac7c
DB
814/**\r
815 Searches a string for the first occurrence of a character contained in a\r
816 specified buffer.\r
817\r
818 @param String Point to the string where to find the substring.\r
819 @param CharSet Point to the string to be found.\r
748edcd5 820\r
e8a5ac7c 821**/\r
748edcd5
PB
822CHAR8 *\r
823EFIAPI\r
824AsciiStrBrk (\r
825 IN CHAR8 *String,\r
826 IN CHAR8 *CharSet\r
827 )\r
748edcd5
PB
828{\r
829 CHAR8 *Str1;\r
830 CHAR8 *Str2;\r
831\r
832 for (Str1 = String; *Str1 != '\0'; Str1 ++) {\r
833 for (Str2 = CharSet; *Str2 != '\0'; Str2 ++) {\r
834 if (*Str1 == *Str2) {\r
835 return (CHAR8 *) Str1;\r
836 }\r
837 }\r
838 }\r
839\r
840 return NULL;\r
841}\r
842\r
e8a5ac7c
DB
843/**\r
844\r
845 Find the next token after one or more specified characters.\r
846\r
847 @param String Point to the string where to find the substring.\r
848 @param CharSet Point to the string to be found.\r
849\r
850**/\r
748edcd5
PB
851CHAR8 *\r
852EFIAPI\r
853AsciiStrTokenLine (\r
854 IN CHAR8 *String OPTIONAL,\r
855 IN CHAR8 *CharSet\r
856 )\r
748edcd5
PB
857{\r
858 CHAR8 *Begin;\r
859 CHAR8 *End;\r
860\r
861 Begin = (String == NULL) ? mAsciiLineBuffer : String;\r
862 if (Begin == NULL) {\r
863 return NULL;\r
864 }\r
865\r
866 Begin += AsciiStrSpn (Begin, CharSet);\r
867 if (*Begin == '\0') {\r
868 mAsciiLineBuffer = NULL;\r
869 return NULL;\r
870 }\r
871\r
872 End = AsciiStrBrk (Begin, CharSet);\r
873 if ((End != NULL) && (*End != '\0')) {\r
874 *End = '\0';\r
875 End ++;\r
876 }\r
877\r
878 mAsciiLineBuffer = End;\r
879 return Begin;\r
880}\r
881\r
e8a5ac7c
DB
882/**\r
883\r
884 Find the next token after one specificed characters.\r
885\r
886 @param String Point to the string where to find the substring.\r
887 @param CharSet Point to the string to be found.\r
888\r
889**/\r
748edcd5
PB
890CHAR8 *\r
891EFIAPI\r
892AsciiStrTokenField (\r
893 IN CHAR8 *String OPTIONAL,\r
894 IN CHAR8 *CharSet\r
895 )\r
748edcd5
PB
896{\r
897 CHAR8 *Begin;\r
898 CHAR8 *End;\r
899\r
900\r
901 Begin = (String == NULL) ? mAsciiFieldBuffer : String;\r
902 if (Begin == NULL) {\r
903 return NULL;\r
904 }\r
905\r
45b18ce5 906 if (*Begin == '\0') {\r
748edcd5
PB
907 mAsciiFieldBuffer = NULL;\r
908 return NULL;\r
909 }\r
910\r
911 End = AsciiStrBrk (Begin, CharSet);\r
912 if ((End != NULL) && (*End != '\0')) {\r
913 *End = '\0';\r
914 End ++;\r
915 }\r
916\r
917 mAsciiFieldBuffer = End;\r
918 return Begin;\r
919}\r
920\r
d138a2e9
DB
921/**\r
922\r
923 Find the next token after one or more specified characters.\r
924\r
925 @param String Point to the string where to find the substring.\r
926 @param CharSet Point to the string to be found.\r
927\r
928**/\r
748edcd5
PB
929CHAR8 *\r
930EFIAPI\r
931AsciiStrGetNewTokenLine (\r
932 IN CHAR8 *String,\r
933 IN CHAR8 *CharSet\r
934 )\r
935{\r
936 return AsciiStrTokenLine (String, CharSet);\r
937}\r
938\r
d138a2e9
DB
939/**\r
940\r
941 Find the next token after one or more specified characters.\r
942\r
943 @param CharSet Point to the string to be found.\r
944\r
945**/\r
748edcd5
PB
946CHAR8 *\r
947EFIAPI\r
948AsciiStrGetNextTokenLine (\r
949 IN CHAR8 *CharSet\r
950 )\r
951{\r
952 return AsciiStrTokenLine (NULL, CharSet);\r
953}\r
954\r
d138a2e9
DB
955/**\r
956\r
957 Find the next token after one specificed characters.\r
958\r
959 @param String Point to the string where to find the substring.\r
960 @param CharSet Point to the string to be found.\r
961\r
962**/\r
748edcd5
PB
963CHAR8 *\r
964EFIAPI\r
965AsciiStrGetNewTokenField (\r
966 IN CHAR8 *String,\r
967 IN CHAR8 *CharSet\r
968 )\r
969{\r
970 return AsciiStrTokenField (String, CharSet);\r
971}\r
972\r
d138a2e9
DB
973/**\r
974\r
975 Find the next token after one specificed characters.\r
976\r
977 @param CharSet Point to the string to be found.\r
978\r
979**/\r
748edcd5
PB
980CHAR8 *\r
981EFIAPI\r
982AsciiStrGetNextTokenField (\r
983 IN CHAR8 *CharSet\r
984 )\r
985{\r
986 return AsciiStrTokenField (NULL, CharSet);\r
987}\r
988\r
d138a2e9
DB
989/**\r
990\r
991 Patch a character to the end of a string.\r
992\r
993 @param Buffer The string to be patched.\r
994 @param Patch The patch character.\r
995\r
996**/\r
748edcd5
PB
997VOID\r
998EFIAPI\r
999PatchForAsciiStrTokenAfter (\r
1000 IN CHAR8 *Buffer,\r
1001 IN CHAR8 Patch\r
1002 )\r
1003{\r
1004 CHAR8 *Str;\r
1005\r
1006 if (Buffer == NULL) {\r
1007 return ;\r
1008 }\r
1009\r
1010 Str = Buffer;\r
1011 while (*Str != 0) {\r
1012 Str ++;\r
1013 }\r
1014 *Str = Patch;\r
1015\r
532daaed 1016 while (*(Str ++) != '\0') {\r
748edcd5
PB
1017 if (*Str == 0) {\r
1018 *Str = Patch;\r
1019 } else {\r
1020 break;\r
1021 }\r
1022 }\r
1023\r
1024 return ;\r
1025}\r
1026\r
d138a2e9
DB
1027/**\r
1028 Patch a character at the beginning of a string.\r
1029\r
1030 @param Buffer The string to be patched.\r
1031 @param Patch The patch character.\r
1032\r
1033**/\r
748edcd5
PB
1034VOID\r
1035EFIAPI\r
1036PatchForAsciiStrTokenBefore (\r
1037 IN CHAR8 *Buffer,\r
1038 IN CHAR8 Patch\r
1039 )\r
1040{\r
1041 CHAR8 *Str;\r
1042\r
1043 if (Buffer == NULL) {\r
1044 return ;\r
1045 }\r
1046\r
1047 Str = Buffer;\r
532daaed 1048 while (*(Str --) != '\0') {\r
748edcd5
PB
1049 if ((*Str == 0) || (*Str == Patch)) {\r
1050 *Str = Patch;\r
1051 } else {\r
1052 break;\r
1053 }\r
1054 }\r
1055\r
1056 return ;\r
1057}\r