]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c
3 Copyright (c) 2007 - 2016, 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 Convert the character to upper case.
314 @param Chr the character to be converted.
323 return (Chr
>= L
'a' && Chr
<= L
'z') ? Chr
- (L
'a' - L
'A') : Chr
;
328 Convert the character to upper case.
330 @param Chr the character to be converted.
339 return (Chr
>= 'a' && Chr
<= 'z') ? Chr
- ('a' - 'A') : Chr
;
343 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
345 @param String - Unicode String to process
347 @param String2 - Ascii string to process
349 @return Return a positive integer if String is lexicall greater than String2; Zero if
350 the two strings are identical; and a negative interger if String is lexically
356 StrCmpUnicodeAndAscii (
361 while (*String
!= '\0') {
362 if (*String
!= (CHAR16
)*String2
) {
370 return (*String
- (CHAR16
)*String2
);
375 Compare the Unicode string pointed by String to the string pointed by String2.
377 @param String - Unicode String to process
378 @param String2 - Unicode string to process
380 @return Return a positive integer if String is lexically greater than String2; Zero if
381 the two strings are identical; and a negative integer if String is lexically
392 while ((*String
!= L
'\0') &&
393 (UnicodeToUpper (*String
) == UnicodeToUpper (*String2
))) {
398 return UnicodeToUpper (*String
) - UnicodeToUpper (*String2
);
403 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
405 @param String - Unicode String to process
406 @param String2 - Ascii string to process
408 @return Return a positive integer if String is lexically greater than String2; Zero if
409 the two strings are identical; and a negative integer if String is lexically
415 StriCmpUnicodeAndAscii (
420 while ((*String
!= L
'\0') &&
421 (UnicodeToUpper (*String
) == (CHAR16
)AsciiToUpper (*String2
))) {
426 return UnicodeToUpper (*String
) - (CHAR16
)AsciiToUpper (*String2
);
431 Verify if the string is end with the sub string.
433 @param Str - The string where to search the sub string
434 @param SubStr - The substring.
446 if ((Str
== NULL
) || (SubStr
== NULL
) || (StrLen(Str
) < StrLen(SubStr
))) {
450 Temp
= Str
+ StrLen(Str
) - StrLen(SubStr
);
455 if (StriCmp (Temp
, SubStr
) == 0) {
465 @param Src The string to be duplicated.
477 Size
= (StrLen(Src
) + 1) * sizeof(CHAR16
);
478 Dest
= AllocateZeroPool (Size
);
480 CopyMem (Dest
, Src
, Size
);
486 CHAR16
*mLineBuffer
= NULL
;
487 CHAR16
*mFieldBuffer
= NULL
;
491 Find the first substring.
493 @param String Point to the string where to find the substring.
494 @param CharSet Point to the string to be found.
510 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
511 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
512 if (*Str1
== *Str2
) {
517 if (*Str2
== L
'\0') {
529 Searches a string for the first occurrence of a character contained in a
532 @param String Point to the string where to find the substring.
533 @param CharSet Point to the string to be found.
546 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
547 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
548 if (*Str1
== *Str2
) {
549 return (CHAR16
*) Str1
;
559 Find the next token after one or more specified characters.
561 @param String Point to the string where to find the substring.
562 @param CharSet Point to the string to be found.
568 IN CHAR16
*String OPTIONAL
,
575 Begin
= (String
== NULL
) ? mLineBuffer
: String
;
580 Begin
+= StrSpn (Begin
, CharSet
);
581 if (*Begin
== L
'\0') {
586 End
= StrBrk (Begin
, CharSet
);
587 if ((End
!= NULL
) && (*End
!= L
'\0')) {
598 Find the next token after one specificed characters.
600 @param String Point to the string where to find the substring.
601 @param CharSet Point to the string to be found.
607 IN CHAR16
*String OPTIONAL
,
615 Begin
= (String
== NULL
) ? mFieldBuffer
: String
;
620 if (*Begin
== L
'\0') {
625 End
= StrBrk (Begin
, CharSet
);
626 if ((End
!= NULL
) && (*End
!= L
'\0')) {
637 Find the next token after one or more specified characters.
639 @param String Point to the string where to find the substring.
640 @param CharSet Point to the string to be found.
650 return StrTokenLine (String
, CharSet
);
655 Find the next token after one or more specified characters.
657 @param CharSet Point to the string to be found.
662 StrGetNextTokenLine (
666 return StrTokenLine (NULL
, CharSet
);
671 Find the next token after one specificed characters.
673 @param String Point to the string where to find the substring.
674 @param CharSet Point to the string to be found.
679 StrGetNewTokenField (
684 return StrTokenField (String
, CharSet
);
689 Find the next token after one specificed characters.
691 @param CharSet Point to the string to be found.
696 StrGetNextTokenField (
700 return StrTokenField (NULL
, CharSet
);
705 Patch a character to the end of a string.
707 @param Buffer The string to be patched.
708 @param Patch The patch character.
713 PatchForStrTokenAfter (
720 if (Buffer
== NULL
) {
730 while (*(Str
++) != '\0') {
742 Patch a character at the beginning of a string.
744 @param Buffer The string to be patched.
745 @param Patch The patch character.
750 PatchForStrTokenBefore (
757 if (Buffer
== NULL
) {
762 while (*(Str
--) != '\0') {
763 if ((*Str
== 0) || (*Str
== Patch
)) {
773 CHAR8
*mAsciiLineBuffer
= NULL
;
774 CHAR8
*mAsciiFieldBuffer
= NULL
;
778 Find the first substring.
780 @param String Point to the string where to find the substring.
781 @param CharSet Point to the string to be found.
797 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
798 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
799 if (*Str1
== *Str2
) {
815 Searches a string for the first occurrence of a character contained in a
818 @param String Point to the string where to find the substring.
819 @param CharSet Point to the string to be found.
832 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
833 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
834 if (*Str1
== *Str2
) {
835 return (CHAR8
*) Str1
;
845 Find the next token after one or more specified characters.
847 @param String Point to the string where to find the substring.
848 @param CharSet Point to the string to be found.
854 IN CHAR8
*String OPTIONAL
,
861 Begin
= (String
== NULL
) ? mAsciiLineBuffer
: String
;
866 Begin
+= AsciiStrSpn (Begin
, CharSet
);
867 if (*Begin
== '\0') {
868 mAsciiLineBuffer
= NULL
;
872 End
= AsciiStrBrk (Begin
, CharSet
);
873 if ((End
!= NULL
) && (*End
!= '\0')) {
878 mAsciiLineBuffer
= End
;
884 Find the next token after one specificed characters.
886 @param String Point to the string where to find the substring.
887 @param CharSet Point to the string to be found.
893 IN CHAR8
*String OPTIONAL
,
901 Begin
= (String
== NULL
) ? mAsciiFieldBuffer
: String
;
906 if (*Begin
== '\0') {
907 mAsciiFieldBuffer
= NULL
;
911 End
= AsciiStrBrk (Begin
, CharSet
);
912 if ((End
!= NULL
) && (*End
!= '\0')) {
917 mAsciiFieldBuffer
= End
;
923 Find the next token after one or more specified characters.
925 @param String Point to the string where to find the substring.
926 @param CharSet Point to the string to be found.
931 AsciiStrGetNewTokenLine (
936 return AsciiStrTokenLine (String
, CharSet
);
941 Find the next token after one or more specified characters.
943 @param CharSet Point to the string to be found.
948 AsciiStrGetNextTokenLine (
952 return AsciiStrTokenLine (NULL
, CharSet
);
957 Find the next token after one specificed characters.
959 @param String Point to the string where to find the substring.
960 @param CharSet Point to the string to be found.
965 AsciiStrGetNewTokenField (
970 return AsciiStrTokenField (String
, CharSet
);
975 Find the next token after one specificed characters.
977 @param CharSet Point to the string to be found.
982 AsciiStrGetNextTokenField (
986 return AsciiStrTokenField (NULL
, CharSet
);
991 Patch a character to the end of a string.
993 @param Buffer The string to be patched.
994 @param Patch The patch character.
999 PatchForAsciiStrTokenAfter (
1006 if (Buffer
== NULL
) {
1016 while (*(Str
++) != '\0') {
1028 Patch a character at the beginning of a string.
1030 @param Buffer The string to be patched.
1031 @param Patch The patch character.
1036 PatchForAsciiStrTokenBefore (
1043 if (Buffer
== NULL
) {
1048 while (*(Str
--) != '\0') {
1049 if ((*Str
== 0) || (*Str
== Patch
)) {