exportname ::= | importname ::= | | |
| 335 | // exportname ::= <plainname> | <interfacename> |
| 336 | // importname ::= <exportname> | <depname> | <urlname> | <hashname> |
| 337 | Expect<ComponentName> ComponentName::parse(std::string_view Name) { |
| 338 | ComponentName Result(Name); |
| 339 | auto Next = Name; |
| 340 | |
| 341 | // plainname ::= <label> |
| 342 | // | '[constructor]' <label> |
| 343 | // | '[method]' <label> '.' <label> |
| 344 | // | '[static]' <label> '.' <label> |
| 345 | |
| 346 | if (tryRead("[constructor]"sv, Next)) { |
| 347 | if (!isKebabString(Next)) { |
| 348 | return reportError("invalid label after [constructor]"sv); |
| 349 | } |
| 350 | Result.Detail.emplace<ConstructorDetail>(ConstructorDetail{Next}); |
| 351 | Result.NoTagName = Next; |
| 352 | Result.Kind = ComponentNameKind::Constructor; |
| 353 | return Result; |
| 354 | } |
| 355 | |
| 356 | auto tryReadResourceWithLabel = [&](std::string_view Tag, |
| 357 | std::string_view &Resource, |
| 358 | std::string_view &Label) -> bool { |
| 359 | auto Saved = Next; |
| 360 | if (!tryRead(Tag, Next)) { |
| 361 | return false; |
| 362 | } |
| 363 | auto TmpNoTagName = Next; |
| 364 | if (!readUntil(Next, '.', Resource)) { |
| 365 | Next = Saved; |
| 366 | return false; |
| 367 | } |
| 368 | if (!isKebabString(Resource) || !isKebabString(Next)) { |
| 369 | Next = Saved; |
| 370 | return false; |
| 371 | } |
| 372 | Result.NoTagName = TmpNoTagName; |
| 373 | Label = Next; |
| 374 | return true; |
| 375 | }; |
| 376 | |
| 377 | { |
| 378 | std::string_view Resource, Label; |
| 379 | if (tryReadResourceWithLabel("[method]"sv, Resource, Label)) { |
| 380 | Result.Detail.emplace<MethodDetail>(MethodDetail{Resource, Label}); |
| 381 | Result.Kind = ComponentNameKind::Method; |
| 382 | return Result; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | { |
| 387 | std::string_view Resource, Label; |
| 388 | if (tryReadResourceWithLabel("[static]"sv, Resource, Label)) { |
| 389 | Result.Detail.emplace<StaticDetail>(StaticDetail{Resource, Label}); |
| 390 | Result.Kind = ComponentNameKind::Static; |
| 391 | return Result; |
| 392 | } |
| 393 | } |
| 394 |
nothing calls this directly
no test coverage detected