]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | Unicode and ASCII string primatives.\r | |
3 | \r | |
127010dd | 4 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r |
bb817c56 | 5 | This program and the accompanying materials\r |
e1f414b6 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
127010dd | 8 | http://opensource.org/licenses/bsd-license.php.\r |
e1f414b6 | 9 | \r |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
e1f414b6 | 13 | **/\r |
14 | \r | |
e1f414b6 | 15 | #include "BaseLibInternals.h"\r |
16 | \r | |
24dcb5e5 | 17 | \r |
e1f414b6 | 18 | /**\r |
19 | Copies one Null-terminated Unicode string to another Null-terminated Unicode\r | |
20 | string and returns the new Unicode string.\r | |
21 | \r | |
22 | This function copies the contents of the Unicode string Source to the Unicode\r | |
23 | string Destination, and returns Destination. If Source and Destination\r | |
24 | overlap, then the results are undefined.\r | |
25 | \r | |
26 | If Destination is NULL, then ASSERT().\r | |
27 | If Destination is not aligned on a 16-bit boundary, then ASSERT().\r | |
28 | If Source is NULL, then ASSERT().\r | |
29 | If Source is not aligned on a 16-bit boundary, then ASSERT().\r | |
30 | If Source and Destination overlap, then ASSERT().\r | |
31 | If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r | |
dfbe9de9 | 32 | PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 33 | Null-terminator, then ASSERT().\r |
34 | \r | |
127010dd | 35 | @param Destination A pointer to a Null-terminated Unicode string.\r |
36 | @param Source A pointer to a Null-terminated Unicode string.\r | |
e1f414b6 | 37 | \r |
9aa049d9 | 38 | @return Destination.\r |
e1f414b6 | 39 | \r |
40 | **/\r | |
41 | CHAR16 *\r | |
42 | EFIAPI\r | |
43 | StrCpy (\r | |
44 | OUT CHAR16 *Destination,\r | |
45 | IN CONST CHAR16 *Source\r | |
46 | )\r | |
47 | {\r | |
48 | CHAR16 *ReturnValue;\r | |
49 | \r | |
50 | //\r | |
51 | // Destination cannot be NULL\r | |
52 | //\r | |
53 | ASSERT (Destination != NULL);\r | |
24dcb5e5 | 54 | ASSERT (((UINTN) Destination & BIT0) == 0);\r |
e1f414b6 | 55 | \r |
56 | //\r | |
57 | // Destination and source cannot overlap\r | |
58 | //\r | |
59 | ASSERT ((UINTN)(Destination - Source) > StrLen (Source));\r | |
60 | ASSERT ((UINTN)(Source - Destination) > StrLen (Source));\r | |
61 | \r | |
62 | ReturnValue = Destination;\r | |
42eedea9 | 63 | while (*Source != 0) {\r |
e1f414b6 | 64 | *(Destination++) = *(Source++);\r |
65 | }\r | |
66 | *Destination = 0;\r | |
67 | return ReturnValue;\r | |
68 | }\r | |
69 | \r | |
70 | /**\r | |
9aa049d9 | 71 | Copies up to a specified length from one Null-terminated Unicode string to \r |
72 | another Null-terminated Unicode string and returns the new Unicode string.\r | |
e1f414b6 | 73 | \r |
74 | This function copies the contents of the Unicode string Source to the Unicode\r | |
75 | string Destination, and returns Destination. At most, Length Unicode\r | |
76 | characters are copied from Source to Destination. If Length is 0, then\r | |
77 | Destination is returned unmodified. If Length is greater that the number of\r | |
78 | Unicode characters in Source, then Destination is padded with Null Unicode\r | |
79 | characters. If Source and Destination overlap, then the results are\r | |
80 | undefined.\r | |
81 | \r | |
82 | If Length > 0 and Destination is NULL, then ASSERT().\r | |
83 | If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().\r | |
84 | If Length > 0 and Source is NULL, then ASSERT().\r | |
77f863ee | 85 | If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 86 | If Source and Destination overlap, then ASSERT().\r |
53e96610 | 87 | If PcdMaximumUnicodeStringLength is not zero, and Length is greater than \r |
88 | PcdMaximumUnicodeStringLength, then ASSERT().\r | |
e1f414b6 | 89 | If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r |
dfbe9de9 | 90 | PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r |
53e96610 | 91 | then ASSERT().\r |
e1f414b6 | 92 | \r |
127010dd | 93 | @param Destination A pointer to a Null-terminated Unicode string.\r |
94 | @param Source A pointer to a Null-terminated Unicode string.\r | |
2fc59a00 | 95 | @param Length The maximum number of Unicode characters to copy.\r |
e1f414b6 | 96 | \r |
9aa049d9 | 97 | @return Destination.\r |
e1f414b6 | 98 | \r |
99 | **/\r | |
100 | CHAR16 *\r | |
101 | EFIAPI\r | |
102 | StrnCpy (\r | |
103 | OUT CHAR16 *Destination,\r | |
104 | IN CONST CHAR16 *Source,\r | |
105 | IN UINTN Length\r | |
106 | )\r | |
107 | {\r | |
108 | CHAR16 *ReturnValue;\r | |
109 | \r | |
110 | if (Length == 0) {\r | |
111 | return Destination;\r | |
112 | }\r | |
113 | \r | |
114 | //\r | |
115 | // Destination cannot be NULL if Length is not zero\r | |
116 | //\r | |
117 | ASSERT (Destination != NULL);\r | |
24dcb5e5 | 118 | ASSERT (((UINTN) Destination & BIT0) == 0);\r |
e1f414b6 | 119 | \r |
120 | //\r | |
121 | // Destination and source cannot overlap\r | |
e1f414b6 | 122 | //\r |
123 | ASSERT ((UINTN)(Destination - Source) > StrLen (Source));\r | |
124 | ASSERT ((UINTN)(Source - Destination) >= Length);\r | |
125 | \r | |
dfbe9de9 | 126 | if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {\r |
127 | ASSERT (Length <= PcdGet32 (PcdMaximumUnicodeStringLength));\r | |
128 | }\r | |
129 | \r | |
e1f414b6 | 130 | ReturnValue = Destination;\r |
131 | \r | |
132 | while ((*Source != L'\0') && (Length > 0)) {\r | |
133 | *(Destination++) = *(Source++);\r | |
134 | Length--;\r | |
135 | }\r | |
136 | \r | |
137 | ZeroMem (Destination, Length * sizeof (*Destination));\r | |
138 | return ReturnValue;\r | |
139 | }\r | |
140 | \r | |
141 | /**\r | |
142 | Returns the length of a Null-terminated Unicode string.\r | |
143 | \r | |
144 | This function returns the number of Unicode characters in the Null-terminated\r | |
145 | Unicode string specified by String.\r | |
146 | \r | |
147 | If String is NULL, then ASSERT().\r | |
148 | If String is not aligned on a 16-bit boundary, then ASSERT().\r | |
149 | If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r | |
dfbe9de9 | 150 | PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 151 | Null-terminator, then ASSERT().\r |
152 | \r | |
127010dd | 153 | @param String A pointer to a Null-terminated Unicode string.\r |
e1f414b6 | 154 | \r |
155 | @return The length of String.\r | |
156 | \r | |
157 | **/\r | |
158 | UINTN\r | |
159 | EFIAPI\r | |
160 | StrLen (\r | |
161 | IN CONST CHAR16 *String\r | |
162 | )\r | |
163 | {\r | |
164 | UINTN Length;\r | |
165 | \r | |
166 | ASSERT (String != NULL);\r | |
24dcb5e5 | 167 | ASSERT (((UINTN) String & BIT0) == 0);\r |
e1f414b6 | 168 | \r |
169 | for (Length = 0; *String != L'\0'; String++, Length++) {\r | |
170 | //\r | |
171 | // If PcdMaximumUnicodeStringLength is not zero,\r | |
172 | // length should not more than PcdMaximumUnicodeStringLength\r | |
173 | //\r | |
174 | if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {\r | |
175 | ASSERT (Length < PcdGet32 (PcdMaximumUnicodeStringLength));\r | |
176 | }\r | |
177 | }\r | |
178 | return Length;\r | |
179 | }\r | |
180 | \r | |
181 | /**\r | |
182 | Returns the size of a Null-terminated Unicode string in bytes, including the\r | |
183 | Null terminator.\r | |
184 | \r | |
9aa049d9 | 185 | This function returns the size, in bytes, of the Null-terminated Unicode string \r |
186 | specified by String.\r | |
e1f414b6 | 187 | \r |
188 | If String is NULL, then ASSERT().\r | |
189 | If String is not aligned on a 16-bit boundary, then ASSERT().\r | |
190 | If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r | |
dfbe9de9 | 191 | PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 192 | Null-terminator, then ASSERT().\r |
193 | \r | |
127010dd | 194 | @param String A pointer to a Null-terminated Unicode string.\r |
e1f414b6 | 195 | \r |
9aa049d9 | 196 | @return The size of String.\r |
e1f414b6 | 197 | \r |
198 | **/\r | |
199 | UINTN\r | |
200 | EFIAPI\r | |
201 | StrSize (\r | |
202 | IN CONST CHAR16 *String\r | |
203 | )\r | |
204 | {\r | |
205 | return (StrLen (String) + 1) * sizeof (*String);\r | |
206 | }\r | |
207 | \r | |
208 | /**\r | |
209 | Compares two Null-terminated Unicode strings, and returns the difference\r | |
210 | between the first mismatched Unicode characters.\r | |
211 | \r | |
212 | This function compares the Null-terminated Unicode string FirstString to the\r | |
213 | Null-terminated Unicode string SecondString. If FirstString is identical to\r | |
214 | SecondString, then 0 is returned. Otherwise, the value returned is the first\r | |
215 | mismatched Unicode character in SecondString subtracted from the first\r | |
216 | mismatched Unicode character in FirstString.\r | |
217 | \r | |
218 | If FirstString is NULL, then ASSERT().\r | |
219 | If FirstString is not aligned on a 16-bit boundary, then ASSERT().\r | |
220 | If SecondString is NULL, then ASSERT().\r | |
221 | If SecondString is not aligned on a 16-bit boundary, then ASSERT().\r | |
222 | If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more\r | |
dfbe9de9 | 223 | than PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 224 | Null-terminator, then ASSERT().\r |
225 | If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more\r | |
dfbe9de9 | 226 | than PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 227 | Null-terminator, then ASSERT().\r |
228 | \r | |
127010dd | 229 | @param FirstString A pointer to a Null-terminated Unicode string.\r |
230 | @param SecondString A pointer to a Null-terminated Unicode string.\r | |
e1f414b6 | 231 | \r |
1106ffe1 | 232 | @retval 0 FirstString is identical to SecondString.\r |
9aa049d9 | 233 | @return others FirstString is not identical to SecondString.\r |
e1f414b6 | 234 | \r |
235 | **/\r | |
236 | INTN\r | |
237 | EFIAPI\r | |
238 | StrCmp (\r | |
239 | IN CONST CHAR16 *FirstString,\r | |
240 | IN CONST CHAR16 *SecondString\r | |
241 | )\r | |
242 | {\r | |
243 | //\r | |
244 | // ASSERT both strings are less long than PcdMaximumUnicodeStringLength\r | |
245 | //\r | |
246 | ASSERT (StrSize (FirstString) != 0);\r | |
247 | ASSERT (StrSize (SecondString) != 0);\r | |
248 | \r | |
249 | while ((*FirstString != L'\0') && (*FirstString == *SecondString)) {\r | |
250 | FirstString++;\r | |
251 | SecondString++;\r | |
252 | }\r | |
253 | return *FirstString - *SecondString;\r | |
254 | }\r | |
255 | \r | |
256 | /**\r | |
9aa049d9 | 257 | Compares up to a specified length the contents of two Null-terminated Unicode strings,\r |
258 | and returns the difference between the first mismatched Unicode characters.\r | |
2fc60b70 | 259 | \r |
e1f414b6 | 260 | This function compares the Null-terminated Unicode string FirstString to the\r |
261 | Null-terminated Unicode string SecondString. At most, Length Unicode\r | |
262 | characters will be compared. If Length is 0, then 0 is returned. If\r | |
263 | FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r | |
264 | value returned is the first mismatched Unicode character in SecondString\r | |
265 | subtracted from the first mismatched Unicode character in FirstString.\r | |
266 | \r | |
267 | If Length > 0 and FirstString is NULL, then ASSERT().\r | |
77f863ee | 268 | If Length > 0 and FirstString is not aligned on a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 269 | If Length > 0 and SecondString is NULL, then ASSERT().\r |
77f863ee | 270 | If Length > 0 and SecondString is not aligned on a 16-bit boundary, then ASSERT().\r |
53e96610 | 271 | If PcdMaximumUnicodeStringLength is not zero, and Length is greater than\r |
272 | PcdMaximumUnicodeStringLength, then ASSERT().\r | |
273 | If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than\r | |
274 | PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r | |
275 | then ASSERT().\r | |
276 | If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than\r | |
277 | PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r | |
dfbe9de9 | 278 | then ASSERT().\r |
e1f414b6 | 279 | \r |
127010dd | 280 | @param FirstString A pointer to a Null-terminated Unicode string.\r |
281 | @param SecondString A pointer to a Null-terminated Unicode string.\r | |
2fc59a00 | 282 | @param Length The maximum number of Unicode characters to compare.\r |
e1f414b6 | 283 | \r |
1106ffe1 | 284 | @retval 0 FirstString is identical to SecondString.\r |
9aa049d9 | 285 | @return others FirstString is not identical to SecondString.\r |
e1f414b6 | 286 | \r |
287 | **/\r | |
288 | INTN\r | |
289 | EFIAPI\r | |
290 | StrnCmp (\r | |
291 | IN CONST CHAR16 *FirstString,\r | |
292 | IN CONST CHAR16 *SecondString,\r | |
293 | IN UINTN Length\r | |
294 | )\r | |
295 | {\r | |
2bfb6009 | 296 | if (Length == 0) {\r |
e1f414b6 | 297 | return 0;\r |
298 | }\r | |
299 | \r | |
300 | //\r | |
301 | // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.\r | |
302 | // Length tests are performed inside StrLen().\r | |
303 | //\r | |
304 | ASSERT (StrSize (FirstString) != 0);\r | |
305 | ASSERT (StrSize (SecondString) != 0);\r | |
306 | \r | |
dfbe9de9 | 307 | if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {\r |
308 | ASSERT (Length <= PcdGet32 (PcdMaximumUnicodeStringLength));\r | |
309 | }\r | |
310 | \r | |
e1f414b6 | 311 | while ((*FirstString != L'\0') &&\r |
312 | (*FirstString == *SecondString) &&\r | |
313 | (Length > 1)) {\r | |
314 | FirstString++;\r | |
315 | SecondString++;\r | |
316 | Length--;\r | |
317 | }\r | |
318 | \r | |
319 | return *FirstString - *SecondString;\r | |
320 | }\r | |
321 | \r | |
322 | /**\r | |
323 | Concatenates one Null-terminated Unicode string to another Null-terminated\r | |
324 | Unicode string, and returns the concatenated Unicode string.\r | |
325 | \r | |
326 | This function concatenates two Null-terminated Unicode strings. The contents\r | |
327 | of Null-terminated Unicode string Source are concatenated to the end of\r | |
328 | Null-terminated Unicode string Destination. The Null-terminated concatenated\r | |
329 | Unicode String is returned. If Source and Destination overlap, then the\r | |
330 | results are undefined.\r | |
331 | \r | |
332 | If Destination is NULL, then ASSERT().\r | |
77f863ee | 333 | If Destination is not aligned on a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 334 | If Source is NULL, then ASSERT().\r |
77f863ee | 335 | If Source is not aligned on a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 336 | If Source and Destination overlap, then ASSERT().\r |
337 | If PcdMaximumUnicodeStringLength is not zero, and Destination contains more\r | |
dfbe9de9 | 338 | than PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 339 | Null-terminator, then ASSERT().\r |
340 | If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r | |
dfbe9de9 | 341 | PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 342 | Null-terminator, then ASSERT().\r |
343 | If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination\r | |
344 | and Source results in a Unicode string with more than\r | |
dfbe9de9 | 345 | PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 346 | Null-terminator, then ASSERT().\r |
347 | \r | |
127010dd | 348 | @param Destination A pointer to a Null-terminated Unicode string.\r |
349 | @param Source A pointer to a Null-terminated Unicode string.\r | |
e1f414b6 | 350 | \r |
9aa049d9 | 351 | @return Destination.\r |
e1f414b6 | 352 | \r |
353 | **/\r | |
354 | CHAR16 *\r | |
355 | EFIAPI\r | |
356 | StrCat (\r | |
357 | IN OUT CHAR16 *Destination,\r | |
358 | IN CONST CHAR16 *Source\r | |
359 | )\r | |
360 | {\r | |
361 | StrCpy (Destination + StrLen (Destination), Source);\r | |
362 | \r | |
363 | //\r | |
364 | // Size of the resulting string should never be zero.\r | |
365 | // PcdMaximumUnicodeStringLength is tested inside StrLen().\r | |
366 | //\r | |
367 | ASSERT (StrSize (Destination) != 0);\r | |
368 | return Destination;\r | |
369 | }\r | |
370 | \r | |
371 | /**\r | |
9aa049d9 | 372 | Concatenates up to a specified length one Null-terminated Unicode to the end \r |
373 | of another Null-terminated Unicode string, and returns the concatenated \r | |
e1f414b6 | 374 | Unicode string.\r |
375 | \r | |
376 | This function concatenates two Null-terminated Unicode strings. The contents\r | |
377 | of Null-terminated Unicode string Source are concatenated to the end of\r | |
378 | Null-terminated Unicode string Destination, and Destination is returned. At\r | |
379 | most, Length Unicode characters are concatenated from Source to the end of\r | |
380 | Destination, and Destination is always Null-terminated. If Length is 0, then\r | |
381 | Destination is returned unmodified. If Source and Destination overlap, then\r | |
382 | the results are undefined.\r | |
383 | \r | |
384 | If Destination is NULL, then ASSERT().\r | |
385 | If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().\r | |
386 | If Length > 0 and Source is NULL, then ASSERT().\r | |
387 | If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().\r | |
388 | If Source and Destination overlap, then ASSERT().\r | |
53e96610 | 389 | If PcdMaximumUnicodeStringLength is not zero, and Length is greater than \r |
390 | PcdMaximumUnicodeStringLength, then ASSERT().\r | |
e1f414b6 | 391 | If PcdMaximumUnicodeStringLength is not zero, and Destination contains more\r |
dfbe9de9 | 392 | than PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 393 | Null-terminator, then ASSERT().\r |
394 | If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r | |
dfbe9de9 | 395 | PcdMaximumUnicodeStringLength Unicode characters, not including the\r |
e1f414b6 | 396 | Null-terminator, then ASSERT().\r |
397 | If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination\r | |
53e96610 | 398 | and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength\r |
399 | Unicode characters, not including the Null-terminator, then ASSERT().\r | |
e1f414b6 | 400 | \r |
127010dd | 401 | @param Destination A pointer to a Null-terminated Unicode string.\r |
402 | @param Source A pointer to a Null-terminated Unicode string.\r | |
2fc59a00 | 403 | @param Length The maximum number of Unicode characters to concatenate from\r |
e1f414b6 | 404 | Source.\r |
405 | \r | |
9aa049d9 | 406 | @return Destination.\r |
e1f414b6 | 407 | \r |
408 | **/\r | |
409 | CHAR16 *\r | |
410 | EFIAPI\r | |
411 | StrnCat (\r | |
412 | IN OUT CHAR16 *Destination,\r | |
413 | IN CONST CHAR16 *Source,\r | |
414 | IN UINTN Length\r | |
415 | )\r | |
416 | {\r | |
8f635c36 | 417 | UINTN DestinationLen;\r |
418 | \r | |
419 | DestinationLen = StrLen (Destination);\r | |
420 | StrnCpy (Destination + DestinationLen, Source, Length);\r | |
421 | Destination[DestinationLen + Length] = L'\0';\r | |
e1f414b6 | 422 | \r |
423 | //\r | |
424 | // Size of the resulting string should never be zero.\r | |
425 | // PcdMaximumUnicodeStringLength is tested inside StrLen().\r | |
426 | //\r | |
427 | ASSERT (StrSize (Destination) != 0);\r | |
428 | return Destination;\r | |
429 | }\r | |
430 | \r | |
431 | /**\r | |
9aa049d9 | 432 | Returns the first occurrence of a Null-terminated Unicode sub-string\r |
e1f414b6 | 433 | in a Null-terminated Unicode string.\r |
434 | \r | |
9aa049d9 | 435 | This function scans the contents of the Null-terminated Unicode string\r |
436 | specified by String and returns the first occurrence of SearchString.\r | |
437 | If SearchString is not found in String, then NULL is returned. If\r | |
438 | the length of SearchString is zero, then String is\r | |
e1f414b6 | 439 | returned.\r |
9aa049d9 | 440 | \r |
e1f414b6 | 441 | If String is NULL, then ASSERT().\r |
442 | If String is not aligned on a 16-bit boundary, then ASSERT().\r | |
443 | If SearchString is NULL, then ASSERT().\r | |
444 | If SearchString is not aligned on a 16-bit boundary, then ASSERT().\r | |
445 | \r | |
9aa049d9 | 446 | If PcdMaximumUnicodeStringLength is not zero, and SearchString\r |
447 | or String contains more than PcdMaximumUnicodeStringLength Unicode\r | |
dfbe9de9 | 448 | characters, not including the Null-terminator, then ASSERT().\r |
e1f414b6 | 449 | \r |
127010dd | 450 | @param String A pointer to a Null-terminated Unicode string.\r |
451 | @param SearchString A pointer to a Null-terminated Unicode string to search for.\r | |
e1f414b6 | 452 | \r |
9aa049d9 | 453 | @retval NULL If the SearchString does not appear in String.\r |
454 | @return others If there is a match.\r | |
e1f414b6 | 455 | \r |
456 | **/\r | |
457 | CHAR16 *\r | |
458 | EFIAPI\r | |
459 | StrStr (\r | |
2fc60b70 | 460 | IN CONST CHAR16 *String,\r |
461 | IN CONST CHAR16 *SearchString\r | |
e1f414b6 | 462 | )\r |
463 | {\r | |
464 | CONST CHAR16 *FirstMatch;\r | |
465 | CONST CHAR16 *SearchStringTmp;\r | |
466 | \r | |
e1f414b6 | 467 | //\r |
4df26661 | 468 | // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.\r |
469 | // Length tests are performed inside StrLen().\r | |
e1f414b6 | 470 | //\r |
4df26661 | 471 | ASSERT (StrSize (String) != 0);\r |
472 | ASSERT (StrSize (SearchString) != 0);\r | |
e1f414b6 | 473 | \r |
62e71e2f | 474 | if (*SearchString == L'\0') {\r |
faeb3214 | 475 | return (CHAR16 *) String;\r |
62e71e2f | 476 | }\r |
477 | \r | |
478 | while (*String != L'\0') {\r | |
e1f414b6 | 479 | SearchStringTmp = SearchString;\r |
480 | FirstMatch = String;\r | |
481 | \r | |
482 | while ((*String == *SearchStringTmp) \r | |
62e71e2f | 483 | && (*String != L'\0')) {\r |
e1f414b6 | 484 | String++;\r |
485 | SearchStringTmp++;\r | |
486 | } \r | |
487 | \r | |
62e71e2f | 488 | if (*SearchStringTmp == L'\0') {\r |
e1f414b6 | 489 | return (CHAR16 *) FirstMatch;\r |
490 | }\r | |
491 | \r | |
62e71e2f | 492 | if (*String == L'\0') {\r |
493 | return NULL;\r | |
e1f414b6 | 494 | }\r |
62e71e2f | 495 | \r |
496 | String = FirstMatch + 1;\r | |
e1f414b6 | 497 | }\r |
498 | \r | |
499 | return NULL;\r | |
500 | }\r | |
501 | \r | |
502 | /**\r | |
503 | Check if a Unicode character is a decimal character.\r | |
504 | \r | |
505 | This internal function checks if a Unicode character is a \r | |
506 | decimal character. The valid decimal character is from\r | |
507 | L'0' to L'9'.\r | |
508 | \r | |
e1f414b6 | 509 | @param Char The character to check against.\r |
510 | \r | |
511 | @retval TRUE If the Char is a decmial character.\r | |
24dcb5e5 | 512 | @retval FALSE If the Char is not a decmial character.\r |
e1f414b6 | 513 | \r |
514 | **/\r | |
e1f414b6 | 515 | BOOLEAN\r |
42eedea9 | 516 | EFIAPI\r |
e1f414b6 | 517 | InternalIsDecimalDigitCharacter (\r |
518 | IN CHAR16 Char\r | |
519 | )\r | |
520 | {\r | |
521 | return (BOOLEAN) (Char >= L'0' && Char <= L'9');\r | |
522 | }\r | |
523 | \r | |
524 | /**\r | |
525 | Convert a Unicode character to upper case only if \r | |
526 | it maps to a valid small-case ASCII character.\r | |
527 | \r | |
528 | This internal function only deal with Unicode character\r | |
24dcb5e5 | 529 | which maps to a valid small-case ASCII character, i.e.\r |
e1f414b6 | 530 | L'a' to L'z'. For other Unicode character, the input character\r |
531 | is returned directly.\r | |
532 | \r | |
e1f414b6 | 533 | @param Char The character to convert.\r |
534 | \r | |
535 | @retval LowerCharacter If the Char is with range L'a' to L'z'.\r | |
536 | @retval Unchanged Otherwise.\r | |
537 | \r | |
538 | **/\r | |
e1f414b6 | 539 | CHAR16\r |
42eedea9 | 540 | EFIAPI\r |
e1f414b6 | 541 | InternalCharToUpper (\r |
542 | IN CHAR16 Char\r | |
543 | )\r | |
544 | {\r | |
545 | if (Char >= L'a' && Char <= L'z') {\r | |
546 | return (CHAR16) (Char - (L'a' - L'A'));\r | |
547 | }\r | |
548 | \r | |
549 | return Char;\r | |
550 | }\r | |
551 | \r | |
552 | /**\r | |
553 | Convert a Unicode character to numerical value.\r | |
554 | \r | |
555 | This internal function only deal with Unicode character\r | |
556 | which maps to a valid hexadecimal ASII character, i.e.\r | |
557 | L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other \r | |
558 | Unicode character, the value returned does not make sense.\r | |
559 | \r | |
560 | @param Char The character to convert.\r | |
561 | \r | |
24dcb5e5 | 562 | @return The numerical value converted.\r |
e1f414b6 | 563 | \r |
564 | **/\r | |
e1f414b6 | 565 | UINTN\r |
42eedea9 | 566 | EFIAPI\r |
e1f414b6 | 567 | InternalHexCharToUintn (\r |
568 | IN CHAR16 Char\r | |
569 | )\r | |
570 | {\r | |
571 | if (InternalIsDecimalDigitCharacter (Char)) {\r | |
572 | return Char - L'0';\r | |
573 | }\r | |
574 | \r | |
575 | return (UINTN) (10 + InternalCharToUpper (Char) - L'A');\r | |
576 | }\r | |
577 | \r | |
578 | /**\r | |
579 | Check if a Unicode character is a hexadecimal character.\r | |
580 | \r | |
581 | This internal function checks if a Unicode character is a \r | |
582 | decimal character. The valid hexadecimal character is \r | |
583 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r | |
584 | \r | |
585 | \r | |
586 | @param Char The character to check against.\r | |
587 | \r | |
588 | @retval TRUE If the Char is a hexadecmial character.\r | |
24dcb5e5 | 589 | @retval FALSE If the Char is not a hexadecmial character.\r |
e1f414b6 | 590 | \r |
591 | **/\r | |
e1f414b6 | 592 | BOOLEAN\r |
42eedea9 | 593 | EFIAPI\r |
e1f414b6 | 594 | InternalIsHexaDecimalDigitCharacter (\r |
595 | IN CHAR16 Char\r | |
596 | )\r | |
597 | {\r | |
598 | \r | |
599 | return (BOOLEAN) (InternalIsDecimalDigitCharacter (Char) ||\r | |
600 | (Char >= L'A' && Char <= L'F') ||\r | |
601 | (Char >= L'a' && Char <= L'f'));\r | |
602 | }\r | |
603 | \r | |
604 | /**\r | |
9aa049d9 | 605 | Convert a Null-terminated Unicode decimal string to a value of\r |
e1f414b6 | 606 | type UINTN.\r |
607 | \r | |
9aa049d9 | 608 | This function returns a value of type UINTN by interpreting the contents\r |
609 | of the Unicode string specified by String as a decimal number. The format\r | |
e1f414b6 | 610 | of the input Unicode string String is:\r |
9aa049d9 | 611 | \r |
2fe241a2 | 612 | [spaces] [decimal digits].\r |
9aa049d9 | 613 | \r |
614 | The valid decimal digit character is in the range [0-9]. The\r | |
615 | function will ignore the pad space, which includes spaces or\r | |
616 | tab characters, before [decimal digits]. The running zero in the\r | |
617 | beginning of [decimal digits] will be ignored. Then, the function\r | |
618 | stops at the first character that is a not a valid decimal character\r | |
619 | or a Null-terminator, whichever one comes first.\r | |
620 | \r | |
e1f414b6 | 621 | If String is NULL, then ASSERT().\r |
9aa049d9 | 622 | If String is not aligned in a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 623 | If String has only pad spaces, then 0 is returned.\r |
9aa049d9 | 624 | If String has no pad spaces or valid decimal digits,\r |
e1f414b6 | 625 | then 0 is returned.\r |
9aa049d9 | 626 | If the number represented by String overflows according\r |
e1f414b6 | 627 | to the range defined by UINTN, then ASSERT().\r |
9aa049d9 | 628 | \r |
629 | If PcdMaximumUnicodeStringLength is not zero, and String contains\r | |
dfbe9de9 | 630 | more than PcdMaximumUnicodeStringLength Unicode characters, not including\r |
e1f414b6 | 631 | the Null-terminator, then ASSERT().\r |
632 | \r | |
127010dd | 633 | @param String A pointer to a Null-terminated Unicode string.\r |
e1f414b6 | 634 | \r |
9aa049d9 | 635 | @retval Value translated from String.\r |
e1f414b6 | 636 | \r |
637 | **/\r | |
638 | UINTN\r | |
639 | EFIAPI\r | |
640 | StrDecimalToUintn (\r | |
2fc60b70 | 641 | IN CONST CHAR16 *String\r |
e1f414b6 | 642 | )\r |
643 | {\r | |
644 | UINTN Result;\r | |
645 | \r | |
4df26661 | 646 | //\r |
647 | // ASSERT String is less long than PcdMaximumUnicodeStringLength.\r | |
648 | // Length tests are performed inside StrLen().\r | |
649 | //\r | |
650 | ASSERT (StrSize (String) != 0);\r | |
e1f414b6 | 651 | \r |
652 | //\r | |
653 | // Ignore the pad spaces (space or tab)\r | |
654 | //\r | |
955c32f2 | 655 | while ((*String == L' ') || (*String == L'\t')) {\r |
e1f414b6 | 656 | String++;\r |
657 | }\r | |
658 | \r | |
659 | //\r | |
660 | // Ignore leading Zeros after the spaces\r | |
661 | //\r | |
955c32f2 | 662 | while (*String == L'0') {\r |
e1f414b6 | 663 | String++;\r |
664 | }\r | |
665 | \r | |
666 | Result = 0;\r | |
667 | \r | |
668 | while (InternalIsDecimalDigitCharacter (*String)) {\r | |
669 | //\r | |
670 | // If the number represented by String overflows according \r | |
671 | // to the range defined by UINTN, then ASSERT().\r | |
672 | //\r | |
6efe9461 | 673 | ASSERT (Result <= ((((UINTN) ~0) - (*String - L'0')) / 10));\r |
e1f414b6 | 674 | \r |
675 | Result = Result * 10 + (*String - L'0');\r | |
676 | String++;\r | |
677 | }\r | |
678 | \r | |
679 | return Result;\r | |
680 | }\r | |
681 | \r | |
682 | \r | |
683 | /**\r | |
9aa049d9 | 684 | Convert a Null-terminated Unicode decimal string to a value of\r |
e1f414b6 | 685 | type UINT64.\r |
686 | \r | |
9aa049d9 | 687 | This function returns a value of type UINT64 by interpreting the contents\r |
688 | of the Unicode string specified by String as a decimal number. The format\r | |
e1f414b6 | 689 | of the input Unicode string String is:\r |
9aa049d9 | 690 | \r |
2fe241a2 | 691 | [spaces] [decimal digits].\r |
9aa049d9 | 692 | \r |
693 | The valid decimal digit character is in the range [0-9]. The\r | |
694 | function will ignore the pad space, which includes spaces or\r | |
695 | tab characters, before [decimal digits]. The running zero in the\r | |
696 | beginning of [decimal digits] will be ignored. Then, the function\r | |
697 | stops at the first character that is a not a valid decimal character\r | |
698 | or a Null-terminator, whichever one comes first.\r | |
699 | \r | |
e1f414b6 | 700 | If String is NULL, then ASSERT().\r |
9aa049d9 | 701 | If String is not aligned in a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 702 | If String has only pad spaces, then 0 is returned.\r |
9aa049d9 | 703 | If String has no pad spaces or valid decimal digits,\r |
e1f414b6 | 704 | then 0 is returned.\r |
9aa049d9 | 705 | If the number represented by String overflows according\r |
e1f414b6 | 706 | to the range defined by UINT64, then ASSERT().\r |
9aa049d9 | 707 | \r |
708 | If PcdMaximumUnicodeStringLength is not zero, and String contains\r | |
dfbe9de9 | 709 | more than PcdMaximumUnicodeStringLength Unicode characters, not including\r |
e1f414b6 | 710 | the Null-terminator, then ASSERT().\r |
711 | \r | |
127010dd | 712 | @param String A pointer to a Null-terminated Unicode string.\r |
e1f414b6 | 713 | \r |
9aa049d9 | 714 | @retval Value translated from String.\r |
e1f414b6 | 715 | \r |
716 | **/\r | |
717 | UINT64\r | |
718 | EFIAPI\r | |
719 | StrDecimalToUint64 (\r | |
2fc60b70 | 720 | IN CONST CHAR16 *String\r |
e1f414b6 | 721 | )\r |
722 | {\r | |
723 | UINT64 Result;\r | |
724 | \r | |
4df26661 | 725 | //\r |
726 | // ASSERT String is less long than PcdMaximumUnicodeStringLength.\r | |
727 | // Length tests are performed inside StrLen().\r | |
728 | //\r | |
729 | ASSERT (StrSize (String) != 0);\r | |
e1f414b6 | 730 | \r |
731 | //\r | |
732 | // Ignore the pad spaces (space or tab)\r | |
733 | //\r | |
955c32f2 | 734 | while ((*String == L' ') || (*String == L'\t')) {\r |
e1f414b6 | 735 | String++;\r |
736 | }\r | |
737 | \r | |
738 | //\r | |
739 | // Ignore leading Zeros after the spaces\r | |
740 | //\r | |
955c32f2 | 741 | while (*String == L'0') {\r |
e1f414b6 | 742 | String++;\r |
743 | }\r | |
744 | \r | |
745 | Result = 0;\r | |
746 | \r | |
747 | while (InternalIsDecimalDigitCharacter (*String)) {\r | |
748 | //\r | |
749 | // If the number represented by String overflows according \r | |
750 | // to the range defined by UINTN, then ASSERT().\r | |
751 | //\r | |
6efe9461 | 752 | ASSERT (Result <= DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10));\r |
e1f414b6 | 753 | \r |
754 | Result = MultU64x32 (Result, 10) + (*String - L'0');\r | |
755 | String++;\r | |
756 | }\r | |
757 | \r | |
758 | return Result;\r | |
759 | }\r | |
760 | \r | |
761 | /**\r | |
762 | Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.\r | |
763 | \r | |
9aa049d9 | 764 | This function returns a value of type UINTN by interpreting the contents\r |
765 | of the Unicode string specified by String as a hexadecimal number.\r | |
e1f414b6 | 766 | The format of the input Unicode string String is:\r |
9aa049d9 | 767 | \r |
768 | [spaces][zeros][x][hexadecimal digits].\r | |
769 | \r | |
770 | The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r | |
771 | The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r | |
772 | If "x" appears in the input string, it must be prefixed with at least one 0.\r | |
773 | The function will ignore the pad space, which includes spaces or tab characters,\r | |
774 | before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or\r | |
775 | [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the\r | |
776 | first valid hexadecimal digit. Then, the function stops at the first character that is\r | |
e1f414b6 | 777 | a not a valid hexadecimal character or NULL, whichever one comes first.\r |
778 | \r | |
779 | If String is NULL, then ASSERT().\r | |
780 | If String is not aligned in a 16-bit boundary, then ASSERT().\r | |
781 | If String has only pad spaces, then zero is returned.\r | |
9aa049d9 | 782 | If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r |
e1f414b6 | 783 | then zero is returned.\r |
9aa049d9 | 784 | If the number represented by String overflows according to the range defined by\r |
e1f414b6 | 785 | UINTN, then ASSERT().\r |
786 | \r | |
9aa049d9 | 787 | If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r |
dfbe9de9 | 788 | PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r |
e1f414b6 | 789 | then ASSERT().\r |
790 | \r | |
127010dd | 791 | @param String A pointer to a Null-terminated Unicode string.\r |
e1f414b6 | 792 | \r |
9aa049d9 | 793 | @retval Value translated from String.\r |
e1f414b6 | 794 | \r |
795 | **/\r | |
796 | UINTN\r | |
797 | EFIAPI\r | |
798 | StrHexToUintn (\r | |
2fc60b70 | 799 | IN CONST CHAR16 *String\r |
e1f414b6 | 800 | )\r |
801 | {\r | |
802 | UINTN Result;\r | |
803 | \r | |
4df26661 | 804 | //\r |
805 | // ASSERT String is less long than PcdMaximumUnicodeStringLength.\r | |
806 | // Length tests are performed inside StrLen().\r | |
807 | //\r | |
808 | ASSERT (StrSize (String) != 0);\r | |
e1f414b6 | 809 | \r |
810 | //\r | |
811 | // Ignore the pad spaces (space or tab) \r | |
812 | //\r | |
955c32f2 | 813 | while ((*String == L' ') || (*String == L'\t')) {\r |
e1f414b6 | 814 | String++;\r |
815 | }\r | |
816 | \r | |
817 | //\r | |
818 | // Ignore leading Zeros after the spaces\r | |
819 | //\r | |
955c32f2 | 820 | while (*String == L'0') {\r |
e1f414b6 | 821 | String++;\r |
822 | }\r | |
823 | \r | |
824 | if (InternalCharToUpper (*String) == L'X') {\r | |
955c32f2 | 825 | if (*(String - 1) != L'0') {\r |
e1f414b6 | 826 | return 0;\r |
827 | }\r | |
828 | //\r | |
829 | // Skip the 'X'\r | |
830 | //\r | |
831 | String++;\r | |
832 | }\r | |
833 | \r | |
834 | Result = 0;\r | |
835 | \r | |
836 | while (InternalIsHexaDecimalDigitCharacter (*String)) {\r | |
837 | //\r | |
838 | // If the Hex Number represented by String overflows according \r | |
839 | // to the range defined by UINTN, then ASSERT().\r | |
840 | //\r | |
6efe9461 | 841 | ASSERT (Result <= ((((UINTN) ~0) - InternalHexCharToUintn (*String)) >> 4));\r |
e1f414b6 | 842 | \r |
843 | Result = (Result << 4) + InternalHexCharToUintn (*String);\r | |
844 | String++;\r | |
845 | }\r | |
846 | \r | |
847 | return Result;\r | |
848 | }\r | |
849 | \r | |
850 | \r | |
851 | /**\r | |
852 | Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.\r | |
853 | \r | |
9aa049d9 | 854 | This function returns a value of type UINT64 by interpreting the contents\r |
855 | of the Unicode string specified by String as a hexadecimal number.\r | |
856 | The format of the input Unicode string String is\r | |
857 | \r | |
858 | [spaces][zeros][x][hexadecimal digits].\r | |
859 | \r | |
860 | The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r | |
861 | The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r | |
862 | If "x" appears in the input string, it must be prefixed with at least one 0.\r | |
863 | The function will ignore the pad space, which includes spaces or tab characters,\r | |
864 | before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or\r | |
865 | [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the\r | |
866 | first valid hexadecimal digit. Then, the function stops at the first character that is\r | |
e1f414b6 | 867 | a not a valid hexadecimal character or NULL, whichever one comes first.\r |
868 | \r | |
869 | If String is NULL, then ASSERT().\r | |
870 | If String is not aligned in a 16-bit boundary, then ASSERT().\r | |
871 | If String has only pad spaces, then zero is returned.\r | |
9aa049d9 | 872 | If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r |
e1f414b6 | 873 | then zero is returned.\r |
9aa049d9 | 874 | If the number represented by String overflows according to the range defined by\r |
e1f414b6 | 875 | UINT64, then ASSERT().\r |
876 | \r | |
9aa049d9 | 877 | If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r |
dfbe9de9 | 878 | PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r |
e1f414b6 | 879 | then ASSERT().\r |
880 | \r | |
127010dd | 881 | @param String A pointer to a Null-terminated Unicode string.\r |
e1f414b6 | 882 | \r |
9aa049d9 | 883 | @retval Value translated from String.\r |
e1f414b6 | 884 | \r |
2fc60b70 | 885 | **/\r |
e1f414b6 | 886 | UINT64\r |
887 | EFIAPI\r | |
888 | StrHexToUint64 (\r | |
2fc60b70 | 889 | IN CONST CHAR16 *String\r |
e1f414b6 | 890 | )\r |
891 | {\r | |
892 | UINT64 Result;\r | |
893 | \r | |
4df26661 | 894 | //\r |
895 | // ASSERT String is less long than PcdMaximumUnicodeStringLength.\r | |
896 | // Length tests are performed inside StrLen().\r | |
897 | //\r | |
898 | ASSERT (StrSize (String) != 0);\r | |
e1f414b6 | 899 | \r |
900 | //\r | |
901 | // Ignore the pad spaces (space or tab) \r | |
902 | //\r | |
955c32f2 | 903 | while ((*String == L' ') || (*String == L'\t')) {\r |
e1f414b6 | 904 | String++;\r |
905 | }\r | |
906 | \r | |
907 | //\r | |
908 | // Ignore leading Zeros after the spaces\r | |
909 | //\r | |
955c32f2 | 910 | while (*String == L'0') {\r |
e1f414b6 | 911 | String++;\r |
912 | }\r | |
913 | \r | |
914 | if (InternalCharToUpper (*String) == L'X') {\r | |
955c32f2 | 915 | ASSERT (*(String - 1) == L'0');\r |
916 | if (*(String - 1) != L'0') {\r | |
e1f414b6 | 917 | return 0;\r |
918 | }\r | |
919 | //\r | |
920 | // Skip the 'X'\r | |
921 | //\r | |
922 | String++;\r | |
923 | }\r | |
924 | \r | |
925 | Result = 0;\r | |
926 | \r | |
927 | while (InternalIsHexaDecimalDigitCharacter (*String)) {\r | |
928 | //\r | |
929 | // If the Hex Number represented by String overflows according \r | |
930 | // to the range defined by UINTN, then ASSERT().\r | |
931 | //\r | |
6efe9461 | 932 | ASSERT (Result <= RShiftU64 (((UINT64) ~0) - InternalHexCharToUintn (*String) , 4));\r |
e1f414b6 | 933 | \r |
934 | Result = LShiftU64 (Result, 4);\r | |
935 | Result = Result + InternalHexCharToUintn (*String);\r | |
936 | String++;\r | |
937 | }\r | |
938 | \r | |
939 | return Result;\r | |
940 | }\r | |
941 | \r | |
942 | /**\r | |
943 | Check if a ASCII character is a decimal character.\r | |
944 | \r | |
945 | This internal function checks if a Unicode character is a \r | |
946 | decimal character. The valid decimal character is from\r | |
947 | '0' to '9'.\r | |
948 | \r | |
949 | @param Char The character to check against.\r | |
950 | \r | |
951 | @retval TRUE If the Char is a decmial character.\r | |
24dcb5e5 | 952 | @retval FALSE If the Char is not a decmial character.\r |
e1f414b6 | 953 | \r |
954 | **/\r | |
e1f414b6 | 955 | BOOLEAN\r |
42eedea9 | 956 | EFIAPI\r |
e1f414b6 | 957 | InternalAsciiIsDecimalDigitCharacter (\r |
958 | IN CHAR8 Char\r | |
959 | )\r | |
960 | {\r | |
961 | return (BOOLEAN) (Char >= '0' && Char <= '9');\r | |
962 | }\r | |
963 | \r | |
964 | /**\r | |
965 | Check if a ASCII character is a hexadecimal character.\r | |
966 | \r | |
967 | This internal function checks if a ASCII character is a \r | |
968 | decimal character. The valid hexadecimal character is \r | |
969 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r | |
970 | \r | |
971 | \r | |
972 | @param Char The character to check against.\r | |
973 | \r | |
974 | @retval TRUE If the Char is a hexadecmial character.\r | |
24dcb5e5 | 975 | @retval FALSE If the Char is not a hexadecmial character.\r |
e1f414b6 | 976 | \r |
977 | **/\r | |
e1f414b6 | 978 | BOOLEAN\r |
42eedea9 | 979 | EFIAPI\r |
e1f414b6 | 980 | InternalAsciiIsHexaDecimalDigitCharacter (\r |
981 | IN CHAR8 Char\r | |
982 | )\r | |
983 | {\r | |
984 | \r | |
985 | return (BOOLEAN) (InternalAsciiIsDecimalDigitCharacter (Char) ||\r | |
986 | (Char >= 'A' && Char <= 'F') ||\r | |
987 | (Char >= 'a' && Char <= 'f'));\r | |
988 | }\r | |
989 | \r | |
990 | /**\r | |
9aa049d9 | 991 | Convert a Null-terminated Unicode string to a Null-terminated\r |
e1f414b6 | 992 | ASCII string and returns the ASCII string.\r |
9aa049d9 | 993 | \r |
994 | This function converts the content of the Unicode string Source\r | |
995 | to the ASCII string Destination by copying the lower 8 bits of\r | |
996 | each Unicode character. It returns Destination.\r | |
997 | \r | |
998 | If any Unicode characters in Source contain non-zero value in\r | |
999 | the upper 8 bits, then ASSERT().\r | |
e1f414b6 | 1000 | \r |
1001 | If Destination is NULL, then ASSERT().\r | |
1002 | If Source is NULL, then ASSERT().\r | |
1003 | If Source is not aligned on a 16-bit boundary, then ASSERT().\r | |
1004 | If Source and Destination overlap, then ASSERT().\r | |
1005 | \r | |
9aa049d9 | 1006 | If PcdMaximumUnicodeStringLength is not zero, and Source contains\r |
dfbe9de9 | 1007 | more than PcdMaximumUnicodeStringLength Unicode characters, not including\r |
e1f414b6 | 1008 | the Null-terminator, then ASSERT().\r |
9aa049d9 | 1009 | \r |
1010 | If PcdMaximumAsciiStringLength is not zero, and Source contains more\r | |
dfbe9de9 | 1011 | than PcdMaximumAsciiStringLength Unicode characters, not including the\r |
e1f414b6 | 1012 | Null-terminator, then ASSERT().\r |
1013 | \r | |
127010dd | 1014 | @param Source A pointer to a Null-terminated Unicode string.\r |
1015 | @param Destination A pointer to a Null-terminated ASCII string.\r | |
e1f414b6 | 1016 | \r |
9aa049d9 | 1017 | @return Destination.\r |
e1f414b6 | 1018 | \r |
1019 | **/\r | |
1020 | CHAR8 *\r | |
1021 | EFIAPI\r | |
1022 | UnicodeStrToAsciiStr (\r | |
2fc60b70 | 1023 | IN CONST CHAR16 *Source,\r |
1024 | OUT CHAR8 *Destination\r | |
e1f414b6 | 1025 | )\r |
1026 | {\r | |
4df26661 | 1027 | CHAR8 *ReturnValue;\r |
1028 | \r | |
e1f414b6 | 1029 | ASSERT (Destination != NULL);\r |
4df26661 | 1030 | \r |
1031 | //\r | |
1032 | // ASSERT if Source is long than PcdMaximumUnicodeStringLength.\r | |
1033 | // Length tests are performed inside StrLen().\r | |
1034 | //\r | |
1035 | ASSERT (StrSize (Source) != 0);\r | |
e1f414b6 | 1036 | \r |
1037 | //\r | |
1038 | // Source and Destination should not overlap\r | |
1039 | //\r | |
1040 | ASSERT ((UINTN) ((CHAR16 *) Destination - Source) > StrLen (Source));\r | |
1041 | ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > StrLen (Source));\r | |
1042 | \r | |
e1f414b6 | 1043 | \r |
4df26661 | 1044 | ReturnValue = Destination;\r |
e1f414b6 | 1045 | while (*Source != '\0') {\r |
1046 | //\r | |
1047 | // If any Unicode characters in Source contain \r | |
1048 | // non-zero value in the upper 8 bits, then ASSERT().\r | |
1049 | //\r | |
1050 | ASSERT (*Source < 0x100);\r | |
1051 | *(Destination++) = (CHAR8) *(Source++);\r | |
1052 | }\r | |
1053 | \r | |
1054 | *Destination = '\0';\r | |
4df26661 | 1055 | \r |
1056 | //\r | |
1057 | // ASSERT Original Destination is less long than PcdMaximumAsciiStringLength.\r | |
1058 | // Length tests are performed inside AsciiStrLen().\r | |
1059 | //\r | |
1060 | ASSERT (AsciiStrSize (ReturnValue) != 0);\r | |
1061 | \r | |
1062 | return ReturnValue;\r | |
e1f414b6 | 1063 | }\r |
1064 | \r | |
1065 | \r | |
1066 | /**\r | |
1067 | Copies one Null-terminated ASCII string to another Null-terminated ASCII\r | |
1068 | string and returns the new ASCII string.\r | |
1069 | \r | |
1070 | This function copies the contents of the ASCII string Source to the ASCII\r | |
1071 | string Destination, and returns Destination. If Source and Destination\r | |
1072 | overlap, then the results are undefined.\r | |
1073 | \r | |
1074 | If Destination is NULL, then ASSERT().\r | |
1075 | If Source is NULL, then ASSERT().\r | |
1076 | If Source and Destination overlap, then ASSERT().\r | |
1077 | If PcdMaximumAsciiStringLength is not zero and Source contains more than\r | |
dfbe9de9 | 1078 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1079 | then ASSERT().\r |
1080 | \r | |
127010dd | 1081 | @param Destination A pointer to a Null-terminated ASCII string.\r |
1082 | @param Source A pointer to a Null-terminated ASCII string.\r | |
e1f414b6 | 1083 | \r |
9aa049d9 | 1084 | @return Destination\r |
e1f414b6 | 1085 | \r |
1086 | **/\r | |
1087 | CHAR8 *\r | |
1088 | EFIAPI\r | |
1089 | AsciiStrCpy (\r | |
1090 | OUT CHAR8 *Destination,\r | |
1091 | IN CONST CHAR8 *Source\r | |
1092 | )\r | |
1093 | {\r | |
1094 | CHAR8 *ReturnValue;\r | |
1095 | \r | |
1096 | //\r | |
1097 | // Destination cannot be NULL\r | |
1098 | //\r | |
1099 | ASSERT (Destination != NULL);\r | |
1100 | \r | |
1101 | //\r | |
1102 | // Destination and source cannot overlap\r | |
1103 | //\r | |
1104 | ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));\r | |
1105 | ASSERT ((UINTN)(Source - Destination) > AsciiStrLen (Source));\r | |
1106 | \r | |
1107 | ReturnValue = Destination;\r | |
42eedea9 | 1108 | while (*Source != 0) {\r |
e1f414b6 | 1109 | *(Destination++) = *(Source++);\r |
1110 | }\r | |
1111 | *Destination = 0;\r | |
1112 | return ReturnValue;\r | |
1113 | }\r | |
1114 | \r | |
1115 | /**\r | |
9aa049d9 | 1116 | Copies up to a specified length one Null-terminated ASCII string to another \r |
1117 | Null-terminated ASCII string and returns the new ASCII string.\r | |
e1f414b6 | 1118 | \r |
1119 | This function copies the contents of the ASCII string Source to the ASCII\r | |
1120 | string Destination, and returns Destination. At most, Length ASCII characters\r | |
1121 | are copied from Source to Destination. If Length is 0, then Destination is\r | |
1122 | returned unmodified. If Length is greater that the number of ASCII characters\r | |
1123 | in Source, then Destination is padded with Null ASCII characters. If Source\r | |
1124 | and Destination overlap, then the results are undefined.\r | |
1125 | \r | |
1126 | If Destination is NULL, then ASSERT().\r | |
1127 | If Source is NULL, then ASSERT().\r | |
1128 | If Source and Destination overlap, then ASSERT().\r | |
53e96610 | 1129 | If PcdMaximumAsciiStringLength is not zero, and Length is greater than \r |
1130 | PcdMaximumAsciiStringLength, then ASSERT().\r | |
e1f414b6 | 1131 | If PcdMaximumAsciiStringLength is not zero, and Source contains more than\r |
dfbe9de9 | 1132 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
53e96610 | 1133 | then ASSERT().\r |
e1f414b6 | 1134 | \r |
127010dd | 1135 | @param Destination A pointer to a Null-terminated ASCII string.\r |
1136 | @param Source A pointer to a Null-terminated ASCII string.\r | |
2fc59a00 | 1137 | @param Length The maximum number of ASCII characters to copy.\r |
e1f414b6 | 1138 | \r |
9aa049d9 | 1139 | @return Destination\r |
e1f414b6 | 1140 | \r |
1141 | **/\r | |
1142 | CHAR8 *\r | |
1143 | EFIAPI\r | |
1144 | AsciiStrnCpy (\r | |
1145 | OUT CHAR8 *Destination,\r | |
1146 | IN CONST CHAR8 *Source,\r | |
1147 | IN UINTN Length\r | |
1148 | )\r | |
1149 | {\r | |
1150 | CHAR8 *ReturnValue;\r | |
1151 | \r | |
2bfb6009 | 1152 | if (Length == 0) {\r |
e1f414b6 | 1153 | return Destination;\r |
1154 | }\r | |
1155 | \r | |
1156 | //\r | |
1157 | // Destination cannot be NULL\r | |
1158 | //\r | |
1159 | ASSERT (Destination != NULL);\r | |
1160 | \r | |
1161 | //\r | |
1162 | // Destination and source cannot overlap\r | |
1163 | //\r | |
1164 | ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));\r | |
1165 | ASSERT ((UINTN)(Source - Destination) >= Length);\r | |
1166 | \r | |
dfbe9de9 | 1167 | if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {\r |
1168 | ASSERT (Length <= PcdGet32 (PcdMaximumAsciiStringLength));\r | |
1169 | }\r | |
1170 | \r | |
e1f414b6 | 1171 | ReturnValue = Destination;\r |
1172 | \r | |
42eedea9 | 1173 | while (*Source != 0 && Length > 0) {\r |
e1f414b6 | 1174 | *(Destination++) = *(Source++);\r |
1175 | Length--;\r | |
1176 | }\r | |
1177 | \r | |
1178 | ZeroMem (Destination, Length * sizeof (*Destination));\r | |
1179 | return ReturnValue;\r | |
1180 | }\r | |
1181 | \r | |
1182 | /**\r | |
1183 | Returns the length of a Null-terminated ASCII string.\r | |
1184 | \r | |
1185 | This function returns the number of ASCII characters in the Null-terminated\r | |
1186 | ASCII string specified by String.\r | |
1187 | \r | |
9aa049d9 | 1188 | If Length > 0 and Destination is NULL, then ASSERT().\r |
1189 | If Length > 0 and Source is NULL, then ASSERT().\r | |
e1f414b6 | 1190 | If PcdMaximumAsciiStringLength is not zero and String contains more than\r |
dfbe9de9 | 1191 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1192 | then ASSERT().\r |
1193 | \r | |
127010dd | 1194 | @param String A pointer to a Null-terminated ASCII string.\r |
e1f414b6 | 1195 | \r |
1196 | @return The length of String.\r | |
1197 | \r | |
1198 | **/\r | |
1199 | UINTN\r | |
1200 | EFIAPI\r | |
1201 | AsciiStrLen (\r | |
1202 | IN CONST CHAR8 *String\r | |
1203 | )\r | |
1204 | {\r | |
1205 | UINTN Length;\r | |
1206 | \r | |
1207 | ASSERT (String != NULL);\r | |
1208 | \r | |
1209 | for (Length = 0; *String != '\0'; String++, Length++) {\r | |
1210 | //\r | |
1211 | // If PcdMaximumUnicodeStringLength is not zero,\r | |
1212 | // length should not more than PcdMaximumUnicodeStringLength\r | |
1213 | //\r | |
1214 | if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {\r | |
1215 | ASSERT (Length < PcdGet32 (PcdMaximumAsciiStringLength));\r | |
1216 | }\r | |
1217 | }\r | |
1218 | return Length;\r | |
1219 | }\r | |
1220 | \r | |
1221 | /**\r | |
1222 | Returns the size of a Null-terminated ASCII string in bytes, including the\r | |
1223 | Null terminator.\r | |
1224 | \r | |
1225 | This function returns the size, in bytes, of the Null-terminated ASCII string\r | |
1226 | specified by String.\r | |
1227 | \r | |
1228 | If String is NULL, then ASSERT().\r | |
1229 | If PcdMaximumAsciiStringLength is not zero and String contains more than\r | |
dfbe9de9 | 1230 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1231 | then ASSERT().\r |
1232 | \r | |
127010dd | 1233 | @param String A pointer to a Null-terminated ASCII string.\r |
e1f414b6 | 1234 | \r |
1235 | @return The size of String.\r | |
1236 | \r | |
1237 | **/\r | |
1238 | UINTN\r | |
1239 | EFIAPI\r | |
1240 | AsciiStrSize (\r | |
1241 | IN CONST CHAR8 *String\r | |
1242 | )\r | |
1243 | {\r | |
1244 | return (AsciiStrLen (String) + 1) * sizeof (*String);\r | |
1245 | }\r | |
1246 | \r | |
1247 | /**\r | |
1248 | Compares two Null-terminated ASCII strings, and returns the difference\r | |
1249 | between the first mismatched ASCII characters.\r | |
1250 | \r | |
1251 | This function compares the Null-terminated ASCII string FirstString to the\r | |
1252 | Null-terminated ASCII string SecondString. If FirstString is identical to\r | |
1253 | SecondString, then 0 is returned. Otherwise, the value returned is the first\r | |
1254 | mismatched ASCII character in SecondString subtracted from the first\r | |
1255 | mismatched ASCII character in FirstString.\r | |
1256 | \r | |
1257 | If FirstString is NULL, then ASSERT().\r | |
1258 | If SecondString is NULL, then ASSERT().\r | |
1259 | If PcdMaximumAsciiStringLength is not zero and FirstString contains more than\r | |
dfbe9de9 | 1260 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1261 | then ASSERT().\r |
1262 | If PcdMaximumAsciiStringLength is not zero and SecondString contains more\r | |
dfbe9de9 | 1263 | than PcdMaximumAsciiStringLength ASCII characters, not including the\r |
e1f414b6 | 1264 | Null-terminator, then ASSERT().\r |
1265 | \r | |
127010dd | 1266 | @param FirstString A pointer to a Null-terminated ASCII string.\r |
1267 | @param SecondString A pointer to a Null-terminated ASCII string.\r | |
e1f414b6 | 1268 | \r |
9aa049d9 | 1269 | @retval ==0 FirstString is identical to SecondString.\r |
1270 | @retval !=0 FirstString is not identical to SecondString.\r | |
e1f414b6 | 1271 | \r |
1272 | **/\r | |
1273 | INTN\r | |
1274 | EFIAPI\r | |
1275 | AsciiStrCmp (\r | |
1276 | IN CONST CHAR8 *FirstString,\r | |
1277 | IN CONST CHAR8 *SecondString\r | |
1278 | )\r | |
1279 | {\r | |
1280 | //\r | |
1281 | // ASSERT both strings are less long than PcdMaximumAsciiStringLength\r | |
1282 | //\r | |
1283 | ASSERT (AsciiStrSize (FirstString));\r | |
1284 | ASSERT (AsciiStrSize (SecondString));\r | |
1285 | \r | |
1286 | while ((*FirstString != '\0') && (*FirstString == *SecondString)) {\r | |
1287 | FirstString++;\r | |
1288 | SecondString++;\r | |
1289 | }\r | |
1290 | \r | |
1291 | return *FirstString - *SecondString;\r | |
1292 | }\r | |
1293 | \r | |
1294 | /**\r | |
24dcb5e5 | 1295 | Converts a lowercase Ascii character to upper one.\r |
e1f414b6 | 1296 | \r |
1297 | If Chr is lowercase Ascii character, then converts it to upper one.\r | |
1298 | \r | |
1299 | If Value >= 0xA0, then ASSERT().\r | |
1300 | If (Value & 0x0F) >= 0x0A, then ASSERT().\r | |
1301 | \r | |
42eedea9 | 1302 | @param Chr one Ascii character\r |
e1f414b6 | 1303 | \r |
1304 | @return The uppercase value of Ascii character \r | |
1305 | \r | |
1306 | **/\r | |
e1f414b6 | 1307 | CHAR8\r |
42eedea9 | 1308 | EFIAPI\r |
80151e53 | 1309 | InternalBaseLibAsciiToUpper (\r |
e1f414b6 | 1310 | IN CHAR8 Chr\r |
1311 | )\r | |
1312 | {\r | |
1313 | return (UINT8) ((Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr);\r | |
1314 | }\r | |
1315 | \r | |
1316 | /**\r | |
1317 | Convert a ASCII character to numerical value.\r | |
1318 | \r | |
1319 | This internal function only deal with Unicode character\r | |
1320 | which maps to a valid hexadecimal ASII character, i.e.\r | |
1321 | '0' to '9', 'a' to 'f' or 'A' to 'F'. For other \r | |
1322 | ASCII character, the value returned does not make sense.\r | |
1323 | \r | |
1324 | @param Char The character to convert.\r | |
1325 | \r | |
24dcb5e5 | 1326 | @return The numerical value converted.\r |
e1f414b6 | 1327 | \r |
1328 | **/\r | |
e1f414b6 | 1329 | UINTN\r |
42eedea9 | 1330 | EFIAPI\r |
e1f414b6 | 1331 | InternalAsciiHexCharToUintn (\r |
1332 | IN CHAR8 Char\r | |
1333 | )\r | |
1334 | {\r | |
1335 | if (InternalIsDecimalDigitCharacter (Char)) {\r | |
1336 | return Char - '0';\r | |
1337 | }\r | |
1338 | \r | |
80151e53 | 1339 | return (UINTN) (10 + InternalBaseLibAsciiToUpper (Char) - 'A');\r |
e1f414b6 | 1340 | }\r |
1341 | \r | |
1342 | \r | |
1343 | /**\r | |
1344 | Performs a case insensitive comparison of two Null-terminated ASCII strings,\r | |
1345 | and returns the difference between the first mismatched ASCII characters.\r | |
1346 | \r | |
1347 | This function performs a case insensitive comparison of the Null-terminated\r | |
1348 | ASCII string FirstString to the Null-terminated ASCII string SecondString. If\r | |
1349 | FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r | |
1350 | value returned is the first mismatched lower case ASCII character in\r | |
1351 | SecondString subtracted from the first mismatched lower case ASCII character\r | |
1352 | in FirstString.\r | |
1353 | \r | |
1354 | If FirstString is NULL, then ASSERT().\r | |
1355 | If SecondString is NULL, then ASSERT().\r | |
1356 | If PcdMaximumAsciiStringLength is not zero and FirstString contains more than\r | |
dfbe9de9 | 1357 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1358 | then ASSERT().\r |
1359 | If PcdMaximumAsciiStringLength is not zero and SecondString contains more\r | |
dfbe9de9 | 1360 | than PcdMaximumAsciiStringLength ASCII characters, not including the\r |
e1f414b6 | 1361 | Null-terminator, then ASSERT().\r |
1362 | \r | |
127010dd | 1363 | @param FirstString A pointer to a Null-terminated ASCII string.\r |
1364 | @param SecondString A pointer to a Null-terminated ASCII string.\r | |
e1f414b6 | 1365 | \r |
9aa049d9 | 1366 | @retval ==0 FirstString is identical to SecondString using case insensitive\r |
1106ffe1 | 1367 | comparisons.\r |
9aa049d9 | 1368 | @retval !=0 FirstString is not identical to SecondString using case\r |
1369 | insensitive comparisons.\r | |
e1f414b6 | 1370 | \r |
1371 | **/\r | |
1372 | INTN\r | |
1373 | EFIAPI\r | |
1374 | AsciiStriCmp (\r | |
1375 | IN CONST CHAR8 *FirstString,\r | |
1376 | IN CONST CHAR8 *SecondString\r | |
1377 | )\r | |
1378 | {\r | |
1379 | CHAR8 UpperFirstString;\r | |
1380 | CHAR8 UpperSecondString;\r | |
1381 | \r | |
1382 | //\r | |
1383 | // ASSERT both strings are less long than PcdMaximumAsciiStringLength\r | |
1384 | //\r | |
1385 | ASSERT (AsciiStrSize (FirstString));\r | |
1386 | ASSERT (AsciiStrSize (SecondString));\r | |
1387 | \r | |
80151e53 LG |
1388 | UpperFirstString = InternalBaseLibAsciiToUpper (*FirstString);\r |
1389 | UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);\r | |
e1f414b6 | 1390 | while ((*FirstString != '\0') && (UpperFirstString == UpperSecondString)) {\r |
1391 | FirstString++;\r | |
1392 | SecondString++;\r | |
80151e53 LG |
1393 | UpperFirstString = InternalBaseLibAsciiToUpper (*FirstString);\r |
1394 | UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);\r | |
e1f414b6 | 1395 | }\r |
1396 | \r | |
1397 | return UpperFirstString - UpperSecondString;\r | |
1398 | }\r | |
1399 | \r | |
1400 | /**\r | |
1401 | Compares two Null-terminated ASCII strings with maximum lengths, and returns\r | |
1402 | the difference between the first mismatched ASCII characters.\r | |
1403 | \r | |
1404 | This function compares the Null-terminated ASCII string FirstString to the\r | |
1405 | Null-terminated ASCII string SecondString. At most, Length ASCII characters\r | |
1406 | will be compared. If Length is 0, then 0 is returned. If FirstString is\r | |
1407 | identical to SecondString, then 0 is returned. Otherwise, the value returned\r | |
1408 | is the first mismatched ASCII character in SecondString subtracted from the\r | |
1409 | first mismatched ASCII character in FirstString.\r | |
1410 | \r | |
9aa049d9 | 1411 | If Length > 0 and FirstString is NULL, then ASSERT().\r |
1412 | If Length > 0 and SecondString is NULL, then ASSERT().\r | |
53e96610 | 1413 | If PcdMaximumAsciiStringLength is not zero, and Length is greater than \r |
1414 | PcdMaximumAsciiStringLength, then ASSERT().\r | |
1415 | If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than\r | |
dfbe9de9 | 1416 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1417 | then ASSERT().\r |
53e96610 | 1418 | If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than\r |
dfbe9de9 | 1419 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
53e96610 | 1420 | then ASSERT().\r |
e1f414b6 | 1421 | \r |
127010dd | 1422 | @param FirstString A pointer to a Null-terminated ASCII string.\r |
1423 | @param SecondString A pointer to a Null-terminated ASCII string.\r | |
2fc59a00 | 1424 | @param Length The maximum number of ASCII characters for compare.\r |
2fc60b70 | 1425 | \r |
9aa049d9 | 1426 | @retval ==0 FirstString is identical to SecondString.\r |
1427 | @retval !=0 FirstString is not identical to SecondString.\r | |
e1f414b6 | 1428 | \r |
1429 | **/\r | |
1430 | INTN\r | |
1431 | EFIAPI\r | |
1432 | AsciiStrnCmp (\r | |
1433 | IN CONST CHAR8 *FirstString,\r | |
1434 | IN CONST CHAR8 *SecondString,\r | |
1435 | IN UINTN Length\r | |
1436 | )\r | |
1437 | {\r | |
2bfb6009 | 1438 | if (Length == 0) {\r |
e1f414b6 | 1439 | return 0;\r |
1440 | }\r | |
1441 | \r | |
1442 | //\r | |
1443 | // ASSERT both strings are less long than PcdMaximumAsciiStringLength\r | |
1444 | //\r | |
1445 | ASSERT (AsciiStrSize (FirstString));\r | |
1446 | ASSERT (AsciiStrSize (SecondString));\r | |
1447 | \r | |
dfbe9de9 | 1448 | if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {\r |
1449 | ASSERT (Length <= PcdGet32 (PcdMaximumAsciiStringLength));\r | |
1450 | }\r | |
1451 | \r | |
e1f414b6 | 1452 | while ((*FirstString != '\0') &&\r |
1453 | (*FirstString == *SecondString) &&\r | |
1454 | (Length > 1)) {\r | |
1455 | FirstString++;\r | |
1456 | SecondString++;\r | |
1457 | Length--;\r | |
1458 | }\r | |
1459 | return *FirstString - *SecondString;\r | |
1460 | }\r | |
1461 | \r | |
1462 | /**\r | |
1463 | Concatenates one Null-terminated ASCII string to another Null-terminated\r | |
1464 | ASCII string, and returns the concatenated ASCII string.\r | |
1465 | \r | |
1466 | This function concatenates two Null-terminated ASCII strings. The contents of\r | |
1467 | Null-terminated ASCII string Source are concatenated to the end of Null-\r | |
1468 | terminated ASCII string Destination. The Null-terminated concatenated ASCII\r | |
1469 | String is returned.\r | |
1470 | \r | |
1471 | If Destination is NULL, then ASSERT().\r | |
1472 | If Source is NULL, then ASSERT().\r | |
1473 | If PcdMaximumAsciiStringLength is not zero and Destination contains more than\r | |
dfbe9de9 | 1474 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1475 | then ASSERT().\r |
1476 | If PcdMaximumAsciiStringLength is not zero and Source contains more than\r | |
dfbe9de9 | 1477 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1478 | then ASSERT().\r |
1479 | If PcdMaximumAsciiStringLength is not zero and concatenating Destination and\r | |
1480 | Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r | |
1481 | ASCII characters, then ASSERT().\r | |
1482 | \r | |
127010dd | 1483 | @param Destination A pointer to a Null-terminated ASCII string.\r |
1484 | @param Source A pointer to a Null-terminated ASCII string.\r | |
e1f414b6 | 1485 | \r |
9aa049d9 | 1486 | @return Destination\r |
e1f414b6 | 1487 | \r |
1488 | **/\r | |
1489 | CHAR8 *\r | |
1490 | EFIAPI\r | |
1491 | AsciiStrCat (\r | |
1492 | IN OUT CHAR8 *Destination,\r | |
1493 | IN CONST CHAR8 *Source\r | |
1494 | )\r | |
1495 | {\r | |
1496 | AsciiStrCpy (Destination + AsciiStrLen (Destination), Source);\r | |
1497 | \r | |
1498 | //\r | |
1499 | // Size of the resulting string should never be zero.\r | |
1500 | // PcdMaximumUnicodeStringLength is tested inside StrLen().\r | |
1501 | //\r | |
1502 | ASSERT (AsciiStrSize (Destination) != 0);\r | |
1503 | return Destination;\r | |
1504 | }\r | |
1505 | \r | |
1506 | /**\r | |
9aa049d9 | 1507 | Concatenates up to a specified length one Null-terminated ASCII string to \r |
1508 | the end of another Null-terminated ASCII string, and returns the \r | |
1509 | concatenated ASCII string.\r | |
e1f414b6 | 1510 | \r |
1511 | This function concatenates two Null-terminated ASCII strings. The contents\r | |
1512 | of Null-terminated ASCII string Source are concatenated to the end of Null-\r | |
1513 | terminated ASCII string Destination, and Destination is returned. At most,\r | |
1514 | Length ASCII characters are concatenated from Source to the end of\r | |
1515 | Destination, and Destination is always Null-terminated. If Length is 0, then\r | |
1516 | Destination is returned unmodified. If Source and Destination overlap, then\r | |
1517 | the results are undefined.\r | |
1518 | \r | |
9aa049d9 | 1519 | If Length > 0 and Destination is NULL, then ASSERT().\r |
1520 | If Length > 0 and Source is NULL, then ASSERT().\r | |
e1f414b6 | 1521 | If Source and Destination overlap, then ASSERT().\r |
53e96610 | 1522 | If PcdMaximumAsciiStringLength is not zero, and Length is greater than\r |
1523 | PcdMaximumAsciiStringLength, then ASSERT().\r | |
e1f414b6 | 1524 | If PcdMaximumAsciiStringLength is not zero, and Destination contains more than\r |
dfbe9de9 | 1525 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1526 | then ASSERT().\r |
1527 | If PcdMaximumAsciiStringLength is not zero, and Source contains more than\r | |
dfbe9de9 | 1528 | PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r |
e1f414b6 | 1529 | then ASSERT().\r |
1530 | If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and\r | |
1531 | Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r | |
53e96610 | 1532 | ASCII characters, not including the Null-terminator, then ASSERT().\r |
e1f414b6 | 1533 | \r |
127010dd | 1534 | @param Destination A pointer to a Null-terminated ASCII string.\r |
1535 | @param Source A pointer to a Null-terminated ASCII string.\r | |
2fc59a00 | 1536 | @param Length The maximum number of ASCII characters to concatenate from\r |
e1f414b6 | 1537 | Source.\r |
1538 | \r | |
9aa049d9 | 1539 | @return Destination\r |
e1f414b6 | 1540 | \r |
1541 | **/\r | |
1542 | CHAR8 *\r | |
1543 | EFIAPI\r | |
1544 | AsciiStrnCat (\r | |
1545 | IN OUT CHAR8 *Destination,\r | |
1546 | IN CONST CHAR8 *Source,\r | |
1547 | IN UINTN Length\r | |
1548 | )\r | |
1549 | {\r | |
8f635c36 | 1550 | UINTN DestinationLen;\r |
1551 | \r | |
1552 | DestinationLen = AsciiStrLen (Destination);\r | |
1553 | AsciiStrnCpy (Destination + DestinationLen, Source, Length);\r | |
1554 | Destination[DestinationLen + Length] = '\0';\r | |
e1f414b6 | 1555 | \r |
1556 | //\r | |
1557 | // Size of the resulting string should never be zero.\r | |
1558 | // PcdMaximumUnicodeStringLength is tested inside StrLen().\r | |
1559 | //\r | |
1560 | ASSERT (AsciiStrSize (Destination) != 0);\r | |
1561 | return Destination;\r | |
1562 | }\r | |
1563 | \r | |
1564 | /**\r | |
9aa049d9 | 1565 | Returns the first occurrence of a Null-terminated ASCII sub-string\r |
e1f414b6 | 1566 | in a Null-terminated ASCII string.\r |
1567 | \r | |
9aa049d9 | 1568 | This function scans the contents of the ASCII string specified by String\r |
1569 | and returns the first occurrence of SearchString. If SearchString is not\r | |
1570 | found in String, then NULL is returned. If the length of SearchString is zero,\r | |
e1f414b6 | 1571 | then String is returned.\r |
9aa049d9 | 1572 | \r |
e1f414b6 | 1573 | If String is NULL, then ASSERT().\r |
1574 | If SearchString is NULL, then ASSERT().\r | |
1575 | \r | |
9aa049d9 | 1576 | If PcdMaximumAsciiStringLength is not zero, and SearchString or\r |
1577 | String contains more than PcdMaximumAsciiStringLength Unicode characters\r | |
e1f414b6 | 1578 | not including the Null-terminator, then ASSERT().\r |
1579 | \r | |
127010dd | 1580 | @param String A pointer to a Null-terminated ASCII string.\r |
1581 | @param SearchString A pointer to a Null-terminated ASCII string to search for.\r | |
e1f414b6 | 1582 | \r |
1583 | @retval NULL If the SearchString does not appear in String.\r | |
9aa049d9 | 1584 | @retval others If there is a match return the first occurrence of SearchingString.\r |
1585 | If the length of SearchString is zero,return String.\r | |
e1f414b6 | 1586 | \r |
1587 | **/\r | |
1588 | CHAR8 *\r | |
1589 | EFIAPI\r | |
1590 | AsciiStrStr (\r | |
2fc60b70 | 1591 | IN CONST CHAR8 *String,\r |
1592 | IN CONST CHAR8 *SearchString\r | |
e1f414b6 | 1593 | )\r |
1594 | {\r | |
1595 | CONST CHAR8 *FirstMatch;\r | |
1596 | CONST CHAR8 *SearchStringTmp;\r | |
1597 | \r | |
e1f414b6 | 1598 | //\r |
4df26661 | 1599 | // ASSERT both strings are less long than PcdMaximumAsciiStringLength\r |
e1f414b6 | 1600 | //\r |
4df26661 | 1601 | ASSERT (AsciiStrSize (String) != 0);\r |
1602 | ASSERT (AsciiStrSize (SearchString) != 0);\r | |
e1f414b6 | 1603 | \r |
62e71e2f | 1604 | if (*SearchString == '\0') {\r |
faeb3214 | 1605 | return (CHAR8 *) String;\r |
62e71e2f | 1606 | }\r |
1607 | \r | |
e1f414b6 | 1608 | while (*String != '\0') {\r |
1609 | SearchStringTmp = SearchString;\r | |
1610 | FirstMatch = String;\r | |
1611 | \r | |
1612 | while ((*String == *SearchStringTmp) \r | |
e1f414b6 | 1613 | && (*String != '\0')) {\r |
1614 | String++;\r | |
1615 | SearchStringTmp++;\r | |
1616 | } \r | |
1617 | \r | |
1618 | if (*SearchStringTmp == '\0') {\r | |
1619 | return (CHAR8 *) FirstMatch;\r | |
1620 | }\r | |
1621 | \r | |
62e71e2f | 1622 | if (*String == '\0') {\r |
1623 | return NULL;\r | |
e1f414b6 | 1624 | }\r |
1625 | \r | |
62e71e2f | 1626 | String = FirstMatch + 1;\r |
e1f414b6 | 1627 | }\r |
1628 | \r | |
1629 | return NULL;\r | |
1630 | }\r | |
1631 | \r | |
1632 | /**\r | |
9aa049d9 | 1633 | Convert a Null-terminated ASCII decimal string to a value of type\r |
e1f414b6 | 1634 | UINTN.\r |
1635 | \r | |
9aa049d9 | 1636 | This function returns a value of type UINTN by interpreting the contents\r |
1637 | of the ASCII string String as a decimal number. The format of the input\r | |
e1f414b6 | 1638 | ASCII string String is:\r |
9aa049d9 | 1639 | \r |
e1f414b6 | 1640 | [spaces] [decimal digits].\r |
9aa049d9 | 1641 | \r |
1642 | The valid decimal digit character is in the range [0-9]. The function will\r | |
1643 | ignore the pad space, which includes spaces or tab characters, before the digits.\r | |
1644 | The running zero in the beginning of [decimal digits] will be ignored. Then, the\r | |
1645 | function stops at the first character that is a not a valid decimal character or\r | |
e1f414b6 | 1646 | Null-terminator, whichever on comes first.\r |
9aa049d9 | 1647 | \r |
e1f414b6 | 1648 | If String has only pad spaces, then 0 is returned.\r |
1649 | If String has no pad spaces or valid decimal digits, then 0 is returned.\r | |
9aa049d9 | 1650 | If the number represented by String overflows according to the range defined by\r |
e1f414b6 | 1651 | UINTN, then ASSERT().\r |
1652 | If String is NULL, then ASSERT().\r | |
9aa049d9 | 1653 | If PcdMaximumAsciiStringLength is not zero, and String contains more than\r |
1654 | PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r | |
e1f414b6 | 1655 | then ASSERT().\r |
1656 | \r | |
127010dd | 1657 | @param String A pointer to a Null-terminated ASCII string.\r |
e1f414b6 | 1658 | \r |
9aa049d9 | 1659 | @retval Value translated from String.\r |
e1f414b6 | 1660 | \r |
1661 | **/\r | |
1662 | UINTN\r | |
1663 | EFIAPI\r | |
1664 | AsciiStrDecimalToUintn (\r | |
4df26661 | 1665 | IN CONST CHAR8 *String\r |
e1f414b6 | 1666 | )\r |
1667 | {\r | |
1668 | UINTN Result;\r | |
1669 | \r | |
4df26661 | 1670 | //\r |
1671 | // ASSERT Strings is less long than PcdMaximumAsciiStringLength\r | |
1672 | //\r | |
1673 | ASSERT (AsciiStrSize (String) != 0);\r | |
e1f414b6 | 1674 | \r |
1675 | //\r | |
1676 | // Ignore the pad spaces (space or tab)\r | |
1677 | //\r | |
955c32f2 | 1678 | while ((*String == ' ') || (*String == '\t' )) {\r |
e1f414b6 | 1679 | String++;\r |
1680 | }\r | |
1681 | \r | |
1682 | //\r | |
1683 | // Ignore leading Zeros after the spaces\r | |
1684 | //\r | |
955c32f2 | 1685 | while (*String == '0') {\r |
e1f414b6 | 1686 | String++;\r |
1687 | }\r | |
1688 | \r | |
1689 | Result = 0;\r | |
1690 | \r | |
1691 | while (InternalAsciiIsDecimalDigitCharacter (*String)) {\r | |
1692 | //\r | |
1693 | // If the number represented by String overflows according \r | |
1694 | // to the range defined by UINTN, then ASSERT().\r | |
1695 | //\r | |
6efe9461 | 1696 | ASSERT (Result <= ((((UINTN) ~0) - (*String - L'0')) / 10));\r |
e1f414b6 | 1697 | \r |
1698 | Result = Result * 10 + (*String - '0');\r | |
1699 | String++;\r | |
1700 | }\r | |
1701 | \r | |
1702 | return Result;\r | |
1703 | }\r | |
1704 | \r | |
1705 | \r | |
1706 | /**\r | |
9aa049d9 | 1707 | Convert a Null-terminated ASCII decimal string to a value of type\r |
e1f414b6 | 1708 | UINT64.\r |
1709 | \r | |
9aa049d9 | 1710 | This function returns a value of type UINT64 by interpreting the contents\r |
1711 | of the ASCII string String as a decimal number. The format of the input\r | |
e1f414b6 | 1712 | ASCII string String is:\r |
9aa049d9 | 1713 | \r |
e1f414b6 | 1714 | [spaces] [decimal digits].\r |
9aa049d9 | 1715 | \r |
1716 | The valid decimal digit character is in the range [0-9]. The function will\r | |
1717 | ignore the pad space, which includes spaces or tab characters, before the digits.\r | |
1718 | The running zero in the beginning of [decimal digits] will be ignored. Then, the\r | |
1719 | function stops at the first character that is a not a valid decimal character or\r | |
e1f414b6 | 1720 | Null-terminator, whichever on comes first.\r |
9aa049d9 | 1721 | \r |
e1f414b6 | 1722 | If String has only pad spaces, then 0 is returned.\r |
1723 | If String has no pad spaces or valid decimal digits, then 0 is returned.\r | |
9aa049d9 | 1724 | If the number represented by String overflows according to the range defined by\r |
e1f414b6 | 1725 | UINT64, then ASSERT().\r |
1726 | If String is NULL, then ASSERT().\r | |
9aa049d9 | 1727 | If PcdMaximumAsciiStringLength is not zero, and String contains more than\r |
1728 | PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r | |
e1f414b6 | 1729 | then ASSERT().\r |
1730 | \r | |
127010dd | 1731 | @param String A pointer to a Null-terminated ASCII string.\r |
e1f414b6 | 1732 | \r |
9aa049d9 | 1733 | @retval Value translated from String.\r |
e1f414b6 | 1734 | \r |
1735 | **/\r | |
1736 | UINT64\r | |
1737 | EFIAPI\r | |
1738 | AsciiStrDecimalToUint64 (\r | |
2fc60b70 | 1739 | IN CONST CHAR8 *String\r |
e1f414b6 | 1740 | )\r |
1741 | {\r | |
1742 | UINT64 Result;\r | |
1743 | \r | |
4df26661 | 1744 | //\r |
1745 | // ASSERT Strings is less long than PcdMaximumAsciiStringLength\r | |
1746 | //\r | |
1747 | ASSERT (AsciiStrSize (String) != 0);\r | |
e1f414b6 | 1748 | \r |
1749 | //\r | |
1750 | // Ignore the pad spaces (space or tab)\r | |
1751 | //\r | |
955c32f2 | 1752 | while ((*String == ' ') || (*String == '\t' )) {\r |
e1f414b6 | 1753 | String++;\r |
1754 | }\r | |
1755 | \r | |
1756 | //\r | |
1757 | // Ignore leading Zeros after the spaces\r | |
1758 | //\r | |
955c32f2 | 1759 | while (*String == '0') {\r |
e1f414b6 | 1760 | String++;\r |
1761 | }\r | |
1762 | \r | |
1763 | Result = 0;\r | |
1764 | \r | |
1765 | while (InternalAsciiIsDecimalDigitCharacter (*String)) {\r | |
1766 | //\r | |
1767 | // If the number represented by String overflows according \r | |
1768 | // to the range defined by UINTN, then ASSERT().\r | |
1769 | //\r | |
6efe9461 | 1770 | ASSERT (Result <= DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10));\r |
e1f414b6 | 1771 | \r |
1772 | Result = MultU64x32 (Result, 10) + (*String - '0');\r | |
1773 | String++;\r | |
1774 | }\r | |
1775 | \r | |
1776 | return Result;\r | |
1777 | }\r | |
1778 | \r | |
1779 | /**\r | |
1780 | Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.\r | |
1781 | \r | |
9aa049d9 | 1782 | This function returns a value of type UINTN by interpreting the contents of\r |
1783 | the ASCII string String as a hexadecimal number. The format of the input ASCII\r | |
e1f414b6 | 1784 | string String is:\r |
9aa049d9 | 1785 | \r |
e1f414b6 | 1786 | [spaces][zeros][x][hexadecimal digits].\r |
9aa049d9 | 1787 | \r |
1788 | The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r | |
1789 | The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"\r | |
1790 | appears in the input string, it must be prefixed with at least one 0. The function\r | |
1791 | will ignore the pad space, which includes spaces or tab characters, before [zeros],\r | |
1792 | [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]\r | |
1793 | will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal\r | |
1794 | digit. Then, the function stops at the first character that is a not a valid\r | |
e1f414b6 | 1795 | hexadecimal character or Null-terminator, whichever on comes first.\r |
9aa049d9 | 1796 | \r |
e1f414b6 | 1797 | If String has only pad spaces, then 0 is returned.\r |
1798 | If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then\r | |
1799 | 0 is returned.\r | |
1800 | \r | |
9aa049d9 | 1801 | If the number represented by String overflows according to the range defined by UINTN,\r |
e1f414b6 | 1802 | then ASSERT().\r |
1803 | If String is NULL, then ASSERT().\r | |
9aa049d9 | 1804 | If PcdMaximumAsciiStringLength is not zero,\r |
1805 | and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r | |
e1f414b6 | 1806 | the Null-terminator, then ASSERT().\r |
1807 | \r | |
127010dd | 1808 | @param String A pointer to a Null-terminated ASCII string.\r |
e1f414b6 | 1809 | \r |
9aa049d9 | 1810 | @retval Value translated from String.\r |
e1f414b6 | 1811 | \r |
1812 | **/\r | |
1813 | UINTN\r | |
1814 | EFIAPI\r | |
1815 | AsciiStrHexToUintn (\r | |
2fc60b70 | 1816 | IN CONST CHAR8 *String\r |
e1f414b6 | 1817 | )\r |
1818 | {\r | |
1819 | UINTN Result;\r | |
1820 | \r | |
4df26661 | 1821 | //\r |
1822 | // ASSERT Strings is less long than PcdMaximumAsciiStringLength\r | |
1823 | //\r | |
1824 | ASSERT (AsciiStrSize (String) != 0);\r | |
e1f414b6 | 1825 | \r |
1826 | //\r | |
1827 | // Ignore the pad spaces (space or tab) \r | |
1828 | //\r | |
955c32f2 | 1829 | while ((*String == ' ') || (*String == '\t' )) {\r |
e1f414b6 | 1830 | String++;\r |
1831 | }\r | |
1832 | \r | |
1833 | //\r | |
1834 | // Ignore leading Zeros after the spaces\r | |
1835 | //\r | |
955c32f2 | 1836 | while (*String == '0') {\r |
e1f414b6 | 1837 | String++;\r |
1838 | }\r | |
1839 | \r | |
80151e53 | 1840 | if (InternalBaseLibAsciiToUpper (*String) == 'X') {\r |
955c32f2 | 1841 | ASSERT (*(String - 1) == '0');\r |
1842 | if (*(String - 1) != '0') {\r | |
e1f414b6 | 1843 | return 0;\r |
1844 | }\r | |
1845 | //\r | |
1846 | // Skip the 'X'\r | |
1847 | //\r | |
1848 | String++;\r | |
1849 | }\r | |
1850 | \r | |
1851 | Result = 0;\r | |
1852 | \r | |
1853 | while (InternalAsciiIsHexaDecimalDigitCharacter (*String)) {\r | |
1854 | //\r | |
1855 | // If the Hex Number represented by String overflows according \r | |
1856 | // to the range defined by UINTN, then ASSERT().\r | |
1857 | //\r | |
6efe9461 | 1858 | ASSERT (Result <= ((((UINTN) ~0) - InternalHexCharToUintn (*String)) >> 4));\r |
e1f414b6 | 1859 | \r |
1860 | Result = (Result << 4) + InternalAsciiHexCharToUintn (*String);\r | |
1861 | String++;\r | |
1862 | }\r | |
1863 | \r | |
1864 | return Result;\r | |
1865 | }\r | |
1866 | \r | |
1867 | \r | |
1868 | /**\r | |
1869 | Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.\r | |
1870 | \r | |
9aa049d9 | 1871 | This function returns a value of type UINT64 by interpreting the contents of\r |
1872 | the ASCII string String as a hexadecimal number. The format of the input ASCII\r | |
e1f414b6 | 1873 | string String is:\r |
9aa049d9 | 1874 | \r |
e1f414b6 | 1875 | [spaces][zeros][x][hexadecimal digits].\r |
9aa049d9 | 1876 | \r |
1877 | The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r | |
1878 | The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"\r | |
1879 | appears in the input string, it must be prefixed with at least one 0. The function\r | |
1880 | will ignore the pad space, which includes spaces or tab characters, before [zeros],\r | |
1881 | [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]\r | |
1882 | will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal\r | |
1883 | digit. Then, the function stops at the first character that is a not a valid\r | |
e1f414b6 | 1884 | hexadecimal character or Null-terminator, whichever on comes first.\r |
9aa049d9 | 1885 | \r |
e1f414b6 | 1886 | If String has only pad spaces, then 0 is returned.\r |
1887 | If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then\r | |
1888 | 0 is returned.\r | |
1889 | \r | |
9aa049d9 | 1890 | If the number represented by String overflows according to the range defined by UINT64,\r |
e1f414b6 | 1891 | then ASSERT().\r |
1892 | If String is NULL, then ASSERT().\r | |
9aa049d9 | 1893 | If PcdMaximumAsciiStringLength is not zero,\r |
1894 | and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r | |
e1f414b6 | 1895 | the Null-terminator, then ASSERT().\r |
1896 | \r | |
127010dd | 1897 | @param String A pointer to a Null-terminated ASCII string.\r |
e1f414b6 | 1898 | \r |
9aa049d9 | 1899 | @retval Value translated from String.\r |
e1f414b6 | 1900 | \r |
1901 | **/\r | |
1902 | UINT64\r | |
1903 | EFIAPI\r | |
1904 | AsciiStrHexToUint64 (\r | |
2fc60b70 | 1905 | IN CONST CHAR8 *String\r |
e1f414b6 | 1906 | )\r |
1907 | {\r | |
1908 | UINT64 Result;\r | |
1909 | \r | |
4df26661 | 1910 | //\r |
1911 | // ASSERT Strings is less long than PcdMaximumAsciiStringLength\r | |
1912 | //\r | |
1913 | ASSERT (AsciiStrSize (String) != 0);\r | |
e1f414b6 | 1914 | \r |
1915 | //\r | |
1916 | // Ignore the pad spaces (space or tab) and leading Zeros\r | |
1917 | //\r | |
1918 | //\r | |
1919 | // Ignore the pad spaces (space or tab) \r | |
1920 | //\r | |
955c32f2 | 1921 | while ((*String == ' ') || (*String == '\t' )) {\r |
e1f414b6 | 1922 | String++;\r |
1923 | }\r | |
1924 | \r | |
1925 | //\r | |
1926 | // Ignore leading Zeros after the spaces\r | |
1927 | //\r | |
955c32f2 | 1928 | while (*String == '0') {\r |
e1f414b6 | 1929 | String++;\r |
1930 | }\r | |
1931 | \r | |
80151e53 | 1932 | if (InternalBaseLibAsciiToUpper (*String) == 'X') {\r |
955c32f2 | 1933 | ASSERT (*(String - 1) == '0');\r |
1934 | if (*(String - 1) != '0') {\r | |
e1f414b6 | 1935 | return 0;\r |
1936 | }\r | |
1937 | //\r | |
1938 | // Skip the 'X'\r | |
1939 | //\r | |
1940 | String++;\r | |
1941 | }\r | |
1942 | \r | |
1943 | Result = 0;\r | |
1944 | \r | |
1945 | while (InternalAsciiIsHexaDecimalDigitCharacter (*String)) {\r | |
1946 | //\r | |
1947 | // If the Hex Number represented by String overflows according \r | |
1948 | // to the range defined by UINTN, then ASSERT().\r | |
1949 | //\r | |
6efe9461 | 1950 | ASSERT (Result <= RShiftU64 (((UINT64) ~0) - InternalHexCharToUintn (*String) , 4));\r |
e1f414b6 | 1951 | \r |
1952 | Result = LShiftU64 (Result, 4);\r | |
1953 | Result = Result + InternalAsciiHexCharToUintn (*String);\r | |
1954 | String++;\r | |
1955 | }\r | |
1956 | \r | |
1957 | return Result;\r | |
1958 | }\r | |
1959 | \r | |
1960 | \r | |
1961 | /**\r | |
9aa049d9 | 1962 | Convert one Null-terminated ASCII string to a Null-terminated\r |
e1f414b6 | 1963 | Unicode string and returns the Unicode string.\r |
1964 | \r | |
9aa049d9 | 1965 | This function converts the contents of the ASCII string Source to the Unicode\r |
1966 | string Destination, and returns Destination. The function terminates the\r | |
1967 | Unicode string Destination by appending a Null-terminator character at the end.\r | |
1968 | The caller is responsible to make sure Destination points to a buffer with size\r | |
e1f414b6 | 1969 | equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.\r |
9aa049d9 | 1970 | \r |
e1f414b6 | 1971 | If Destination is NULL, then ASSERT().\r |
1972 | If Destination is not aligned on a 16-bit boundary, then ASSERT().\r | |
1973 | If Source is NULL, then ASSERT().\r | |
1974 | If Source and Destination overlap, then ASSERT().\r | |
9aa049d9 | 1975 | If PcdMaximumAsciiStringLength is not zero, and Source contains more than\r |
1976 | PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r | |
e1f414b6 | 1977 | then ASSERT().\r |
9aa049d9 | 1978 | If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r |
1979 | PcdMaximumUnicodeStringLength ASCII characters not including the\r | |
e1f414b6 | 1980 | Null-terminator, then ASSERT().\r |
1981 | \r | |
127010dd | 1982 | @param Source A pointer to a Null-terminated ASCII string.\r |
1983 | @param Destination A pointer to a Null-terminated Unicode string.\r | |
e1f414b6 | 1984 | \r |
9aa049d9 | 1985 | @return Destination.\r |
e1f414b6 | 1986 | \r |
1987 | **/\r | |
1988 | CHAR16 *\r | |
1989 | EFIAPI\r | |
1990 | AsciiStrToUnicodeStr (\r | |
4df26661 | 1991 | IN CONST CHAR8 *Source,\r |
1992 | OUT CHAR16 *Destination\r | |
e1f414b6 | 1993 | )\r |
1994 | {\r | |
4df26661 | 1995 | CHAR16 *ReturnValue;\r |
1996 | \r | |
e1f414b6 | 1997 | ASSERT (Destination != NULL);\r |
e1f414b6 | 1998 | \r |
1999 | //\r | |
4df26661 | 2000 | // ASSERT Source is less long than PcdMaximumAsciiStringLength\r |
e1f414b6 | 2001 | //\r |
4df26661 | 2002 | ASSERT (AsciiStrSize (Source) != 0);\r |
e1f414b6 | 2003 | \r |
2004 | //\r | |
4df26661 | 2005 | // Source and Destination should not overlap\r |
e1f414b6 | 2006 | //\r |
4df26661 | 2007 | ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));\r |
2008 | ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));\r | |
e1f414b6 | 2009 | \r |
4df26661 | 2010 | \r |
2011 | ReturnValue = Destination;\r | |
e1f414b6 | 2012 | while (*Source != '\0') {\r |
2013 | *(Destination++) = (CHAR16) *(Source++);\r | |
2014 | }\r | |
2015 | //\r | |
2016 | // End the Destination with a NULL.\r | |
2017 | //\r | |
2018 | *Destination = '\0';\r | |
2019 | \r | |
4df26661 | 2020 | //\r |
2021 | // ASSERT Original Destination is less long than PcdMaximumUnicodeStringLength\r | |
2022 | //\r | |
2023 | ASSERT (StrSize (ReturnValue) != 0);\r | |
2024 | \r | |
2025 | return ReturnValue;\r | |
e1f414b6 | 2026 | }\r |
2027 | \r | |
2028 | /**\r | |
2029 | Converts an 8-bit value to an 8-bit BCD value.\r | |
2030 | \r | |
2031 | Converts the 8-bit value specified by Value to BCD. The BCD value is\r | |
2032 | returned.\r | |
2033 | \r | |
2034 | If Value >= 100, then ASSERT().\r | |
2035 | \r | |
2036 | @param Value The 8-bit value to convert to BCD. Range 0..99.\r | |
2037 | \r | |
9aa049d9 | 2038 | @return The BCD value.\r |
e1f414b6 | 2039 | \r |
2040 | **/\r | |
2041 | UINT8\r | |
2042 | EFIAPI\r | |
2043 | DecimalToBcd8 (\r | |
2044 | IN UINT8 Value\r | |
2045 | )\r | |
2046 | {\r | |
2047 | ASSERT (Value < 100);\r | |
2048 | return (UINT8) (((Value / 10) << 4) | (Value % 10));\r | |
2049 | }\r | |
2050 | \r | |
2051 | /**\r | |
2052 | Converts an 8-bit BCD value to an 8-bit value.\r | |
2053 | \r | |
2054 | Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit\r | |
2055 | value is returned.\r | |
2056 | \r | |
2057 | If Value >= 0xA0, then ASSERT().\r | |
2058 | If (Value & 0x0F) >= 0x0A, then ASSERT().\r | |
2059 | \r | |
2060 | @param Value The 8-bit BCD value to convert to an 8-bit value.\r | |
2061 | \r | |
9aa049d9 | 2062 | @return The 8-bit value is returned.\r |
e1f414b6 | 2063 | \r |
2064 | **/\r | |
2065 | UINT8\r | |
2066 | EFIAPI\r | |
2067 | BcdToDecimal8 (\r | |
2068 | IN UINT8 Value\r | |
2069 | )\r | |
2070 | {\r | |
2071 | ASSERT (Value < 0xa0);\r | |
2072 | ASSERT ((Value & 0xf) < 0xa);\r | |
2073 | return (UINT8) ((Value >> 4) * 10 + (Value & 0xf));\r | |
2074 | }\r |