Rev 2726 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2726 | vana | 1 | /*++ |
| 2 | |||
| 3 | Copyright (c) 1998 Intel Corporation |
||
| 4 | |||
| 5 | Module Name: |
||
| 6 | |||
| 7 | str.c |
||
| 8 | |||
| 9 | Abstract: |
||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | |||
| 14 | Revision History |
||
| 15 | |||
| 16 | --*/ |
||
| 17 | |||
| 18 | #include "lib.h" |
||
| 19 | |||
| 20 | |||
| 21 | INTN |
||
| 22 | StrCmp ( |
||
| 23 | IN CHAR16 *s1, |
||
| 24 | IN CHAR16 *s2 |
||
| 25 | ) |
||
| 26 | // compare strings |
||
| 27 | { |
||
| 28 | return RtStrCmp(s1, s2); |
||
| 29 | } |
||
| 30 | |||
| 31 | INTN |
||
| 32 | StrnCmp ( |
||
| 33 | IN CHAR16 *s1, |
||
| 34 | IN CHAR16 *s2, |
||
| 35 | IN UINTN len |
||
| 36 | ) |
||
| 37 | // compare strings |
||
| 38 | { |
||
| 39 | while (*s1 && len) { |
||
| 40 | if (*s1 != *s2) { |
||
| 41 | break; |
||
| 42 | } |
||
| 43 | |||
| 44 | s1 += 1; |
||
| 45 | s2 += 1; |
||
| 46 | len -= 1; |
||
| 47 | } |
||
| 48 | |||
| 49 | return len ? *s1 - *s2 : 0; |
||
| 50 | } |
||
| 51 | |||
| 52 | |||
| 53 | INTN |
||
| 54 | LibStubStriCmp ( |
||
| 55 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
||
| 56 | IN CHAR16 *s1, |
||
| 57 | IN CHAR16 *s2 |
||
| 58 | ) |
||
| 59 | { |
||
| 60 | return StrCmp (s1, s2); |
||
| 61 | } |
||
| 62 | |||
| 63 | VOID |
||
| 64 | LibStubStrLwrUpr ( |
||
| 65 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
||
| 66 | IN CHAR16 *Str |
||
| 67 | ) |
||
| 68 | { |
||
| 69 | } |
||
| 70 | |||
| 71 | INTN |
||
| 72 | StriCmp ( |
||
| 73 | IN CHAR16 *s1, |
||
| 74 | IN CHAR16 *s2 |
||
| 75 | ) |
||
| 76 | // compare strings |
||
| 77 | { |
||
| 78 | return UnicodeInterface->StriColl(UnicodeInterface, s1, s2); |
||
| 79 | } |
||
| 80 | |||
| 81 | VOID |
||
| 82 | StrLwr ( |
||
| 83 | IN CHAR16 *Str |
||
| 84 | ) |
||
| 85 | // lwoer case string |
||
| 86 | { |
||
| 87 | UnicodeInterface->StrLwr(UnicodeInterface, Str); |
||
| 88 | } |
||
| 89 | |||
| 90 | VOID |
||
| 91 | StrUpr ( |
||
| 92 | IN CHAR16 *Str |
||
| 93 | ) |
||
| 94 | // upper case string |
||
| 95 | { |
||
| 96 | UnicodeInterface->StrUpr(UnicodeInterface, Str); |
||
| 97 | } |
||
| 98 | |||
| 99 | VOID |
||
| 100 | StrCpy ( |
||
| 101 | IN CHAR16 *Dest, |
||
| 102 | IN CHAR16 *Src |
||
| 103 | ) |
||
| 104 | // copy strings |
||
| 105 | { |
||
| 106 | RtStrCpy (Dest, Src); |
||
| 107 | } |
||
| 108 | |||
| 109 | VOID |
||
| 110 | StrCat ( |
||
| 111 | IN CHAR16 *Dest, |
||
| 112 | IN CHAR16 *Src |
||
| 113 | ) |
||
| 114 | { |
||
| 115 | RtStrCat(Dest, Src); |
||
| 116 | } |
||
| 117 | |||
| 118 | UINTN |
||
| 119 | StrLen ( |
||
| 120 | IN CHAR16 *s1 |
||
| 121 | ) |
||
| 122 | // string length |
||
| 123 | { |
||
| 124 | return RtStrLen(s1); |
||
| 125 | } |
||
| 126 | |||
| 127 | UINTN |
||
| 128 | StrSize ( |
||
| 129 | IN CHAR16 *s1 |
||
| 130 | ) |
||
| 131 | // string size |
||
| 132 | { |
||
| 133 | return RtStrSize(s1); |
||
| 134 | } |
||
| 135 | |||
| 136 | CHAR16 * |
||
| 137 | StrDuplicate ( |
||
| 138 | IN CHAR16 *Src |
||
| 139 | ) |
||
| 140 | // duplicate a string |
||
| 141 | { |
||
| 142 | CHAR16 *Dest; |
||
| 143 | UINTN Size; |
||
| 144 | |||
| 145 | Size = StrSize(Src); |
||
| 146 | Dest = AllocatePool (Size); |
||
| 147 | if (Dest) { |
||
| 148 | CopyMem (Dest, Src, Size); |
||
| 149 | } |
||
| 150 | return Dest; |
||
| 151 | } |
||
| 152 | |||
| 153 | UINTN |
||
| 154 | strlena ( |
||
| 155 | IN CHAR8 *s1 |
||
| 156 | ) |
||
| 157 | // string length |
||
| 158 | { |
||
| 159 | UINTN len; |
||
| 160 | |||
| 161 | for (len=0; *s1; s1+=1, len+=1) ; |
||
| 162 | return len; |
||
| 163 | } |
||
| 164 | |||
| 165 | UINTN |
||
| 166 | strcmpa ( |
||
| 167 | IN CHAR8 *s1, |
||
| 168 | IN CHAR8 *s2 |
||
| 169 | ) |
||
| 170 | // compare strings |
||
| 171 | { |
||
| 172 | while (*s1) { |
||
| 173 | if (*s1 != *s2) { |
||
| 174 | break; |
||
| 175 | } |
||
| 176 | |||
| 177 | s1 += 1; |
||
| 178 | s2 += 1; |
||
| 179 | } |
||
| 180 | |||
| 181 | return *s1 - *s2; |
||
| 182 | } |
||
| 183 | |||
| 184 | UINTN |
||
| 185 | strncmpa ( |
||
| 186 | IN CHAR8 *s1, |
||
| 187 | IN CHAR8 *s2, |
||
| 188 | IN UINTN len |
||
| 189 | ) |
||
| 190 | // compare strings |
||
| 191 | { |
||
| 192 | while (*s1 && len) { |
||
| 193 | if (*s1 != *s2) { |
||
| 194 | break; |
||
| 195 | } |
||
| 196 | |||
| 197 | s1 += 1; |
||
| 198 | s2 += 1; |
||
| 199 | len -= 1; |
||
| 200 | } |
||
| 201 | |||
| 202 | return len ? *s1 - *s2 : 0; |
||
| 203 | } |
||
| 204 | |||
| 205 | |||
| 206 | |||
| 207 | UINTN |
||
| 208 | xtoi ( |
||
| 209 | CHAR16 *str |
||
| 210 | ) |
||
| 211 | // convert hex string to uint |
||
| 212 | { |
||
| 213 | UINTN u; |
||
| 214 | CHAR16 c; |
||
| 215 | |||
| 216 | // skip preceeding white space |
||
| 217 | while (*str && *str == ' ') { |
||
| 218 | str += 1; |
||
| 219 | } |
||
| 220 | |||
| 221 | // convert hex digits |
||
| 222 | u = 0; |
||
| 223 | while ((c = *(str++))) { |
||
| 224 | if (c >= 'a' && c <= 'f') { |
||
| 225 | c -= 'a' - 'A'; |
||
| 226 | } |
||
| 227 | |||
| 228 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) { |
||
| 229 | u = (u << 4) | (c - (c >= 'A' ? 'A'-10 : '0')); |
||
| 230 | } else { |
||
| 231 | break; |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | return u; |
||
| 236 | } |
||
| 237 | |||
| 238 | UINTN |
||
| 239 | Atoi ( |
||
| 240 | CHAR16 *str |
||
| 241 | ) |
||
| 242 | // convert hex string to uint |
||
| 243 | { |
||
| 244 | UINTN u; |
||
| 245 | CHAR16 c; |
||
| 246 | |||
| 247 | // skip preceeding white space |
||
| 248 | while (*str && *str == ' ') { |
||
| 249 | str += 1; |
||
| 250 | } |
||
| 251 | |||
| 252 | // convert digits |
||
| 253 | u = 0; |
||
| 254 | while ((c = *(str++))) { |
||
| 255 | if (c >= '0' && c <= '9') { |
||
| 256 | u = (u * 10) + c - '0'; |
||
| 257 | } else { |
||
| 258 | break; |
||
| 259 | } |
||
| 260 | } |
||
| 261 | |||
| 262 | return u; |
||
| 263 | } |
||
| 264 | |||
| 265 | BOOLEAN |
||
| 266 | MetaMatch ( |
||
| 267 | IN CHAR16 *String, |
||
| 268 | IN CHAR16 *Pattern |
||
| 269 | ) |
||
| 270 | { |
||
| 271 | CHAR16 c, p, l; |
||
| 272 | |||
| 273 | for (; ;) { |
||
| 274 | p = *Pattern; |
||
| 275 | Pattern += 1; |
||
| 276 | |||
| 277 | switch (p) { |
||
| 278 | case 0: |
||
| 279 | // End of pattern. If end of string, TRUE match |
||
| 280 | return *String ? FALSE : TRUE; |
||
| 281 | |||
| 282 | case '*': |
||
| 283 | // Match zero or more chars |
||
| 284 | while (*String) { |
||
| 285 | if (MetaMatch (String, Pattern)) { |
||
| 286 | return TRUE; |
||
| 287 | } |
||
| 288 | String += 1; |
||
| 289 | } |
||
| 290 | return MetaMatch (String, Pattern); |
||
| 291 | |||
| 292 | case '?': |
||
| 293 | // Match any one char |
||
| 294 | if (!*String) { |
||
| 295 | return FALSE; |
||
| 296 | } |
||
| 297 | String += 1; |
||
| 298 | break; |
||
| 299 | |||
| 300 | case '[': |
||
| 301 | // Match char set |
||
| 302 | c = *String; |
||
| 303 | if (!c) { |
||
| 304 | return FALSE; // syntax problem |
||
| 305 | } |
||
| 306 | |||
| 307 | l = 0; |
||
| 308 | while ((p = *Pattern++)) { |
||
| 309 | if (p == ']') { |
||
| 310 | return FALSE; |
||
| 311 | } |
||
| 312 | |||
| 313 | if (p == '-') { // if range of chars, |
||
| 314 | p = *Pattern; // get high range |
||
| 315 | if (p == 0 || p == ']') { |
||
| 316 | return FALSE; // syntax problem |
||
| 317 | } |
||
| 318 | |||
| 319 | if (c >= l && c <= p) { // if in range, |
||
| 320 | break; // it's a match |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | l = p; |
||
| 325 | if (c == p) { // if char matches |
||
| 326 | break; // move on |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | // skip to end of match char set |
||
| 331 | while (p && p != ']') { |
||
| 332 | p = *Pattern; |
||
| 333 | Pattern += 1; |
||
| 334 | } |
||
| 335 | |||
| 336 | String += 1; |
||
| 337 | break; |
||
| 338 | |||
| 339 | default: |
||
| 340 | c = *String; |
||
| 341 | if (c != p) { |
||
| 342 | return FALSE; |
||
| 343 | } |
||
| 344 | |||
| 345 | String += 1; |
||
| 346 | break; |
||
| 347 | } |
||
| 348 | } |
||
| 349 | } |
||
| 350 | |||
| 351 | |||
| 352 | BOOLEAN |
||
| 353 | LibStubMetaiMatch ( |
||
| 354 | IN EFI_UNICODE_COLLATION_INTERFACE *This, |
||
| 355 | IN CHAR16 *String, |
||
| 356 | IN CHAR16 *Pattern |
||
| 357 | ) |
||
| 358 | { |
||
| 359 | return MetaMatch (String, Pattern); |
||
| 360 | } |
||
| 361 | |||
| 362 | |||
| 363 | BOOLEAN |
||
| 364 | MetaiMatch ( |
||
| 365 | IN CHAR16 *String, |
||
| 366 | IN CHAR16 *Pattern |
||
| 367 | ) |
||
| 368 | { |
||
| 369 | return UnicodeInterface->MetaiMatch(UnicodeInterface, String, Pattern); |
||
| 370 | } |