]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | \r | |
3 | Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r | |
4 | This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "Edb.h"\r | |
16 | \r | |
17 | /**\r | |
18 | \r | |
19 | Convert hex string to uint.\r | |
20 | \r | |
21 | @param Str - The string\r | |
22 | \r | |
23 | **/\r | |
24 | UINTN\r | |
25 | EFIAPI\r | |
26 | Xtoi (\r | |
27 | CHAR16 *Str\r | |
28 | )\r | |
29 | {\r | |
30 | UINTN RetVal;\r | |
31 | CHAR16 TempChar;\r | |
32 | UINTN MaxVal;\r | |
33 | \r | |
34 | ASSERT (Str != NULL);\r | |
35 | \r | |
36 | MaxVal = (UINTN) -1 >> 4;\r | |
37 | //\r | |
38 | // skip preceeding white space\r | |
39 | //\r | |
40 | while (*Str != '\0' && *Str == ' ') {\r | |
41 | Str += 1;\r | |
42 | }\r | |
43 | //\r | |
44 | // skip preceeding zeros\r | |
45 | //\r | |
46 | while (*Str != '\0' && *Str == '0') {\r | |
47 | Str += 1;\r | |
48 | }\r | |
49 | //\r | |
50 | // skip preceeding white space\r | |
51 | //\r | |
52 | if (*Str != '\0' && (*Str == 'x' || *Str == 'X')) {\r | |
53 | Str += 1;\r | |
54 | }\r | |
55 | //\r | |
56 | // convert hex digits\r | |
57 | //\r | |
58 | RetVal = 0;\r | |
59 | TempChar = *(Str++);\r | |
60 | while (TempChar != '\0') {\r | |
61 | if (TempChar >= 'a' && TempChar <= 'f') {\r | |
62 | TempChar -= 'a' - 'A';\r | |
63 | }\r | |
64 | \r | |
65 | if ((TempChar >= '0' && TempChar <= '9') || (TempChar >= 'A' && TempChar <= 'F')) {\r | |
66 | if (RetVal > MaxVal) {\r | |
67 | return (UINTN) -1;\r | |
68 | }\r | |
69 | \r | |
70 | RetVal = (RetVal << 4) | (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));\r | |
71 | } else {\r | |
72 | break;\r | |
73 | }\r | |
74 | \r | |
75 | TempChar = *(Str++);\r | |
76 | }\r | |
77 | \r | |
78 | return RetVal;\r | |
79 | }\r | |
80 | \r | |
81 | /**\r | |
82 | \r | |
83 | Convert hex string to uint.\r | |
84 | \r | |
85 | @param Str - The string\r | |
86 | \r | |
87 | **/\r | |
88 | UINT64\r | |
89 | EFIAPI\r | |
90 | LXtoi (\r | |
91 | CHAR16 *Str\r | |
92 | )\r | |
93 | {\r | |
94 | UINT64 RetVal;\r | |
95 | CHAR16 TempChar;\r | |
96 | UINT64 MaxVal;\r | |
97 | \r | |
98 | ASSERT (Str != NULL);\r | |
99 | \r | |
100 | MaxVal = RShiftU64 ((UINT64) -1, 4);\r | |
101 | //\r | |
102 | // skip preceeding white space\r | |
103 | //\r | |
104 | while (*Str != '\0' && *Str == ' ') {\r | |
105 | Str += 1;\r | |
106 | }\r | |
107 | //\r | |
108 | // skip preceeding zeros\r | |
109 | //\r | |
110 | while (*Str != '\0' && *Str == '0') {\r | |
111 | Str += 1;\r | |
112 | }\r | |
113 | //\r | |
114 | // skip preceeding white space\r | |
115 | //\r | |
116 | if (*Str != '\0' && (*Str == 'x' || *Str == 'X')) {\r | |
117 | Str += 1;\r | |
118 | }\r | |
119 | //\r | |
120 | // convert hex digits\r | |
121 | //\r | |
122 | RetVal = 0;\r | |
123 | TempChar = *(Str++);\r | |
124 | while (TempChar != '\0') {\r | |
125 | if (TempChar >= 'a' && TempChar <= 'f') {\r | |
126 | TempChar -= 'a' - 'A';\r | |
127 | }\r | |
128 | \r | |
129 | if ((TempChar >= '0' && TempChar <= '9') || (TempChar >= 'A' && TempChar <= 'F')) {\r | |
130 | if (RetVal > MaxVal) {\r | |
131 | return (UINT64) -1;\r | |
132 | }\r | |
133 | \r | |
134 | RetVal = LShiftU64 (RetVal, 4);\r | |
135 | RetVal = RetVal + (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));\r | |
136 | } else {\r | |
137 | break;\r | |
138 | }\r | |
139 | \r | |
140 | TempChar = *(Str++);\r | |
141 | }\r | |
142 | \r | |
143 | return RetVal;\r | |
144 | }\r | |
145 | \r | |
146 | /**\r | |
147 | \r | |
148 | Convert hex string to uint.\r | |
149 | \r | |
150 | @param Str - The string\r | |
151 | \r | |
152 | **/\r | |
153 | UINTN\r | |
154 | EFIAPI\r | |
155 | Atoi (\r | |
156 | CHAR16 *Str\r | |
157 | )\r | |
158 | {\r | |
159 | UINTN RetVal;\r | |
160 | CHAR16 TempChar;\r | |
161 | UINTN MaxVal;\r | |
162 | UINTN ResteVal;\r | |
163 | \r | |
164 | ASSERT (Str != NULL);\r | |
165 | \r | |
166 | MaxVal = (UINTN) -1 / 10;\r | |
167 | ResteVal = (UINTN) -1 % 10;\r | |
168 | //\r | |
169 | // skip preceeding white space\r | |
170 | //\r | |
171 | while (*Str != '\0' && *Str == ' ') {\r | |
172 | Str += 1;\r | |
173 | }\r | |
174 | //\r | |
175 | // convert digits\r | |
176 | //\r | |
177 | RetVal = 0;\r | |
178 | TempChar = *(Str++);\r | |
179 | while (TempChar != '\0') {\r | |
180 | if (TempChar >= '0' && TempChar <= '9') {\r | |
181 | if (RetVal > MaxVal || (RetVal == MaxVal && TempChar - '0' > (INTN) ResteVal)) {\r | |
182 | return (UINTN) -1;\r | |
183 | }\r | |
184 | \r | |
185 | RetVal = (RetVal * 10) + TempChar - '0';\r | |
186 | } else {\r | |
187 | break;\r | |
188 | }\r | |
189 | \r | |
190 | TempChar = *(Str++);\r | |
191 | }\r | |
192 | \r | |
193 | return RetVal;\r | |
194 | }\r | |
195 | \r | |
196 | /**\r | |
197 | \r | |
198 | Convert hex string to uint.\r | |
199 | \r | |
200 | @param Str - The string\r | |
201 | \r | |
202 | **/\r | |
203 | UINTN\r | |
204 | EFIAPI\r | |
205 | AsciiXtoi (\r | |
206 | CHAR8 *Str\r | |
207 | )\r | |
208 | {\r | |
209 | UINTN RetVal;\r | |
210 | CHAR8 TempChar;\r | |
211 | UINTN MaxVal;\r | |
212 | \r | |
213 | ASSERT (Str != NULL);\r | |
214 | \r | |
215 | MaxVal = (UINTN) -1 >> 4;\r | |
216 | //\r | |
217 | // skip preceeding white space\r | |
218 | //\r | |
219 | while (*Str != '\0' && *Str == ' ') {\r | |
220 | Str += 1;\r | |
221 | }\r | |
222 | //\r | |
223 | // skip preceeding zeros\r | |
224 | //\r | |
225 | while (*Str != '\0' && *Str == '0') {\r | |
226 | Str += 1;\r | |
227 | }\r | |
228 | //\r | |
229 | // skip preceeding white space\r | |
230 | //\r | |
231 | if (*Str != '\0' && (*Str == 'x' || *Str == 'X')) {\r | |
232 | Str += 1;\r | |
233 | }\r | |
234 | //\r | |
235 | // convert hex digits\r | |
236 | //\r | |
237 | RetVal = 0;\r | |
238 | TempChar = *(Str++);\r | |
239 | while (TempChar != '\0') {\r | |
240 | if (TempChar >= 'a' && TempChar <= 'f') {\r | |
241 | TempChar -= 'a' - 'A';\r | |
242 | }\r | |
243 | \r | |
244 | if ((TempChar >= '0' && TempChar <= '9') || (TempChar >= 'A' && TempChar <= 'F')) {\r | |
245 | if (RetVal > MaxVal) {\r | |
246 | return (UINTN) -1;\r | |
247 | }\r | |
248 | \r | |
249 | RetVal = (RetVal << 4) | (TempChar - (TempChar >= 'A' ? 'A' - 10 : '0'));\r | |
250 | } else {\r | |
251 | break;\r | |
252 | }\r | |
253 | \r | |
254 | TempChar = *(Str++);\r | |
255 | }\r | |
256 | \r | |
257 | return RetVal;\r | |
258 | }\r | |
259 | \r | |
260 | /**\r | |
261 | \r | |
262 | Convert hex string to uint.\r | |
263 | \r | |
264 | @param Str - The string\r | |
265 | \r | |
266 | **/\r | |
267 | UINTN\r | |
268 | EFIAPI\r | |
269 | AsciiAtoi (\r | |
270 | CHAR8 *Str\r | |
271 | )\r | |
272 | {\r | |
273 | UINTN RetVal;\r | |
274 | CHAR8 TempChar;\r | |
275 | UINTN MaxVal;\r | |
276 | UINTN ResteVal;\r | |
277 | \r | |
278 | ASSERT (Str != NULL);\r | |
279 | \r | |
280 | MaxVal = (UINTN) -1 / 10;\r | |
281 | ResteVal = (UINTN) -1 % 10;\r | |
282 | //\r | |
283 | // skip preceeding white space\r | |
284 | //\r | |
285 | while (*Str != '\0' && *Str == ' ') {\r | |
286 | Str += 1;\r | |
287 | }\r | |
288 | //\r | |
289 | // convert digits\r | |
290 | //\r | |
291 | RetVal = 0;\r | |
292 | TempChar = *(Str++);\r | |
293 | while (TempChar != '\0') {\r | |
294 | if (TempChar >= '0' && TempChar <= '9') {\r | |
295 | if (RetVal > MaxVal || (RetVal == MaxVal && TempChar - '0' > (INTN) ResteVal)) {\r | |
296 | return (UINTN) -1;\r | |
297 | }\r | |
298 | \r | |
299 | RetVal = (RetVal * 10) + TempChar - '0';\r | |
300 | } else {\r | |
301 | break;\r | |
302 | }\r | |
303 | \r | |
304 | TempChar = *(Str++);\r | |
305 | }\r | |
306 | \r | |
307 | return RetVal;\r | |
308 | }\r | |
309 | \r | |
310 | \r | |
311 | /**\r | |
312 | Compare the Unicode and Ascii string pointed by String to the string pointed by String2.\r | |
313 | \r | |
314 | @param String - Unicode String to process\r | |
315 | \r | |
316 | @param String2 - Ascii string to process\r | |
317 | \r | |
318 | @return Return a positive integer if String is lexicall greater than String2; Zero if\r | |
319 | the two strings are identical; and a negative interger if String is lexically\r | |
320 | less than String2.\r | |
321 | \r | |
322 | **/\r | |
323 | INTN\r | |
324 | EFIAPI\r | |
325 | StrCmpUnicodeAndAscii (\r | |
326 | IN CHAR16 *String,\r | |
327 | IN CHAR8 *String2\r | |
328 | )\r | |
329 | {\r | |
330 | while (*String != '\0') {\r | |
331 | if (*String != (CHAR16)*String2) {\r | |
332 | break;\r | |
333 | }\r | |
334 | \r | |
335 | String += 1;\r | |
336 | String2 += 1;\r | |
337 | }\r | |
338 | \r | |
339 | return (*String - (CHAR16)*String2);\r | |
340 | }\r | |
341 | \r | |
342 | /**\r | |
343 | \r | |
344 | Compare the Unicode string pointed by String to the string pointed by String2.\r | |
345 | \r | |
346 | @param String - Unicode String to process\r | |
347 | @param String2 - Unicode string to process\r | |
348 | \r | |
349 | @return Return a positive integer if String is lexically greater than String2; Zero if\r | |
350 | the two strings are identical; and a negative integer if String is lexically\r | |
351 | less than String2.\r | |
352 | \r | |
353 | **/\r | |
354 | INTN\r | |
355 | EFIAPI\r | |
356 | StriCmp (\r | |
357 | IN CHAR16 *String,\r | |
358 | IN CHAR16 *String2\r | |
359 | )\r | |
360 | {\r | |
361 | while ((*String != L'\0') &&\r | |
362 | (CharToUpper (*String) == CharToUpper (*String2))) {\r | |
363 | String++;\r | |
364 | String2++;\r | |
365 | }\r | |
366 | \r | |
367 | return CharToUpper (*String) - CharToUpper (*String2);\r | |
368 | }\r | |
369 | \r | |
370 | /**\r | |
371 | \r | |
372 | Compare the Unicode and Ascii string pointed by String to the string pointed by String2.\r | |
373 | \r | |
374 | @param String - Unicode String to process\r | |
375 | @param String2 - Ascii string to process\r | |
376 | \r | |
377 | @return Return a positive integer if String is lexically greater than String2; Zero if\r | |
378 | the two strings are identical; and a negative integer if String is lexically\r | |
379 | less than String2.\r | |
380 | \r | |
381 | **/\r | |
382 | INTN\r | |
383 | EFIAPI\r | |
384 | StriCmpUnicodeAndAscii (\r | |
385 | IN CHAR16 *String,\r | |
386 | IN CHAR8 *String2\r | |
387 | )\r | |
388 | {\r | |
389 | while ((*String != L'\0') &&\r | |
390 | (CharToUpper (*String) == (CHAR16)AsciiCharToUpper (*String2))) {\r | |
391 | String++;\r | |
392 | String2++;\r | |
393 | }\r | |
394 | \r | |
395 | return CharToUpper (*String) - (CHAR16)AsciiCharToUpper (*String2);\r | |
396 | }\r | |
397 | \r | |
398 | /**\r | |
399 | \r | |
400 | Verify if the string is end with the sub string.\r | |
401 | \r | |
402 | @param Str - The string where to search the sub string\r | |
403 | @param SubStr - The substring.\r | |
404 | \r | |
405 | **/\r | |
406 | BOOLEAN\r | |
407 | EFIAPI\r | |
408 | StrEndWith (\r | |
409 | IN CHAR16 *Str,\r | |
410 | IN CHAR16 *SubStr\r | |
411 | )\r | |
412 | {\r | |
413 | CHAR16 *Temp;\r | |
414 | \r | |
415 | if ((Str == NULL) || (SubStr == NULL) || (StrLen(Str) < StrLen(SubStr))) {\r | |
416 | return FALSE;\r | |
417 | }\r | |
418 | \r | |
419 | Temp = Str + StrLen(Str) - StrLen(SubStr);\r | |
420 | \r | |
421 | //\r | |
422 | // Compare\r | |
423 | //\r | |
424 | if (StriCmp (Temp, SubStr) == 0) {\r | |
425 | return TRUE;\r | |
426 | } else {\r | |
427 | return FALSE;\r | |
428 | }\r | |
429 | }\r | |
430 | \r | |
431 | /**\r | |
432 | Duplicate a string.\r | |
433 | \r | |
434 | @param Src The string to be duplicated.\r | |
435 | \r | |
436 | **/\r | |
437 | CHAR16 *\r | |
438 | EFIAPI\r | |
439 | StrDuplicate (\r | |
440 | IN CHAR16 *Src\r | |
441 | )\r | |
442 | {\r | |
443 | CHAR16 *Dest;\r | |
444 | UINTN Size;\r | |
445 | \r | |
446 | Size = (StrLen(Src) + 1) * sizeof(CHAR16);\r | |
447 | Dest = AllocateZeroPool (Size);\r | |
448 | if (Dest != NULL) {\r | |
449 | CopyMem (Dest, Src, Size);\r | |
450 | }\r | |
451 | return Dest;\r | |
452 | }\r | |
453 | \r | |
454 | \r | |
455 | CHAR16 *mLineBuffer = NULL;\r | |
456 | CHAR16 *mFieldBuffer = NULL;\r | |
457 | \r | |
458 | /**\r | |
459 | \r | |
460 | Find the first substring.\r | |
461 | \r | |
462 | @param String Point to the string where to find the substring.\r | |
463 | @param CharSet Point to the string to be found.\r | |
464 | \r | |
465 | **/\r | |
466 | UINTN\r | |
467 | EFIAPI\r | |
468 | StrSpn (\r | |
469 | IN CHAR16 *String,\r | |
470 | IN CHAR16 *CharSet\r | |
471 | )\r | |
472 | {\r | |
473 | UINTN Count;\r | |
474 | CHAR16 *Str1;\r | |
475 | CHAR16 *Str2;\r | |
476 | \r | |
477 | Count = 0;\r | |
478 | \r | |
479 | for (Str1 = String; *Str1 != L'\0'; Str1 ++) {\r | |
480 | for (Str2 = CharSet; *Str2 != L'\0'; Str2 ++) {\r | |
481 | if (*Str1 == *Str2) {\r | |
482 | break;\r | |
483 | }\r | |
484 | }\r | |
485 | \r | |
486 | if (*Str2 == L'\0') {\r | |
487 | return Count;\r | |
488 | }\r | |
489 | \r | |
490 | Count ++;\r | |
491 | }\r | |
492 | \r | |
493 | return Count;\r | |
494 | }\r | |
495 | \r | |
496 | /**\r | |
497 | \r | |
498 | Searches a string for the first occurrence of a character contained in a\r | |
499 | specified buffer.\r | |
500 | \r | |
501 | @param String Point to the string where to find the substring.\r | |
502 | @param CharSet Point to the string to be found.\r | |
503 | \r | |
504 | **/\r | |
505 | CHAR16 *\r | |
506 | EFIAPI\r | |
507 | StrBrk (\r | |
508 | IN CHAR16 *String,\r | |
509 | IN CHAR16 *CharSet\r | |
510 | )\r | |
511 | {\r | |
512 | CHAR16 *Str1;\r | |
513 | CHAR16 *Str2;\r | |
514 | \r | |
515 | for (Str1 = String; *Str1 != L'\0'; Str1 ++) {\r | |
516 | for (Str2 = CharSet; *Str2 != L'\0'; Str2 ++) {\r | |
517 | if (*Str1 == *Str2) {\r | |
518 | return (CHAR16 *) Str1;\r | |
519 | }\r | |
520 | }\r | |
521 | }\r | |
522 | \r | |
523 | return NULL;\r | |
524 | }\r | |
525 | \r | |
526 | /**\r | |
527 | \r | |
528 | Find the next token after one or more specified characters.\r | |
529 | \r | |
530 | @param String Point to the string where to find the substring.\r | |
531 | @param CharSet Point to the string to be found.\r | |
532 | \r | |
533 | **/\r | |
534 | CHAR16 *\r | |
535 | EFIAPI\r | |
536 | StrTokenLine (\r | |
537 | IN CHAR16 *String OPTIONAL,\r | |
538 | IN CHAR16 *CharSet\r | |
539 | )\r | |
540 | {\r | |
541 | CHAR16 *Begin;\r | |
542 | CHAR16 *End;\r | |
543 | \r | |
544 | Begin = (String == NULL) ? mLineBuffer : String;\r | |
545 | if (Begin == NULL) {\r | |
546 | return NULL;\r | |
547 | }\r | |
548 | \r | |
549 | Begin += StrSpn (Begin, CharSet);\r | |
550 | if (*Begin == L'\0') {\r | |
551 | mLineBuffer = NULL;\r | |
552 | return NULL;\r | |
553 | }\r | |
554 | \r | |
555 | End = StrBrk (Begin, CharSet);\r | |
556 | if ((End != NULL) && (*End != L'\0')) {\r | |
557 | *End = L'\0';\r | |
558 | End ++;\r | |
559 | }\r | |
560 | \r | |
561 | mLineBuffer = End;\r | |
562 | return Begin;\r | |
563 | }\r | |
564 | \r | |
565 | /**\r | |
566 | \r | |
567 | Find the next token after one specificed characters.\r | |
568 | \r | |
569 | @param String Point to the string where to find the substring.\r | |
570 | @param CharSet Point to the string to be found.\r | |
571 | \r | |
572 | **/\r | |
573 | CHAR16 *\r | |
574 | EFIAPI\r | |
575 | StrTokenField (\r | |
576 | IN CHAR16 *String OPTIONAL,\r | |
577 | IN CHAR16 *CharSet\r | |
578 | )\r | |
579 | {\r | |
580 | CHAR16 *Begin;\r | |
581 | CHAR16 *End;\r | |
582 | \r | |
583 | \r | |
584 | Begin = (String == NULL) ? mFieldBuffer : String;\r | |
585 | if (Begin == NULL) {\r | |
586 | return NULL;\r | |
587 | }\r | |
588 | \r | |
589 | if (*Begin == L'\0') {\r | |
590 | mFieldBuffer = NULL;\r | |
591 | return NULL;\r | |
592 | }\r | |
593 | \r | |
594 | End = StrBrk (Begin, CharSet);\r | |
595 | if ((End != NULL) && (*End != L'\0')) {\r | |
596 | *End = L'\0';\r | |
597 | End ++;\r | |
598 | }\r | |
599 | \r | |
600 | mFieldBuffer = End;\r | |
601 | return Begin;\r | |
602 | }\r | |
603 | \r | |
604 | /**\r | |
605 | \r | |
606 | Find the next token after one or more specified characters.\r | |
607 | \r | |
608 | @param String Point to the string where to find the substring.\r | |
609 | @param CharSet Point to the string to be found.\r | |
610 | \r | |
611 | **/\r | |
612 | CHAR16 *\r | |
613 | EFIAPI\r | |
614 | StrGetNewTokenLine (\r | |
615 | IN CHAR16 *String,\r | |
616 | IN CHAR16 *CharSet\r | |
617 | )\r | |
618 | {\r | |
619 | return StrTokenLine (String, CharSet);\r | |
620 | }\r | |
621 | \r | |
622 | /**\r | |
623 | \r | |
624 | Find the next token after one or more specified characters.\r | |
625 | \r | |
626 | @param CharSet Point to the string to be found.\r | |
627 | \r | |
628 | **/\r | |
629 | CHAR16 *\r | |
630 | EFIAPI\r | |
631 | StrGetNextTokenLine (\r | |
632 | IN CHAR16 *CharSet\r | |
633 | )\r | |
634 | {\r | |
635 | return StrTokenLine (NULL, CharSet);\r | |
636 | }\r | |
637 | \r | |
638 | /**\r | |
639 | \r | |
640 | Find the next token after one specificed characters.\r | |
641 | \r | |
642 | @param String Point to the string where to find the substring.\r | |
643 | @param CharSet Point to the string to be found.\r | |
644 | \r | |
645 | **/\r | |
646 | CHAR16 *\r | |
647 | EFIAPI\r | |
648 | StrGetNewTokenField (\r | |
649 | IN CHAR16 *String,\r | |
650 | IN CHAR16 *CharSet\r | |
651 | )\r | |
652 | {\r | |
653 | return StrTokenField (String, CharSet);\r | |
654 | }\r | |
655 | \r | |
656 | /**\r | |
657 | \r | |
658 | Find the next token after one specificed characters.\r | |
659 | \r | |
660 | @param CharSet Point to the string to be found.\r | |
661 | \r | |
662 | **/\r | |
663 | CHAR16 *\r | |
664 | EFIAPI\r | |
665 | StrGetNextTokenField (\r | |
666 | IN CHAR16 *CharSet\r | |
667 | )\r | |
668 | {\r | |
669 | return StrTokenField (NULL, CharSet);\r | |
670 | }\r | |
671 | \r | |
672 | /**\r | |
673 | \r | |
674 | Patch a character to the end of a string.\r | |
675 | \r | |
676 | @param Buffer The string to be patched.\r | |
677 | @param Patch The patch character.\r | |
678 | \r | |
679 | **/\r | |
680 | VOID\r | |
681 | EFIAPI\r | |
682 | PatchForStrTokenAfter (\r | |
683 | IN CHAR16 *Buffer,\r | |
684 | IN CHAR16 Patch\r | |
685 | )\r | |
686 | {\r | |
687 | CHAR16 *Str;\r | |
688 | \r | |
689 | if (Buffer == NULL) {\r | |
690 | return ;\r | |
691 | }\r | |
692 | \r | |
693 | Str = Buffer;\r | |
694 | while (*Str != 0) {\r | |
695 | Str ++;\r | |
696 | }\r | |
697 | *Str = Patch;\r | |
698 | \r | |
699 | while (*(Str ++) != '\0') {\r | |
700 | if (*Str == 0) {\r | |
701 | *Str = Patch;\r | |
702 | } else {\r | |
703 | break;\r | |
704 | }\r | |
705 | }\r | |
706 | \r | |
707 | return ;\r | |
708 | }\r | |
709 | \r | |
710 | /**\r | |
711 | Patch a character at the beginning of a string.\r | |
712 | \r | |
713 | @param Buffer The string to be patched.\r | |
714 | @param Patch The patch character.\r | |
715 | \r | |
716 | **/\r | |
717 | VOID\r | |
718 | EFIAPI\r | |
719 | PatchForStrTokenBefore (\r | |
720 | IN CHAR16 *Buffer,\r | |
721 | IN CHAR16 Patch\r | |
722 | )\r | |
723 | {\r | |
724 | CHAR16 *Str;\r | |
725 | \r | |
726 | if (Buffer == NULL) {\r | |
727 | return ;\r | |
728 | }\r | |
729 | \r | |
730 | Str = Buffer;\r | |
731 | while (*(Str --) != '\0') {\r | |
732 | if ((*Str == 0) || (*Str == Patch)) {\r | |
733 | *Str = Patch;\r | |
734 | } else {\r | |
735 | break;\r | |
736 | }\r | |
737 | }\r | |
738 | \r | |
739 | return ;\r | |
740 | }\r | |
741 | \r | |
742 | CHAR8 *mAsciiLineBuffer = NULL;\r | |
743 | CHAR8 *mAsciiFieldBuffer = NULL;\r | |
744 | \r | |
745 | /**\r | |
746 | \r | |
747 | Find the first substring.\r | |
748 | \r | |
749 | @param String Point to the string where to find the substring.\r | |
750 | @param CharSet Point to the string to be found.\r | |
751 | \r | |
752 | **/\r | |
753 | UINTN\r | |
754 | EFIAPI\r | |
755 | AsciiStrSpn (\r | |
756 | IN CHAR8 *String,\r | |
757 | IN CHAR8 *CharSet\r | |
758 | )\r | |
759 | {\r | |
760 | UINTN Count;\r | |
761 | CHAR8 *Str1;\r | |
762 | CHAR8 *Str2;\r | |
763 | \r | |
764 | Count = 0;\r | |
765 | \r | |
766 | for (Str1 = String; *Str1 != '\0'; Str1 ++) {\r | |
767 | for (Str2 = CharSet; *Str2 != '\0'; Str2 ++) {\r | |
768 | if (*Str1 == *Str2) {\r | |
769 | break;\r | |
770 | }\r | |
771 | }\r | |
772 | \r | |
773 | if (*Str2 == '\0') {\r | |
774 | return Count;\r | |
775 | }\r | |
776 | \r | |
777 | Count ++;\r | |
778 | }\r | |
779 | \r | |
780 | return Count;\r | |
781 | }\r | |
782 | \r | |
783 | /**\r | |
784 | Searches a string for the first occurrence of a character contained in a\r | |
785 | specified buffer.\r | |
786 | \r | |
787 | @param String Point to the string where to find the substring.\r | |
788 | @param CharSet Point to the string to be found.\r | |
789 | \r | |
790 | **/\r | |
791 | CHAR8 *\r | |
792 | EFIAPI\r | |
793 | AsciiStrBrk (\r | |
794 | IN CHAR8 *String,\r | |
795 | IN CHAR8 *CharSet\r | |
796 | )\r | |
797 | {\r | |
798 | CHAR8 *Str1;\r | |
799 | CHAR8 *Str2;\r | |
800 | \r | |
801 | for (Str1 = String; *Str1 != '\0'; Str1 ++) {\r | |
802 | for (Str2 = CharSet; *Str2 != '\0'; Str2 ++) {\r | |
803 | if (*Str1 == *Str2) {\r | |
804 | return (CHAR8 *) Str1;\r | |
805 | }\r | |
806 | }\r | |
807 | }\r | |
808 | \r | |
809 | return NULL;\r | |
810 | }\r | |
811 | \r | |
812 | /**\r | |
813 | \r | |
814 | Find the next token after one or more specified characters.\r | |
815 | \r | |
816 | @param String Point to the string where to find the substring.\r | |
817 | @param CharSet Point to the string to be found.\r | |
818 | \r | |
819 | **/\r | |
820 | CHAR8 *\r | |
821 | EFIAPI\r | |
822 | AsciiStrTokenLine (\r | |
823 | IN CHAR8 *String OPTIONAL,\r | |
824 | IN CHAR8 *CharSet\r | |
825 | )\r | |
826 | {\r | |
827 | CHAR8 *Begin;\r | |
828 | CHAR8 *End;\r | |
829 | \r | |
830 | Begin = (String == NULL) ? mAsciiLineBuffer : String;\r | |
831 | if (Begin == NULL) {\r | |
832 | return NULL;\r | |
833 | }\r | |
834 | \r | |
835 | Begin += AsciiStrSpn (Begin, CharSet);\r | |
836 | if (*Begin == '\0') {\r | |
837 | mAsciiLineBuffer = NULL;\r | |
838 | return NULL;\r | |
839 | }\r | |
840 | \r | |
841 | End = AsciiStrBrk (Begin, CharSet);\r | |
842 | if ((End != NULL) && (*End != '\0')) {\r | |
843 | *End = '\0';\r | |
844 | End ++;\r | |
845 | }\r | |
846 | \r | |
847 | mAsciiLineBuffer = End;\r | |
848 | return Begin;\r | |
849 | }\r | |
850 | \r | |
851 | /**\r | |
852 | \r | |
853 | Find the next token after one specificed characters.\r | |
854 | \r | |
855 | @param String Point to the string where to find the substring.\r | |
856 | @param CharSet Point to the string to be found.\r | |
857 | \r | |
858 | **/\r | |
859 | CHAR8 *\r | |
860 | EFIAPI\r | |
861 | AsciiStrTokenField (\r | |
862 | IN CHAR8 *String OPTIONAL,\r | |
863 | IN CHAR8 *CharSet\r | |
864 | )\r | |
865 | {\r | |
866 | CHAR8 *Begin;\r | |
867 | CHAR8 *End;\r | |
868 | \r | |
869 | \r | |
870 | Begin = (String == NULL) ? mAsciiFieldBuffer : String;\r | |
871 | if (Begin == NULL) {\r | |
872 | return NULL;\r | |
873 | }\r | |
874 | \r | |
875 | if (*Begin == '\0') {\r | |
876 | mAsciiFieldBuffer = NULL;\r | |
877 | return NULL;\r | |
878 | }\r | |
879 | \r | |
880 | End = AsciiStrBrk (Begin, CharSet);\r | |
881 | if ((End != NULL) && (*End != '\0')) {\r | |
882 | *End = '\0';\r | |
883 | End ++;\r | |
884 | }\r | |
885 | \r | |
886 | mAsciiFieldBuffer = End;\r | |
887 | return Begin;\r | |
888 | }\r | |
889 | \r | |
890 | /**\r | |
891 | \r | |
892 | Find the next token after one or more specified characters.\r | |
893 | \r | |
894 | @param String Point to the string where to find the substring.\r | |
895 | @param CharSet Point to the string to be found.\r | |
896 | \r | |
897 | **/\r | |
898 | CHAR8 *\r | |
899 | EFIAPI\r | |
900 | AsciiStrGetNewTokenLine (\r | |
901 | IN CHAR8 *String,\r | |
902 | IN CHAR8 *CharSet\r | |
903 | )\r | |
904 | {\r | |
905 | return AsciiStrTokenLine (String, CharSet);\r | |
906 | }\r | |
907 | \r | |
908 | /**\r | |
909 | \r | |
910 | Find the next token after one or more specified characters.\r | |
911 | \r | |
912 | @param CharSet Point to the string to be found.\r | |
913 | \r | |
914 | **/\r | |
915 | CHAR8 *\r | |
916 | EFIAPI\r | |
917 | AsciiStrGetNextTokenLine (\r | |
918 | IN CHAR8 *CharSet\r | |
919 | )\r | |
920 | {\r | |
921 | return AsciiStrTokenLine (NULL, CharSet);\r | |
922 | }\r | |
923 | \r | |
924 | /**\r | |
925 | \r | |
926 | Find the next token after one specificed characters.\r | |
927 | \r | |
928 | @param String Point to the string where to find the substring.\r | |
929 | @param CharSet Point to the string to be found.\r | |
930 | \r | |
931 | **/\r | |
932 | CHAR8 *\r | |
933 | EFIAPI\r | |
934 | AsciiStrGetNewTokenField (\r | |
935 | IN CHAR8 *String,\r | |
936 | IN CHAR8 *CharSet\r | |
937 | )\r | |
938 | {\r | |
939 | return AsciiStrTokenField (String, CharSet);\r | |
940 | }\r | |
941 | \r | |
942 | /**\r | |
943 | \r | |
944 | Find the next token after one specificed characters.\r | |
945 | \r | |
946 | @param CharSet Point to the string to be found.\r | |
947 | \r | |
948 | **/\r | |
949 | CHAR8 *\r | |
950 | EFIAPI\r | |
951 | AsciiStrGetNextTokenField (\r | |
952 | IN CHAR8 *CharSet\r | |
953 | )\r | |
954 | {\r | |
955 | return AsciiStrTokenField (NULL, CharSet);\r | |
956 | }\r | |
957 | \r | |
958 | /**\r | |
959 | \r | |
960 | Patch a character to the end of a string.\r | |
961 | \r | |
962 | @param Buffer The string to be patched.\r | |
963 | @param Patch The patch character.\r | |
964 | \r | |
965 | **/\r | |
966 | VOID\r | |
967 | EFIAPI\r | |
968 | PatchForAsciiStrTokenAfter (\r | |
969 | IN CHAR8 *Buffer,\r | |
970 | IN CHAR8 Patch\r | |
971 | )\r | |
972 | {\r | |
973 | CHAR8 *Str;\r | |
974 | \r | |
975 | if (Buffer == NULL) {\r | |
976 | return ;\r | |
977 | }\r | |
978 | \r | |
979 | Str = Buffer;\r | |
980 | while (*Str != 0) {\r | |
981 | Str ++;\r | |
982 | }\r | |
983 | *Str = Patch;\r | |
984 | \r | |
985 | while (*(Str ++) != '\0') {\r | |
986 | if (*Str == 0) {\r | |
987 | *Str = Patch;\r | |
988 | } else {\r | |
989 | break;\r | |
990 | }\r | |
991 | }\r | |
992 | \r | |
993 | return ;\r | |
994 | }\r | |
995 | \r | |
996 | /**\r | |
997 | Patch a character at the beginning of a string.\r | |
998 | \r | |
999 | @param Buffer The string to be patched.\r | |
1000 | @param Patch The patch character.\r | |
1001 | \r | |
1002 | **/\r | |
1003 | VOID\r | |
1004 | EFIAPI\r | |
1005 | PatchForAsciiStrTokenBefore (\r | |
1006 | IN CHAR8 *Buffer,\r | |
1007 | IN CHAR8 Patch\r | |
1008 | )\r | |
1009 | {\r | |
1010 | CHAR8 *Str;\r | |
1011 | \r | |
1012 | if (Buffer == NULL) {\r | |
1013 | return ;\r | |
1014 | }\r | |
1015 | \r | |
1016 | Str = Buffer;\r | |
1017 | while (*(Str --) != '\0') {\r | |
1018 | if ((*Str == 0) || (*Str == Patch)) {\r | |
1019 | *Str = Patch;\r | |
1020 | } else {\r | |
1021 | break;\r | |
1022 | }\r | |
1023 | }\r | |
1024 | \r | |
1025 | return ;\r | |
1026 | }\r |