]>
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 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Convert hex string to uint.
21 @param Str - The string
36 MaxVal
= (UINTN
) -1 >> 4;
38 // skip preceeding white space
40 while (*Str
!= '\0' && *Str
== ' ') {
44 // skip preceeding zeros
46 while (*Str
!= '\0' && *Str
== '0') {
50 // skip preceeding white space
52 if (*Str
!= '\0' && (*Str
== 'x' || *Str
== 'X')) {
60 while (TempChar
!= '\0') {
61 if (TempChar
>= 'a' && TempChar
<= 'f') {
62 TempChar
-= 'a' - 'A';
65 if ((TempChar
>= '0' && TempChar
<= '9') || (TempChar
>= 'A' && TempChar
<= 'F')) {
66 if (RetVal
> MaxVal
) {
70 RetVal
= (RetVal
<< 4) | (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
83 Convert hex string to uint.
85 @param Str - The string
100 MaxVal
= RShiftU64 ((UINT64
) -1, 4);
102 // skip preceeding white space
104 while (*Str
!= '\0' && *Str
== ' ') {
108 // skip preceeding zeros
110 while (*Str
!= '\0' && *Str
== '0') {
114 // skip preceeding white space
116 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
== ' ') {
179 while (TempChar
!= '\0') {
180 if (TempChar
>= '0' && TempChar
<= '9') {
181 if (RetVal
> MaxVal
|| (RetVal
== MaxVal
&& TempChar
- '0' > (INTN
) ResteVal
)) {
185 RetVal
= (RetVal
* 10) + TempChar
- '0';
198 Convert hex string to uint.
200 @param Str - The string
213 ASSERT (Str
!= NULL
);
215 MaxVal
= (UINTN
) -1 >> 4;
217 // skip preceeding white space
219 while (*Str
!= '\0' && *Str
== ' ') {
223 // skip preceeding zeros
225 while (*Str
!= '\0' && *Str
== '0') {
229 // skip preceeding white space
231 if (*Str
!= '\0' && (*Str
== 'x' || *Str
== 'X')) {
235 // convert hex digits
239 while (TempChar
!= '\0') {
240 if (TempChar
>= 'a' && TempChar
<= 'f') {
241 TempChar
-= 'a' - 'A';
244 if ((TempChar
>= '0' && TempChar
<= '9') || (TempChar
>= 'A' && TempChar
<= 'F')) {
245 if (RetVal
> MaxVal
) {
249 RetVal
= (RetVal
<< 4) | (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
262 Convert hex string to uint.
264 @param Str - The string
278 ASSERT (Str
!= NULL
);
280 MaxVal
= (UINTN
) -1 / 10;
281 ResteVal
= (UINTN
) -1 % 10;
283 // skip preceeding white space
285 while (*Str
!= '\0' && *Str
== ' ') {
293 while (TempChar
!= '\0') {
294 if (TempChar
>= '0' && TempChar
<= '9') {
295 if (RetVal
> MaxVal
|| (RetVal
== MaxVal
&& TempChar
- '0' > (INTN
) ResteVal
)) {
299 RetVal
= (RetVal
* 10) + TempChar
- '0';
312 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
314 @param String - Unicode String to process
316 @param String2 - Ascii string to process
318 @return Return a positive integer if String is lexicall greater than String2; Zero if
319 the two strings are identical; and a negative interger if String is lexically
325 StrCmpUnicodeAndAscii (
330 while (*String
!= '\0') {
331 if (*String
!= (CHAR16
)*String2
) {
339 return (*String
- (CHAR16
)*String2
);
344 Compare the Unicode string pointed by String to the string pointed by String2.
346 @param String - Unicode String to process
347 @param String2 - Unicode string to process
349 @return Return a positive integer if String is lexically greater than String2; Zero if
350 the two strings are identical; and a negative integer if String is lexically
361 while ((*String
!= L
'\0') &&
362 (CharToUpper (*String
) == CharToUpper (*String2
))) {
367 return CharToUpper (*String
) - CharToUpper (*String2
);
372 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
374 @param String - Unicode String to process
375 @param String2 - Ascii string to process
377 @return Return a positive integer if String is lexically greater than String2; Zero if
378 the two strings are identical; and a negative integer if String is lexically
384 StriCmpUnicodeAndAscii (
389 while ((*String
!= L
'\0') &&
390 (CharToUpper (*String
) == (CHAR16
)AsciiCharToUpper (*String2
))) {
395 return CharToUpper (*String
) - (CHAR16
)AsciiCharToUpper (*String2
);
400 Verify if the string is end with the sub string.
402 @param Str - The string where to search the sub string
403 @param SubStr - The substring.
415 if ((Str
== NULL
) || (SubStr
== NULL
) || (StrLen(Str
) < StrLen(SubStr
))) {
419 Temp
= Str
+ StrLen(Str
) - StrLen(SubStr
);
424 if (StriCmp (Temp
, SubStr
) == 0) {
434 @param Src The string to be duplicated.
446 Size
= (StrLen(Src
) + 1) * sizeof(CHAR16
);
447 Dest
= AllocateZeroPool (Size
);
449 CopyMem (Dest
, Src
, Size
);
455 CHAR16
*mLineBuffer
= NULL
;
456 CHAR16
*mFieldBuffer
= NULL
;
460 Find the first substring.
462 @param String Point to the string where to find the substring.
463 @param CharSet Point to the string to be found.
479 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
480 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
481 if (*Str1
== *Str2
) {
486 if (*Str2
== L
'\0') {
498 Searches a string for the first occurrence of a character contained in a
501 @param String Point to the string where to find the substring.
502 @param CharSet Point to the string to be found.
515 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
516 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
517 if (*Str1
== *Str2
) {
518 return (CHAR16
*) Str1
;
528 Find the next token after one or more specified characters.
530 @param String Point to the string where to find the substring.
531 @param CharSet Point to the string to be found.
537 IN CHAR16
*String OPTIONAL
,
544 Begin
= (String
== NULL
) ? mLineBuffer
: String
;
549 Begin
+= StrSpn (Begin
, CharSet
);
550 if (*Begin
== L
'\0') {
555 End
= StrBrk (Begin
, CharSet
);
556 if ((End
!= NULL
) && (*End
!= L
'\0')) {
567 Find the next token after one specificed characters.
569 @param String Point to the string where to find the substring.
570 @param CharSet Point to the string to be found.
576 IN CHAR16
*String OPTIONAL
,
584 Begin
= (String
== NULL
) ? mFieldBuffer
: String
;
589 if (*Begin
== L
'\0') {
594 End
= StrBrk (Begin
, CharSet
);
595 if ((End
!= NULL
) && (*End
!= L
'\0')) {
606 Find the next token after one or more specified characters.
608 @param String Point to the string where to find the substring.
609 @param CharSet Point to the string to be found.
619 return StrTokenLine (String
, CharSet
);
624 Find the next token after one or more specified characters.
626 @param CharSet Point to the string to be found.
631 StrGetNextTokenLine (
635 return StrTokenLine (NULL
, CharSet
);
640 Find the next token after one specificed characters.
642 @param String Point to the string where to find the substring.
643 @param CharSet Point to the string to be found.
648 StrGetNewTokenField (
653 return StrTokenField (String
, CharSet
);
658 Find the next token after one specificed characters.
660 @param CharSet Point to the string to be found.
665 StrGetNextTokenField (
669 return StrTokenField (NULL
, CharSet
);
674 Patch a character to the end of a string.
676 @param Buffer The string to be patched.
677 @param Patch The patch character.
682 PatchForStrTokenAfter (
689 if (Buffer
== NULL
) {
699 while (*(Str
++) != '\0') {
711 Patch a character at the beginning of a string.
713 @param Buffer The string to be patched.
714 @param Patch The patch character.
719 PatchForStrTokenBefore (
726 if (Buffer
== NULL
) {
731 while (*(Str
--) != '\0') {
732 if ((*Str
== 0) || (*Str
== Patch
)) {
742 CHAR8
*mAsciiLineBuffer
= NULL
;
743 CHAR8
*mAsciiFieldBuffer
= NULL
;
747 Find the first substring.
749 @param String Point to the string where to find the substring.
750 @param CharSet Point to the string to be found.
766 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
767 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
768 if (*Str1
== *Str2
) {
784 Searches a string for the first occurrence of a character contained in a
787 @param String Point to the string where to find the substring.
788 @param CharSet Point to the string to be found.
801 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
802 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
803 if (*Str1
== *Str2
) {
804 return (CHAR8
*) Str1
;
814 Find the next token after one or more specified characters.
816 @param String Point to the string where to find the substring.
817 @param CharSet Point to the string to be found.
823 IN CHAR8
*String OPTIONAL
,
830 Begin
= (String
== NULL
) ? mAsciiLineBuffer
: String
;
835 Begin
+= AsciiStrSpn (Begin
, CharSet
);
836 if (*Begin
== '\0') {
837 mAsciiLineBuffer
= NULL
;
841 End
= AsciiStrBrk (Begin
, CharSet
);
842 if ((End
!= NULL
) && (*End
!= '\0')) {
847 mAsciiLineBuffer
= End
;
853 Find the next token after one specificed characters.
855 @param String Point to the string where to find the substring.
856 @param CharSet Point to the string to be found.
862 IN CHAR8
*String OPTIONAL
,
870 Begin
= (String
== NULL
) ? mAsciiFieldBuffer
: String
;
875 if (*Begin
== '\0') {
876 mAsciiFieldBuffer
= NULL
;
880 End
= AsciiStrBrk (Begin
, CharSet
);
881 if ((End
!= NULL
) && (*End
!= '\0')) {
886 mAsciiFieldBuffer
= End
;
892 Find the next token after one or more specified characters.
894 @param String Point to the string where to find the substring.
895 @param CharSet Point to the string to be found.
900 AsciiStrGetNewTokenLine (
905 return AsciiStrTokenLine (String
, CharSet
);
910 Find the next token after one or more specified characters.
912 @param CharSet Point to the string to be found.
917 AsciiStrGetNextTokenLine (
921 return AsciiStrTokenLine (NULL
, CharSet
);
926 Find the next token after one specificed characters.
928 @param String Point to the string where to find the substring.
929 @param CharSet Point to the string to be found.
934 AsciiStrGetNewTokenField (
939 return AsciiStrTokenField (String
, CharSet
);
944 Find the next token after one specificed characters.
946 @param CharSet Point to the string to be found.
951 AsciiStrGetNextTokenField (
955 return AsciiStrTokenField (NULL
, CharSet
);
960 Patch a character to the end of a string.
962 @param Buffer The string to be patched.
963 @param Patch The patch character.
968 PatchForAsciiStrTokenAfter (
975 if (Buffer
== NULL
) {
985 while (*(Str
++) != '\0') {
997 Patch a character at the beginning of a string.
999 @param Buffer The string to be patched.
1000 @param Patch The patch character.
1005 PatchForAsciiStrTokenBefore (
1012 if (Buffer
== NULL
) {
1017 while (*(Str
--) != '\0') {
1018 if ((*Str
== 0) || (*Str
== Patch
)) {