]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c
1a396a40666099caf20650f9cdc182bee449523a
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
&& *Str
== ' ') {
44 // skip preceeding zeros
46 while (*Str
&& *Str
== '0') {
50 // skip preceeding white space
52 if (*Str
&& (*Str
== 'x' || *Str
== 'X')) {
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
101 MaxVal
= RShiftU64 ((UINT64
) -1, 4);
103 // skip preceeding white space
105 while (*Str
&& *Str
== ' ') {
109 // skip preceeding zeros
111 while (*Str
&& *Str
== '0') {
115 // skip preceeding white space
117 if (*Str
&& (*Str
== 'x' || *Str
== 'X')) {
121 // convert hex digits
126 if (TempChar
>= 'a' && TempChar
<= 'f') {
127 TempChar
-= 'a' - 'A';
130 if ((TempChar
>= '0' && TempChar
<= '9') || (TempChar
>= 'A' && TempChar
<= 'F')) {
131 if (RetVal
> MaxVal
) {
135 RetVal
= LShiftU64 (RetVal
, 4);
136 RetVal
= RetVal
+ (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
149 Convert hex string to uint.
151 @param Str - The string
165 ASSERT (Str
!= NULL
);
167 MaxVal
= (UINTN
) -1 / 10;
168 ResteVal
= (UINTN
) -1 % 10;
170 // skip preceeding white space
172 while (*Str
&& *Str
== ' ') {
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
&& *Str
== ' ') {
224 // skip preceeding zeros
226 while (*Str
&& *Str
== '0') {
230 // skip preceeding white space
232 if (*Str
&& (*Str
== 'x' || *Str
== 'X')) {
236 // convert hex digits
241 if (TempChar
>= 'a' && TempChar
<= 'f') {
242 TempChar
-= 'a' - 'A';
245 if ((TempChar
>= '0' && TempChar
<= '9') || (TempChar
>= 'A' && TempChar
<= 'F')) {
246 if (RetVal
> MaxVal
) {
250 RetVal
= (RetVal
<< 4) | (TempChar
- (TempChar
>= 'A' ? 'A' - 10 : '0'));
263 Convert hex string to uint.
265 @param Str - The string
279 ASSERT (Str
!= NULL
);
281 MaxVal
= (UINTN
) -1 / 10;
282 ResteVal
= (UINTN
) -1 % 10;
284 // skip preceeding white space
286 while (*Str
&& *Str
== ' ') {
295 if (TempChar
>= '0' && TempChar
<= '9') {
296 if (RetVal
> MaxVal
|| (RetVal
== MaxVal
&& TempChar
- '0' > (INTN
) ResteVal
)) {
300 RetVal
= (RetVal
* 10) + TempChar
- '0';
317 return (Chr
>= L
'a' && Chr
<= L
'z') ? Chr
- (L
'a' - L
'A') : Chr
;
326 return (Chr
>= 'a' && Chr
<= 'z') ? Chr
- ('a' - 'A') : Chr
;
330 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
332 @param String - Unicode String to process
334 @param String2 - Ascii string to process
336 @return Return a positive integer if String is lexicall greater than String2; Zero if
337 the two strings are identical; and a negative interger if String is lexically
343 StrCmpUnicodeAndAscii (
349 if (*String
!= (CHAR16
)*String2
) {
357 return (*String
- (CHAR16
)*String2
);
362 Compare the Unicode string pointed by String to the string pointed by String2.
364 @param String - Unicode String to process
365 @param String2 - Unicode string to process
367 @return Return a positive integer if String is lexically greater than String2; Zero if
368 the two strings are identical; and a negative integer if String is lexically
379 while ((*String
!= L
'\0') &&
380 (UnicodeToUpper (*String
) == UnicodeToUpper (*String2
))) {
385 return UnicodeToUpper (*String
) - UnicodeToUpper (*String2
);
390 Compare the Unicode and Ascii string pointed by String to the string pointed by String2.
392 @param String - Unicode String to process
393 @param String2 - Ascii string to process
395 @return Return a positive integer if String is lexically greater than String2; Zero if
396 the two strings are identical; and a negative integer if String is lexically
402 StriCmpUnicodeAndAscii (
407 while ((*String
!= L
'\0') &&
408 (UnicodeToUpper (*String
) == (CHAR16
)AsciiToUpper (*String2
))) {
413 return UnicodeToUpper (*String
) - (CHAR16
)AsciiToUpper (*String2
);
418 Verify if the string is end with the sub string.
420 @param Str - The string where to search the sub string
421 @param SubStr - The substring.
433 if ((Str
== NULL
) || (SubStr
== NULL
) || (StrLen(Str
) < StrLen(SubStr
))) {
437 Temp
= Str
+ StrLen(Str
) - StrLen(SubStr
);
442 if (StriCmp (Temp
, SubStr
) == 0) {
452 @param Src The string to be duplicated.
464 Size
= (StrLen(Src
) + 1) * sizeof(CHAR16
);
465 Dest
= AllocateZeroPool (Size
);
467 CopyMem (Dest
, Src
, Size
);
473 CHAR16
*mLineBuffer
= NULL
;
474 CHAR16
*mFieldBuffer
= NULL
;
478 Find the first substring.
480 @param String Point to the string where to find the substring.
481 @param CharSet Point to the string to be found.
497 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
498 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
499 if (*Str1
== *Str2
) {
504 if (*Str2
== L
'\0') {
516 Searches a string for the first occurrence of a character contained in a
519 @param String Point to the string where to find the substring.
520 @param CharSet Point to the string to be found.
534 for (Str1
= String
; *Str1
!= L
'\0'; Str1
++) {
535 for (Str2
= CharSet
; *Str2
!= L
'\0'; Str2
++) {
536 if (*Str1
== *Str2
) {
537 return (CHAR16
*) Str1
;
547 Find the next token after one or more specified characters.
549 @param String Point to the string where to find the substring.
550 @param CharSet Point to the string to be found.
556 IN CHAR16
*String OPTIONAL
,
563 Begin
= (String
== NULL
) ? mLineBuffer
: String
;
568 Begin
+= StrSpn (Begin
, CharSet
);
569 if (*Begin
== L
'\0') {
574 End
= StrBrk (Begin
, CharSet
);
575 if ((End
!= NULL
) && (*End
!= L
'\0')) {
586 Find the next token after one specificed characters.
588 @param String Point to the string where to find the substring.
589 @param CharSet Point to the string to be found.
596 IN CHAR16
*String OPTIONAL
,
604 Begin
= (String
== NULL
) ? mFieldBuffer
: String
;
609 if (*Begin
== L
'\0') {
614 End
= StrBrk (Begin
, CharSet
);
615 if ((End
!= NULL
) && (*End
!= L
'\0')) {
631 return StrTokenLine (String
, CharSet
);
636 StrGetNextTokenLine (
640 return StrTokenLine (NULL
, CharSet
);
645 StrGetNewTokenField (
650 return StrTokenField (String
, CharSet
);
655 StrGetNextTokenField (
659 return StrTokenField (NULL
, CharSet
);
664 PatchForStrTokenAfter (
671 if (Buffer
== NULL
) {
694 PatchForStrTokenBefore (
701 if (Buffer
== NULL
) {
707 if ((*Str
== 0) || (*Str
== Patch
)) {
717 CHAR8
*mAsciiLineBuffer
= NULL
;
718 CHAR8
*mAsciiFieldBuffer
= NULL
;
722 Find the first substring.
724 @param String Point to the string where to find the substring.
725 @param CharSet Point to the string to be found.
741 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
742 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
743 if (*Str1
== *Str2
) {
759 Searches a string for the first occurrence of a character contained in a
762 @param String Point to the string where to find the substring.
763 @param CharSet Point to the string to be found.
776 for (Str1
= String
; *Str1
!= '\0'; Str1
++) {
777 for (Str2
= CharSet
; *Str2
!= '\0'; Str2
++) {
778 if (*Str1
== *Str2
) {
779 return (CHAR8
*) Str1
;
789 Find the next token after one or more specified characters.
791 @param String Point to the string where to find the substring.
792 @param CharSet Point to the string to be found.
798 IN CHAR8
*String OPTIONAL
,
805 Begin
= (String
== NULL
) ? mAsciiLineBuffer
: String
;
810 Begin
+= AsciiStrSpn (Begin
, CharSet
);
811 if (*Begin
== '\0') {
812 mAsciiLineBuffer
= NULL
;
816 End
= AsciiStrBrk (Begin
, CharSet
);
817 if ((End
!= NULL
) && (*End
!= '\0')) {
822 mAsciiLineBuffer
= End
;
828 Find the next token after one specificed characters.
830 @param String Point to the string where to find the substring.
831 @param CharSet Point to the string to be found.
838 IN CHAR8
*String OPTIONAL
,
846 Begin
= (String
== NULL
) ? mAsciiFieldBuffer
: String
;
851 if (*Begin
== '\0') {
852 mAsciiFieldBuffer
= NULL
;
856 End
= AsciiStrBrk (Begin
, CharSet
);
857 if ((End
!= NULL
) && (*End
!= '\0')) {
862 mAsciiFieldBuffer
= End
;
868 AsciiStrGetNewTokenLine (
873 return AsciiStrTokenLine (String
, CharSet
);
878 AsciiStrGetNextTokenLine (
882 return AsciiStrTokenLine (NULL
, CharSet
);
887 AsciiStrGetNewTokenField (
892 return AsciiStrTokenField (String
, CharSet
);
897 AsciiStrGetNextTokenField (
901 return AsciiStrTokenField (NULL
, CharSet
);
906 PatchForAsciiStrTokenAfter (
913 if (Buffer
== NULL
) {
936 PatchForAsciiStrTokenBefore (
943 if (Buffer
== NULL
) {
949 if ((*Str
== 0) || (*Str
== Patch
)) {