]>
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
== ' ') {
38 // skip preceeding zeros
40 while (*Str
!= '\0' && *Str
== '0') {
44 // skip preceeding white space
46 if (*Str
!= '\0' && (*Str
== 'x' || *Str
== 'X')) {
54 while (TempChar
!= '\0') {
55 if (TempChar
>= 'a' && TempChar
<= 'f') {
56 TempChar
-= 'a' - 'A';
59 if ((TempChar
>= '0' && TempChar
<= '9') || (TempChar
>= 'A' && TempChar
<= 'F')) {
60 if (RetVal
> MaxVal
) {
64 RetVal
= (RetVal
<< 4) | (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
77 Convert hex string to uint.
79 @param Str - The string
94 MaxVal
= RShiftU64 ((UINT64
) -1, 4);
96 // skip preceeding white space
98 while (*Str
!= '\0' && *Str
== ' ') {
102 // skip preceeding zeros
104 while (*Str
!= '\0' && *Str
== '0') {
108 // skip preceeding white space
110 if (*Str
!= '\0' && (*Str
== 'x' || *Str
== 'X')) {
114 // convert hex digits
118 while (TempChar
!= '\0') {
119 if (TempChar
>= 'a' && TempChar
<= 'f') {
120 TempChar
-= 'a' - 'A';
123 if ((TempChar
>= '0' && TempChar
<= '9') || (TempChar
>= 'A' && TempChar
<= 'F')) {
124 if (RetVal
> MaxVal
) {
128 RetVal
= LShiftU64 (RetVal
, 4);
129 RetVal
= RetVal
+ (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
142 Convert hex string to uint.
144 @param Str - The string
158 ASSERT (Str
!= NULL
);
160 MaxVal
= (UINTN
) -1 / 10;
161 ResteVal
= (UINTN
) -1 % 10;
163 // skip preceeding white space
165 while (*Str
!= '\0' && *Str
== ' ') {
173 while (TempChar
!= '\0') {
174 if (TempChar
>= '0' && TempChar
<= '9') {
175 if (RetVal
> MaxVal
|| (RetVal
== MaxVal
&& TempChar
- '0' > (INTN
) ResteVal
)) {
179 RetVal
= (RetVal
* 10) + TempChar
- '0';
192 Convert hex string to uint.
194 @param Str - The string
207 ASSERT (Str
!= NULL
);
209 MaxVal
= (UINTN
) -1 >> 4;
211 // skip preceeding white space
213 while (*Str
!= '\0' && *Str
== ' ') {
217 // skip preceeding zeros
219 while (*Str
!= '\0' && *Str
== '0') {
223 // skip preceeding white space
225 if (*Str
!= '\0' && (*Str
== 'x' || *Str
== 'X')) {
229 // convert hex digits
233 while (TempChar
!= '\0') {
234 if (TempChar
>= 'a' && TempChar
<= 'f') {
235 TempChar
-= 'a' - 'A';
238 if ((TempChar
>= '0' && TempChar
<= '9') || (TempChar
>= 'A' && TempChar
<= 'F')) {
239 if (RetVal
> MaxVal
) {
243 RetVal
= (RetVal
<< 4) | (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
256 Convert hex string to uint.
258 @param Str - The string
272 ASSERT (Str
!= NULL
);
274 MaxVal
= (UINTN
) -1 / 10;
275 ResteVal
= (UINTN
) -1 % 10;
277 // skip preceeding white space
279 while (*Str
!= '\0' && *Str
== ' ') {
287 while (TempChar
!= '\0') {
288 if (TempChar
>= '0' && TempChar
<= '9') {
289 if (RetVal
> MaxVal
|| (RetVal
== MaxVal
&& TempChar
- '0' > (INTN
) ResteVal
)) {
293 RetVal
= (RetVal
* 10) + TempChar
- '0';
306 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
308 @param String - Unicode String to process
310 @param String2 - Ascii string to process
312 @return Return a positive integer if String is lexicall greater than String2; Zero if
313 the two strings are identical; and a negative interger if String is lexically
319 StrCmpUnicodeAndAscii (
324 while (*String
!= '\0') {
325 if (*String
!= (CHAR16
)*String2
) {
333 return (*String
- (CHAR16
)*String2
);
338 Compare the Unicode string pointed by String to the string pointed by String2.
340 @param String - Unicode String to process
341 @param String2 - Unicode string to process
343 @return Return a positive integer if String is lexically greater than String2; Zero if
344 the two strings are identical; and a negative integer if String is lexically
355 while ((*String
!= L
'\0') &&
356 (CharToUpper (*String
) == CharToUpper (*String2
))) {
361 return CharToUpper (*String
) - CharToUpper (*String2
);
366 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
368 @param String - Unicode String to process
369 @param String2 - Ascii string to process
371 @return Return a positive integer if String is lexically greater than String2; Zero if
372 the two strings are identical; and a negative integer if String is lexically
378 StriCmpUnicodeAndAscii (
383 while ((*String
!= L
'\0') &&
384 (CharToUpper (*String
) == (CHAR16
)AsciiCharToUpper (*String2
))) {
389 return CharToUpper (*String
) - (CHAR16
)AsciiCharToUpper (*String2
);
394 Verify if the string is end with the sub string.
396 @param Str - The string where to search the sub string
397 @param SubStr - The substring.
409 if ((Str
== NULL
) || (SubStr
== NULL
) || (StrLen(Str
) < StrLen(SubStr
))) {
413 Temp
= Str
+ StrLen(Str
) - StrLen(SubStr
);
418 if (StriCmp (Temp
, SubStr
) == 0) {
428 @param Src The string to be duplicated.
440 Size
= (StrLen(Src
) + 1) * sizeof(CHAR16
);
441 Dest
= AllocateZeroPool (Size
);
443 CopyMem (Dest
, Src
, Size
);
449 CHAR16
*mLineBuffer
= NULL
;
450 CHAR16
*mFieldBuffer
= NULL
;
454 Find the first substring.
456 @param String Point to the string where to find the substring.
457 @param CharSet Point to the string to be found.
473 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
474 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
475 if (*Str1
== *Str2
) {
480 if (*Str2
== L
'\0') {
492 Searches a string for the first occurrence of a character contained in a
495 @param String Point to the string where to find the substring.
496 @param CharSet Point to the string to be found.
509 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
510 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
511 if (*Str1
== *Str2
) {
512 return (CHAR16
*) Str1
;
522 Find the next token after one or more specified characters.
524 @param String Point to the string where to find the substring.
525 @param CharSet Point to the string to be found.
531 IN CHAR16
*String OPTIONAL
,
538 Begin
= (String
== NULL
) ? mLineBuffer
: String
;
543 Begin
+= StrSpn (Begin
, CharSet
);
544 if (*Begin
== L
'\0') {
549 End
= StrBrk (Begin
, CharSet
);
550 if ((End
!= NULL
) && (*End
!= L
'\0')) {
561 Find the next token after one specificed characters.
563 @param String Point to the string where to find the substring.
564 @param CharSet Point to the string to be found.
570 IN CHAR16
*String OPTIONAL
,
578 Begin
= (String
== NULL
) ? mFieldBuffer
: String
;
583 if (*Begin
== L
'\0') {
588 End
= StrBrk (Begin
, CharSet
);
589 if ((End
!= NULL
) && (*End
!= L
'\0')) {
600 Find the next token after one or more specified characters.
602 @param String Point to the string where to find the substring.
603 @param CharSet Point to the string to be found.
613 return StrTokenLine (String
, CharSet
);
618 Find the next token after one or more specified characters.
620 @param CharSet Point to the string to be found.
625 StrGetNextTokenLine (
629 return StrTokenLine (NULL
, CharSet
);
634 Find the next token after one specificed characters.
636 @param String Point to the string where to find the substring.
637 @param CharSet Point to the string to be found.
642 StrGetNewTokenField (
647 return StrTokenField (String
, CharSet
);
652 Find the next token after one specificed characters.
654 @param CharSet Point to the string to be found.
659 StrGetNextTokenField (
663 return StrTokenField (NULL
, CharSet
);
668 Patch a character to the end of a string.
670 @param Buffer The string to be patched.
671 @param Patch The patch character.
676 PatchForStrTokenAfter (
683 if (Buffer
== NULL
) {
693 while (*(Str
++) != '\0') {
705 Patch a character at the beginning of a string.
707 @param Buffer The string to be patched.
708 @param Patch The patch character.
713 PatchForStrTokenBefore (
720 if (Buffer
== NULL
) {
725 while (*(Str
--) != '\0') {
726 if ((*Str
== 0) || (*Str
== Patch
)) {
736 CHAR8
*mAsciiLineBuffer
= NULL
;
737 CHAR8
*mAsciiFieldBuffer
= NULL
;
741 Find the first substring.
743 @param String Point to the string where to find the substring.
744 @param CharSet Point to the string to be found.
760 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
761 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
762 if (*Str1
== *Str2
) {
778 Searches a string for the first occurrence of a character contained in a
781 @param String Point to the string where to find the substring.
782 @param CharSet Point to the string to be found.
795 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
796 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
797 if (*Str1
== *Str2
) {
798 return (CHAR8
*) Str1
;
808 Find the next token after one or more specified characters.
810 @param String Point to the string where to find the substring.
811 @param CharSet Point to the string to be found.
817 IN CHAR8
*String OPTIONAL
,
824 Begin
= (String
== NULL
) ? mAsciiLineBuffer
: String
;
829 Begin
+= AsciiStrSpn (Begin
, CharSet
);
830 if (*Begin
== '\0') {
831 mAsciiLineBuffer
= NULL
;
835 End
= AsciiStrBrk (Begin
, CharSet
);
836 if ((End
!= NULL
) && (*End
!= '\0')) {
841 mAsciiLineBuffer
= End
;
847 Find the next token after one specificed characters.
849 @param String Point to the string where to find the substring.
850 @param CharSet Point to the string to be found.
856 IN CHAR8
*String OPTIONAL
,
864 Begin
= (String
== NULL
) ? mAsciiFieldBuffer
: String
;
869 if (*Begin
== '\0') {
870 mAsciiFieldBuffer
= NULL
;
874 End
= AsciiStrBrk (Begin
, CharSet
);
875 if ((End
!= NULL
) && (*End
!= '\0')) {
880 mAsciiFieldBuffer
= End
;
886 Find the next token after one or more specified characters.
888 @param String Point to the string where to find the substring.
889 @param CharSet Point to the string to be found.
894 AsciiStrGetNewTokenLine (
899 return AsciiStrTokenLine (String
, CharSet
);
904 Find the next token after one or more specified characters.
906 @param CharSet Point to the string to be found.
911 AsciiStrGetNextTokenLine (
915 return AsciiStrTokenLine (NULL
, CharSet
);
920 Find the next token after one specificed characters.
922 @param String Point to the string where to find the substring.
923 @param CharSet Point to the string to be found.
928 AsciiStrGetNewTokenField (
933 return AsciiStrTokenField (String
, CharSet
);
938 Find the next token after one specificed characters.
940 @param CharSet Point to the string to be found.
945 AsciiStrGetNextTokenField (
949 return AsciiStrTokenField (NULL
, CharSet
);
954 Patch a character to the end of a string.
956 @param Buffer The string to be patched.
957 @param Patch The patch character.
962 PatchForAsciiStrTokenAfter (
969 if (Buffer
== NULL
) {
979 while (*(Str
++) != '\0') {
991 Patch a character at the beginning of a string.
993 @param Buffer The string to be patched.
994 @param Patch The patch character.
999 PatchForAsciiStrTokenBefore (
1006 if (Buffer
== NULL
) {
1011 while (*(Str
--) != '\0') {
1012 if ((*Str
== 0) || (*Str
== Patch
)) {