]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c
3 Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Convert hex string to uint.
15 @param Str - The string
30 MaxVal
= (UINTN
)-1 >> 4;
32 // skip preceeding white space
34 while (*Str
!= '\0' && *Str
== ' ') {
39 // skip preceeding zeros
41 while (*Str
!= '\0' && *Str
== '0') {
46 // skip preceeding white space
48 if ((*Str
!= '\0') && ((*Str
== 'x') || (*Str
== 'X'))) {
57 while (TempChar
!= '\0') {
58 if ((TempChar
>= 'a') && (TempChar
<= 'f')) {
59 TempChar
-= 'a' - 'A';
62 if (((TempChar
>= '0') && (TempChar
<= '9')) || ((TempChar
>= 'A') && (TempChar
<= 'F'))) {
63 if (RetVal
> MaxVal
) {
67 RetVal
= (RetVal
<< 4) | (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
80 Convert hex string to uint.
82 @param Str - The string
97 MaxVal
= RShiftU64 ((UINT64
)-1, 4);
99 // skip preceeding white space
101 while (*Str
!= '\0' && *Str
== ' ') {
106 // skip preceeding zeros
108 while (*Str
!= '\0' && *Str
== '0') {
113 // skip preceeding white space
115 if ((*Str
!= '\0') && ((*Str
== 'x') || (*Str
== 'X'))) {
120 // convert hex digits
124 while (TempChar
!= '\0') {
125 if ((TempChar
>= 'a') && (TempChar
<= 'f')) {
126 TempChar
-= 'a' - 'A';
129 if (((TempChar
>= '0') && (TempChar
<= '9')) || ((TempChar
>= 'A') && (TempChar
<= 'F'))) {
130 if (RetVal
> MaxVal
) {
134 RetVal
= LShiftU64 (RetVal
, 4);
135 RetVal
= RetVal
+ (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
148 Convert hex string to uint.
150 @param Str - The string
164 ASSERT (Str
!= NULL
);
166 MaxVal
= (UINTN
)-1 / 10;
167 ResteVal
= (UINTN
)-1 % 10;
169 // skip preceeding white space
171 while (*Str
!= '\0' && *Str
== ' ') {
180 while (TempChar
!= '\0') {
181 if ((TempChar
>= '0') && (TempChar
<= '9')) {
182 if ((RetVal
> MaxVal
) || ((RetVal
== MaxVal
) && (TempChar
- '0' > (INTN
)ResteVal
))) {
186 RetVal
= (RetVal
* 10) + TempChar
- '0';
199 Convert hex string to uint.
201 @param Str - The string
214 ASSERT (Str
!= NULL
);
216 MaxVal
= (UINTN
)-1 >> 4;
218 // skip preceeding white space
220 while (*Str
!= '\0' && *Str
== ' ') {
225 // skip preceeding zeros
227 while (*Str
!= '\0' && *Str
== '0') {
232 // skip preceeding white space
234 if ((*Str
!= '\0') && ((*Str
== 'x') || (*Str
== 'X'))) {
239 // convert hex digits
243 while (TempChar
!= '\0') {
244 if ((TempChar
>= 'a') && (TempChar
<= 'f')) {
245 TempChar
-= 'a' - 'A';
248 if (((TempChar
>= '0') && (TempChar
<= '9')) || ((TempChar
>= 'A') && (TempChar
<= 'F'))) {
249 if (RetVal
> MaxVal
) {
253 RetVal
= (RetVal
<< 4) | (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
266 Convert hex string to uint.
268 @param Str - The string
282 ASSERT (Str
!= NULL
);
284 MaxVal
= (UINTN
)-1 / 10;
285 ResteVal
= (UINTN
)-1 % 10;
287 // skip preceeding white space
289 while (*Str
!= '\0' && *Str
== ' ') {
298 while (TempChar
!= '\0') {
299 if ((TempChar
>= '0') && (TempChar
<= '9')) {
300 if ((RetVal
> MaxVal
) || ((RetVal
== MaxVal
) && (TempChar
- '0' > (INTN
)ResteVal
))) {
304 RetVal
= (RetVal
* 10) + TempChar
- '0';
316 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
318 @param String - Unicode String to process
320 @param String2 - Ascii string to process
322 @return Return a positive integer if String is lexicall greater than String2; Zero if
323 the two strings are identical; and a negative interger if String is lexically
329 StrCmpUnicodeAndAscii (
334 while (*String
!= '\0') {
335 if (*String
!= (CHAR16
)*String2
) {
343 return (*String
- (CHAR16
)*String2
);
348 Compare the Unicode string pointed by String to the string pointed by String2.
350 @param String - Unicode String to process
351 @param String2 - Unicode string to process
353 @return Return a positive integer if String is lexically greater than String2; Zero if
354 the two strings are identical; and a negative integer if String is lexically
365 while ((*String
!= L
'\0') &&
366 (CharToUpper (*String
) == CharToUpper (*String2
)))
372 return CharToUpper (*String
) - CharToUpper (*String2
);
377 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
379 @param String - Unicode String to process
380 @param String2 - Ascii string to process
382 @return Return a positive integer if String is lexically greater than String2; Zero if
383 the two strings are identical; and a negative integer if String is lexically
389 StriCmpUnicodeAndAscii (
394 while ((*String
!= L
'\0') &&
395 (CharToUpper (*String
) == (CHAR16
)AsciiCharToUpper (*String2
)))
401 return CharToUpper (*String
) - (CHAR16
)AsciiCharToUpper (*String2
);
406 Verify if the string is end with the sub string.
408 @param Str - The string where to search the sub string
409 @param SubStr - The substring.
421 if ((Str
== NULL
) || (SubStr
== NULL
) || (StrLen (Str
) < StrLen (SubStr
))) {
425 Temp
= Str
+ StrLen (Str
) - StrLen (SubStr
);
430 if (StriCmp (Temp
, SubStr
) == 0) {
440 @param Src The string to be duplicated.
452 Size
= (StrLen (Src
) + 1) * sizeof (CHAR16
);
453 Dest
= AllocateZeroPool (Size
);
455 CopyMem (Dest
, Src
, Size
);
461 CHAR16
*mLineBuffer
= NULL
;
462 CHAR16
*mFieldBuffer
= NULL
;
466 Find the first substring.
468 @param String Point to the string where to find the substring.
469 @param CharSet Point to the string to be found.
485 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
486 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
487 if (*Str1
== *Str2
) {
492 if (*Str2
== L
'\0') {
504 Searches a string for the first occurrence of a character contained in a
507 @param String Point to the string where to find the substring.
508 @param CharSet Point to the string to be found.
521 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
522 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
523 if (*Str1
== *Str2
) {
524 return (CHAR16
*)Str1
;
534 Find the next token after one or more specified characters.
536 @param String Point to the string where to find the substring.
537 @param CharSet Point to the string to be found.
543 IN CHAR16
*String OPTIONAL
,
550 Begin
= (String
== NULL
) ? mLineBuffer
: String
;
555 Begin
+= StrSpn (Begin
, CharSet
);
556 if (*Begin
== L
'\0') {
561 End
= StrBrk (Begin
, CharSet
);
562 if ((End
!= NULL
) && (*End
!= L
'\0')) {
573 Find the next token after one specificed characters.
575 @param String Point to the string where to find the substring.
576 @param CharSet Point to the string to be found.
582 IN CHAR16
*String OPTIONAL
,
589 Begin
= (String
== NULL
) ? mFieldBuffer
: String
;
594 if (*Begin
== L
'\0') {
599 End
= StrBrk (Begin
, CharSet
);
600 if ((End
!= NULL
) && (*End
!= L
'\0')) {
611 Find the next token after one or more specified characters.
613 @param String Point to the string where to find the substring.
614 @param CharSet Point to the string to be found.
624 return StrTokenLine (String
, CharSet
);
629 Find the next token after one or more specified characters.
631 @param CharSet Point to the string to be found.
636 StrGetNextTokenLine (
640 return StrTokenLine (NULL
, CharSet
);
645 Find the next token after one specificed characters.
647 @param String Point to the string where to find the substring.
648 @param CharSet Point to the string to be found.
653 StrGetNewTokenField (
658 return StrTokenField (String
, CharSet
);
663 Find the next token after one specificed characters.
665 @param CharSet Point to the string to be found.
670 StrGetNextTokenField (
674 return StrTokenField (NULL
, CharSet
);
679 Patch a character to the end of a string.
681 @param Buffer The string to be patched.
682 @param Patch The patch character.
687 PatchForStrTokenAfter (
694 if (Buffer
== NULL
) {
705 while (*(Str
++) != '\0') {
717 Patch a character at the beginning of a string.
719 @param Buffer The string to be patched.
720 @param Patch The patch character.
725 PatchForStrTokenBefore (
732 if (Buffer
== NULL
) {
737 while (*(Str
--) != '\0') {
738 if ((*Str
== 0) || (*Str
== Patch
)) {
748 CHAR8
*mAsciiLineBuffer
= NULL
;
749 CHAR8
*mAsciiFieldBuffer
= NULL
;
753 Find the first substring.
755 @param String Point to the string where to find the substring.
756 @param CharSet Point to the string to be found.
772 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
773 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
774 if (*Str1
== *Str2
) {
790 Searches a string for the first occurrence of a character contained in a
793 @param String Point to the string where to find the substring.
794 @param CharSet Point to the string to be found.
807 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
808 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
809 if (*Str1
== *Str2
) {
810 return (CHAR8
*)Str1
;
820 Find the next token after one or more specified characters.
822 @param String Point to the string where to find the substring.
823 @param CharSet Point to the string to be found.
829 IN CHAR8
*String OPTIONAL
,
836 Begin
= (String
== NULL
) ? mAsciiLineBuffer
: String
;
841 Begin
+= AsciiStrSpn (Begin
, CharSet
);
842 if (*Begin
== '\0') {
843 mAsciiLineBuffer
= NULL
;
847 End
= AsciiStrBrk (Begin
, CharSet
);
848 if ((End
!= NULL
) && (*End
!= '\0')) {
853 mAsciiLineBuffer
= End
;
859 Find the next token after one specificed characters.
861 @param String Point to the string where to find the substring.
862 @param CharSet Point to the string to be found.
868 IN CHAR8
*String OPTIONAL
,
875 Begin
= (String
== NULL
) ? mAsciiFieldBuffer
: String
;
880 if (*Begin
== '\0') {
881 mAsciiFieldBuffer
= NULL
;
885 End
= AsciiStrBrk (Begin
, CharSet
);
886 if ((End
!= NULL
) && (*End
!= '\0')) {
891 mAsciiFieldBuffer
= End
;
897 Find the next token after one or more specified characters.
899 @param String Point to the string where to find the substring.
900 @param CharSet Point to the string to be found.
905 AsciiStrGetNewTokenLine (
910 return AsciiStrTokenLine (String
, CharSet
);
915 Find the next token after one or more specified characters.
917 @param CharSet Point to the string to be found.
922 AsciiStrGetNextTokenLine (
926 return AsciiStrTokenLine (NULL
, CharSet
);
931 Find the next token after one specificed characters.
933 @param String Point to the string where to find the substring.
934 @param CharSet Point to the string to be found.
939 AsciiStrGetNewTokenField (
944 return AsciiStrTokenField (String
, CharSet
);
949 Find the next token after one specificed characters.
951 @param CharSet Point to the string to be found.
956 AsciiStrGetNextTokenField (
960 return AsciiStrTokenField (NULL
, CharSet
);
965 Patch a character to the end of a string.
967 @param Buffer The string to be patched.
968 @param Patch The patch character.
973 PatchForAsciiStrTokenAfter (
980 if (Buffer
== NULL
) {
991 while (*(Str
++) != '\0') {
1003 Patch a character at the beginning of a string.
1005 @param Buffer The string to be patched.
1006 @param Patch The patch character.
1011 PatchForAsciiStrTokenBefore (
1018 if (Buffer
== NULL
) {
1023 while (*(Str
--) != '\0') {
1024 if ((*Str
== 0) || (*Str
== Patch
)) {