| 290 | enum ClassNameType { kName, kDescriptor }; |
| 291 | template<ClassNameType kType, char kSeparator> |
| 292 | static bool IsValidClassName(const char* s) { |
| 293 | int arrayCount = 0; |
| 294 | while (*s == '[') { |
| 295 | arrayCount++; |
| 296 | s++; |
| 297 | } |
| 298 | |
| 299 | if (arrayCount > 255) { |
| 300 | // Arrays may have no more than 255 dimensions. |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | ClassNameType type = kType; |
| 305 | if (type != kDescriptor && arrayCount != 0) { |
| 306 | /* |
| 307 | * If we're looking at an array of some sort, then it doesn't |
| 308 | * matter if what is being asked for is a class name; the |
| 309 | * format looks the same as a type descriptor in that case, so |
| 310 | * treat it as such. |
| 311 | */ |
| 312 | type = kDescriptor; |
| 313 | } |
| 314 | |
| 315 | if (type == kDescriptor) { |
| 316 | /* |
| 317 | * We are looking for a descriptor. Either validate it as a |
| 318 | * single-character primitive type, or continue on to check the |
| 319 | * embedded class name (bracketed by "L" and ";"). |
| 320 | */ |
| 321 | switch (*(s++)) { |
| 322 | case 'B': |
| 323 | case 'C': |
| 324 | case 'D': |
| 325 | case 'F': |
| 326 | case 'I': |
| 327 | case 'J': |
| 328 | case 'S': |
| 329 | case 'Z': |
| 330 | // These are all single-character descriptors for primitive types. |
| 331 | return (*s == '\0'); |
| 332 | case 'V': |
| 333 | // Non-array void is valid, but you can't have an array of void. |
| 334 | return (arrayCount == 0) && (*s == '\0'); |
| 335 | case 'L': |
| 336 | // Class name: Break out and continue below. |
| 337 | break; |
| 338 | default: |
| 339 | // Oddball descriptor character. |
| 340 | return false; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * We just consumed the 'L' that introduces a class name as part |
| 346 | * of a type descriptor, or we are looking for an unadorned class |
| 347 | * name. |
| 348 | */ |
| 349 |
nothing calls this directly
no test coverage detected