TianoCore EDK2 master
Loading...
Searching...
No Matches
EdbSupportString.c
Go to the documentation of this file.
1
9#include "Edb.h"
10
19EFIAPI
21 CHAR16 *Str
22 )
23{
24 UINTN RetVal;
25 CHAR16 TempChar;
26 UINTN MaxVal;
27
28 ASSERT (Str != NULL);
29
30 MaxVal = (UINTN)-1 >> 4;
31 //
32 // skip preceeding white space
33 //
34 while (*Str != '\0' && *Str == ' ') {
35 Str += 1;
36 }
37
38 //
39 // skip preceeding zeros
40 //
41 while (*Str != '\0' && *Str == '0') {
42 Str += 1;
43 }
44
45 //
46 // skip preceeding white space
47 //
48 if ((*Str != '\0') && ((*Str == 'x') || (*Str == 'X'))) {
49 Str += 1;
50 }
51
52 //
53 // convert hex digits
54 //
55 RetVal = 0;
56 TempChar = *(Str++);
57 while (TempChar != '\0') {
58 if ((TempChar >= 'a') && (TempChar <= 'f')) {
59 TempChar -= 'a' - 'A';
60 }
61
62 if (((TempChar >= '0') && (TempChar <= '9')) || ((TempChar >= 'A') && (TempChar <= 'F'))) {
63 if (RetVal > MaxVal) {
64 return (UINTN)-1;
65 }
66
67 RetVal = (RetVal << 4) | (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));
68 } else {
69 break;
70 }
71
72 TempChar = *(Str++);
73 }
74
75 return RetVal;
76}
77
85UINT64
86EFIAPI
88 CHAR16 *Str
89 )
90{
91 UINT64 RetVal;
92 CHAR16 TempChar;
93 UINT64 MaxVal;
94
95 ASSERT (Str != NULL);
96
97 MaxVal = RShiftU64 ((UINT64)-1, 4);
98 //
99 // skip preceeding white space
100 //
101 while (*Str != '\0' && *Str == ' ') {
102 Str += 1;
103 }
104
105 //
106 // skip preceeding zeros
107 //
108 while (*Str != '\0' && *Str == '0') {
109 Str += 1;
110 }
111
112 //
113 // skip preceeding white space
114 //
115 if ((*Str != '\0') && ((*Str == 'x') || (*Str == 'X'))) {
116 Str += 1;
117 }
118
119 //
120 // convert hex digits
121 //
122 RetVal = 0;
123 TempChar = *(Str++);
124 while (TempChar != '\0') {
125 if ((TempChar >= 'a') && (TempChar <= 'f')) {
126 TempChar -= 'a' - 'A';
127 }
128
129 if (((TempChar >= '0') && (TempChar <= '9')) || ((TempChar >= 'A') && (TempChar <= 'F'))) {
130 if (RetVal > MaxVal) {
131 return (UINT64)-1;
132 }
133
134 RetVal = LShiftU64 (RetVal, 4);
135 RetVal = RetVal + (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));
136 } else {
137 break;
138 }
139
140 TempChar = *(Str++);
141 }
142
143 return RetVal;
144}
145
153UINTN
154EFIAPI
156 CHAR16 *Str
157 )
158{
159 UINTN RetVal;
160 CHAR16 TempChar;
161 UINTN MaxVal;
162 UINTN ResteVal;
163
164 ASSERT (Str != NULL);
165
166 MaxVal = (UINTN)-1 / 10;
167 ResteVal = (UINTN)-1 % 10;
168 //
169 // skip preceeding white space
170 //
171 while (*Str != '\0' && *Str == ' ') {
172 Str += 1;
173 }
174
175 //
176 // convert digits
177 //
178 RetVal = 0;
179 TempChar = *(Str++);
180 while (TempChar != '\0') {
181 if ((TempChar >= '0') && (TempChar <= '9')) {
182 if ((RetVal > MaxVal) || ((RetVal == MaxVal) && (TempChar - '0' > (INTN)ResteVal))) {
183 return (UINTN)-1;
184 }
185
186 RetVal = (RetVal * 10) + TempChar - '0';
187 } else {
188 break;
189 }
190
191 TempChar = *(Str++);
192 }
193
194 return RetVal;
195}
196
204UINTN
205EFIAPI
207 CHAR8 *Str
208 )
209{
210 UINTN RetVal;
211 CHAR8 TempChar;
212 UINTN MaxVal;
213
214 ASSERT (Str != NULL);
215
216 MaxVal = (UINTN)-1 >> 4;
217 //
218 // skip preceeding white space
219 //
220 while (*Str != '\0' && *Str == ' ') {
221 Str += 1;
222 }
223
224 //
225 // skip preceeding zeros
226 //
227 while (*Str != '\0' && *Str == '0') {
228 Str += 1;
229 }
230
231 //
232 // skip preceeding white space
233 //
234 if ((*Str != '\0') && ((*Str == 'x') || (*Str == 'X'))) {
235 Str += 1;
236 }
237
238 //
239 // convert hex digits
240 //
241 RetVal = 0;
242 TempChar = *(Str++);
243 while (TempChar != '\0') {
244 if ((TempChar >= 'a') && (TempChar <= 'f')) {
245 TempChar -= 'a' - 'A';
246 }
247
248 if (((TempChar >= '0') && (TempChar <= '9')) || ((TempChar >= 'A') && (TempChar <= 'F'))) {
249 if (RetVal > MaxVal) {
250 return (UINTN)-1;
251 }
252
253 RetVal = (RetVal << 4) | (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));
254 } else {
255 break;
256 }
257
258 TempChar = *(Str++);
259 }
260
261 return RetVal;
262}
263
271UINTN
272EFIAPI
274 CHAR8 *Str
275 )
276{
277 UINTN RetVal;
278 CHAR8 TempChar;
279 UINTN MaxVal;
280 UINTN ResteVal;
281
282 ASSERT (Str != NULL);
283
284 MaxVal = (UINTN)-1 / 10;
285 ResteVal = (UINTN)-1 % 10;
286 //
287 // skip preceeding white space
288 //
289 while (*Str != '\0' && *Str == ' ') {
290 Str += 1;
291 }
292
293 //
294 // convert digits
295 //
296 RetVal = 0;
297 TempChar = *(Str++);
298 while (TempChar != '\0') {
299 if ((TempChar >= '0') && (TempChar <= '9')) {
300 if ((RetVal > MaxVal) || ((RetVal == MaxVal) && (TempChar - '0' > (INTN)ResteVal))) {
301 return (UINTN)-1;
302 }
303
304 RetVal = (RetVal * 10) + TempChar - '0';
305 } else {
306 break;
307 }
308
309 TempChar = *(Str++);
310 }
311
312 return RetVal;
313}
314
327INTN
328EFIAPI
330 IN CHAR16 *String,
331 IN CHAR8 *String2
332 )
333{
334 while (*String != '\0') {
335 if (*String != (CHAR16)*String2) {
336 break;
337 }
338
339 String += 1;
340 String2 += 1;
341 }
342
343 return (*String - (CHAR16)*String2);
344}
345
358INTN
359EFIAPI
361 IN CHAR16 *String,
362 IN CHAR16 *String2
363 )
364{
365 while ((*String != L'\0') &&
366 (CharToUpper (*String) == CharToUpper (*String2)))
367 {
368 String++;
369 String2++;
370 }
371
372 return CharToUpper (*String) - CharToUpper (*String2);
373}
374
387INTN
388EFIAPI
390 IN CHAR16 *String,
391 IN CHAR8 *String2
392 )
393{
394 while ((*String != L'\0') &&
395 (CharToUpper (*String) == (CHAR16)AsciiCharToUpper (*String2)))
396 {
397 String++;
398 String2++;
399 }
400
401 return CharToUpper (*String) - (CHAR16)AsciiCharToUpper (*String2);
402}
403
412BOOLEAN
413EFIAPI
415 IN CHAR16 *Str,
416 IN CHAR16 *SubStr
417 )
418{
419 CHAR16 *Temp;
420
421 if ((Str == NULL) || (SubStr == NULL) || (StrLen (Str) < StrLen (SubStr))) {
422 return FALSE;
423 }
424
425 Temp = Str + StrLen (Str) - StrLen (SubStr);
426
427 //
428 // Compare
429 //
430 if (StriCmp (Temp, SubStr) == 0) {
431 return TRUE;
432 } else {
433 return FALSE;
434 }
435}
436
443CHAR16 *
444EFIAPI
446 IN CHAR16 *Src
447 )
448{
449 CHAR16 *Dest;
450 UINTN Size;
451
452 Size = (StrLen (Src) + 1) * sizeof (CHAR16);
453 Dest = AllocateZeroPool (Size);
454 if (Dest != NULL) {
455 CopyMem (Dest, Src, Size);
456 }
457
458 return Dest;
459}
460
461CHAR16 *mLineBuffer = NULL;
462CHAR16 *mFieldBuffer = NULL;
463
472UINTN
473EFIAPI
475 IN CHAR16 *String,
476 IN CHAR16 *CharSet
477 )
478{
479 UINTN Count;
480 CHAR16 *Str1;
481 CHAR16 *Str2;
482
483 Count = 0;
484
485 for (Str1 = String; *Str1 != L'\0'; Str1++) {
486 for (Str2 = CharSet; *Str2 != L'\0'; Str2++) {
487 if (*Str1 == *Str2) {
488 break;
489 }
490 }
491
492 if (*Str2 == L'\0') {
493 return Count;
494 }
495
496 Count++;
497 }
498
499 return Count;
500}
501
511CHAR16 *
512EFIAPI
514 IN CHAR16 *String,
515 IN CHAR16 *CharSet
516 )
517{
518 CHAR16 *Str1;
519 CHAR16 *Str2;
520
521 for (Str1 = String; *Str1 != L'\0'; Str1++) {
522 for (Str2 = CharSet; *Str2 != L'\0'; Str2++) {
523 if (*Str1 == *Str2) {
524 return (CHAR16 *)Str1;
525 }
526 }
527 }
528
529 return NULL;
530}
531
540CHAR16 *
541EFIAPI
543 IN CHAR16 *String OPTIONAL,
544 IN CHAR16 *CharSet
545 )
546{
547 CHAR16 *Begin;
548 CHAR16 *End;
549
550 Begin = (String == NULL) ? mLineBuffer : String;
551 if (Begin == NULL) {
552 return NULL;
553 }
554
555 Begin += StrSpn (Begin, CharSet);
556 if (*Begin == L'\0') {
557 mLineBuffer = NULL;
558 return NULL;
559 }
560
561 End = StrBrk (Begin, CharSet);
562 if ((End != NULL) && (*End != L'\0')) {
563 *End = L'\0';
564 End++;
565 }
566
567 mLineBuffer = End;
568 return Begin;
569}
570
579CHAR16 *
580EFIAPI
582 IN CHAR16 *String OPTIONAL,
583 IN CHAR16 *CharSet
584 )
585{
586 CHAR16 *Begin;
587 CHAR16 *End;
588
589 Begin = (String == NULL) ? mFieldBuffer : String;
590 if (Begin == NULL) {
591 return NULL;
592 }
593
594 if (*Begin == L'\0') {
595 mFieldBuffer = NULL;
596 return NULL;
597 }
598
599 End = StrBrk (Begin, CharSet);
600 if ((End != NULL) && (*End != L'\0')) {
601 *End = L'\0';
602 End++;
603 }
604
605 mFieldBuffer = End;
606 return Begin;
607}
608
617CHAR16 *
618EFIAPI
620 IN CHAR16 *String,
621 IN CHAR16 *CharSet
622 )
623{
624 return StrTokenLine (String, CharSet);
625}
626
634CHAR16 *
635EFIAPI
637 IN CHAR16 *CharSet
638 )
639{
640 return StrTokenLine (NULL, CharSet);
641}
642
651CHAR16 *
652EFIAPI
654 IN CHAR16 *String,
655 IN CHAR16 *CharSet
656 )
657{
658 return StrTokenField (String, CharSet);
659}
660
668CHAR16 *
669EFIAPI
671 IN CHAR16 *CharSet
672 )
673{
674 return StrTokenField (NULL, CharSet);
675}
676
685VOID
686EFIAPI
688 IN CHAR16 *Buffer,
689 IN CHAR16 Patch
690 )
691{
692 CHAR16 *Str;
693
694 if (Buffer == NULL) {
695 return;
696 }
697
698 Str = Buffer;
699 while (*Str != 0) {
700 Str++;
701 }
702
703 *Str = Patch;
704
705 while (*(Str++) != '\0') {
706 if (*Str == 0) {
707 *Str = Patch;
708 } else {
709 break;
710 }
711 }
712
713 return;
714}
715
723VOID
724EFIAPI
726 IN CHAR16 *Buffer,
727 IN CHAR16 Patch
728 )
729{
730 CHAR16 *Str;
731
732 if (Buffer == NULL) {
733 return;
734 }
735
736 Str = Buffer;
737 while (*(Str--) != '\0') {
738 if ((*Str == 0) || (*Str == Patch)) {
739 *Str = Patch;
740 } else {
741 break;
742 }
743 }
744
745 return;
746}
747
748CHAR8 *mAsciiLineBuffer = NULL;
749CHAR8 *mAsciiFieldBuffer = NULL;
750
759UINTN
760EFIAPI
762 IN CHAR8 *String,
763 IN CHAR8 *CharSet
764 )
765{
766 UINTN Count;
767 CHAR8 *Str1;
768 CHAR8 *Str2;
769
770 Count = 0;
771
772 for (Str1 = String; *Str1 != '\0'; Str1++) {
773 for (Str2 = CharSet; *Str2 != '\0'; Str2++) {
774 if (*Str1 == *Str2) {
775 break;
776 }
777 }
778
779 if (*Str2 == '\0') {
780 return Count;
781 }
782
783 Count++;
784 }
785
786 return Count;
787}
788
797CHAR8 *
798EFIAPI
800 IN CHAR8 *String,
801 IN CHAR8 *CharSet
802 )
803{
804 CHAR8 *Str1;
805 CHAR8 *Str2;
806
807 for (Str1 = String; *Str1 != '\0'; Str1++) {
808 for (Str2 = CharSet; *Str2 != '\0'; Str2++) {
809 if (*Str1 == *Str2) {
810 return (CHAR8 *)Str1;
811 }
812 }
813 }
814
815 return NULL;
816}
817
826CHAR8 *
827EFIAPI
829 IN CHAR8 *String OPTIONAL,
830 IN CHAR8 *CharSet
831 )
832{
833 CHAR8 *Begin;
834 CHAR8 *End;
835
836 Begin = (String == NULL) ? mAsciiLineBuffer : String;
837 if (Begin == NULL) {
838 return NULL;
839 }
840
841 Begin += AsciiStrSpn (Begin, CharSet);
842 if (*Begin == '\0') {
843 mAsciiLineBuffer = NULL;
844 return NULL;
845 }
846
847 End = AsciiStrBrk (Begin, CharSet);
848 if ((End != NULL) && (*End != '\0')) {
849 *End = '\0';
850 End++;
851 }
852
853 mAsciiLineBuffer = End;
854 return Begin;
855}
856
865CHAR8 *
866EFIAPI
868 IN CHAR8 *String OPTIONAL,
869 IN CHAR8 *CharSet
870 )
871{
872 CHAR8 *Begin;
873 CHAR8 *End;
874
875 Begin = (String == NULL) ? mAsciiFieldBuffer : String;
876 if (Begin == NULL) {
877 return NULL;
878 }
879
880 if (*Begin == '\0') {
881 mAsciiFieldBuffer = NULL;
882 return NULL;
883 }
884
885 End = AsciiStrBrk (Begin, CharSet);
886 if ((End != NULL) && (*End != '\0')) {
887 *End = '\0';
888 End++;
889 }
890
891 mAsciiFieldBuffer = End;
892 return Begin;
893}
894
903CHAR8 *
904EFIAPI
906 IN CHAR8 *String,
907 IN CHAR8 *CharSet
908 )
909{
910 return AsciiStrTokenLine (String, CharSet);
911}
912
920CHAR8 *
921EFIAPI
923 IN CHAR8 *CharSet
924 )
925{
926 return AsciiStrTokenLine (NULL, CharSet);
927}
928
937CHAR8 *
938EFIAPI
940 IN CHAR8 *String,
941 IN CHAR8 *CharSet
942 )
943{
944 return AsciiStrTokenField (String, CharSet);
945}
946
954CHAR8 *
955EFIAPI
957 IN CHAR8 *CharSet
958 )
959{
960 return AsciiStrTokenField (NULL, CharSet);
961}
962
971VOID
972EFIAPI
974 IN CHAR8 *Buffer,
975 IN CHAR8 Patch
976 )
977{
978 CHAR8 *Str;
979
980 if (Buffer == NULL) {
981 return;
982 }
983
984 Str = Buffer;
985 while (*Str != 0) {
986 Str++;
987 }
988
989 *Str = Patch;
990
991 while (*(Str++) != '\0') {
992 if (*Str == 0) {
993 *Str = Patch;
994 } else {
995 break;
996 }
997 }
998
999 return;
1000}
1001
1009VOID
1010EFIAPI
1012 IN CHAR8 *Buffer,
1013 IN CHAR8 Patch
1014 )
1015{
1016 CHAR8 *Str;
1017
1018 if (Buffer == NULL) {
1019 return;
1020 }
1021
1022 Str = Buffer;
1023 while (*(Str--) != '\0') {
1024 if ((*Str == 0) || (*Str == Patch)) {
1025 *Str = Patch;
1026 } else {
1027 break;
1028 }
1029 }
1030
1031 return;
1032}
UINT64 UINTN
INT64 INTN
CHAR16 EFIAPI CharToUpper(IN CHAR16 Char)
Definition: String.c:307
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: RShiftU64.c:28
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR8 EFIAPI AsciiCharToUpper(IN CHAR8 Chr)
Definition: String.c:750
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI PatchForAsciiStrTokenAfter(IN CHAR8 *Buffer, IN CHAR8 Patch)
CHAR8 *EFIAPI AsciiStrGetNewTokenLine(IN CHAR8 *String, IN CHAR8 *CharSet)
CHAR8 *EFIAPI AsciiStrTokenField(IN CHAR8 *String OPTIONAL, IN CHAR8 *CharSet)
UINTN EFIAPI AsciiAtoi(CHAR8 *Str)
VOID EFIAPI PatchForAsciiStrTokenBefore(IN CHAR8 *Buffer, IN CHAR8 Patch)
BOOLEAN EFIAPI StrEndWith(IN CHAR16 *Str, IN CHAR16 *SubStr)
CHAR16 *EFIAPI StrBrk(IN CHAR16 *String, IN CHAR16 *CharSet)
CHAR16 *EFIAPI StrTokenLine(IN CHAR16 *String OPTIONAL, IN CHAR16 *CharSet)
VOID EFIAPI PatchForStrTokenAfter(IN CHAR16 *Buffer, IN CHAR16 Patch)
CHAR16 *EFIAPI StrGetNewTokenLine(IN CHAR16 *String, IN CHAR16 *CharSet)
UINTN EFIAPI Xtoi(CHAR16 *Str)
CHAR16 *EFIAPI StrGetNewTokenField(IN CHAR16 *String, IN CHAR16 *CharSet)
UINTN EFIAPI StrSpn(IN CHAR16 *String, IN CHAR16 *CharSet)
CHAR16 *EFIAPI StrGetNextTokenLine(IN CHAR16 *CharSet)
CHAR8 *EFIAPI AsciiStrBrk(IN CHAR8 *String, IN CHAR8 *CharSet)
CHAR16 *EFIAPI StrTokenField(IN CHAR16 *String OPTIONAL, IN CHAR16 *CharSet)
CHAR16 *EFIAPI StrDuplicate(IN CHAR16 *Src)
UINTN EFIAPI Atoi(CHAR16 *Str)
UINTN EFIAPI AsciiStrSpn(IN CHAR8 *String, IN CHAR8 *CharSet)
UINT64 EFIAPI LXtoi(CHAR16 *Str)
UINTN EFIAPI AsciiXtoi(CHAR8 *Str)
INTN EFIAPI StriCmpUnicodeAndAscii(IN CHAR16 *String, IN CHAR8 *String2)
INTN EFIAPI StrCmpUnicodeAndAscii(IN CHAR16 *String, IN CHAR8 *String2)
VOID EFIAPI PatchForStrTokenBefore(IN CHAR16 *Buffer, IN CHAR16 Patch)
CHAR8 *EFIAPI AsciiStrTokenLine(IN CHAR8 *String OPTIONAL, IN CHAR8 *CharSet)
CHAR8 *EFIAPI AsciiStrGetNextTokenLine(IN CHAR8 *CharSet)
CHAR8 *EFIAPI AsciiStrGetNextTokenField(IN CHAR8 *CharSet)
CHAR8 *EFIAPI AsciiStrGetNewTokenField(IN CHAR8 *String, IN CHAR8 *CharSet)
CHAR16 *EFIAPI StrGetNextTokenField(IN CHAR16 *CharSet)
INTN EFIAPI StriCmp(IN CHAR16 *String, IN CHAR16 *String2)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279