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