| 621 | } |
| 622 | |
| 623 | inline bool validate_mod_id(std::string_view str) { |
| 624 | // Disallow empty ids. |
| 625 | if (str.size() == 0) { |
| 626 | return false; |
| 627 | } |
| 628 | |
| 629 | // Allow special dependency ids. |
| 630 | if (str == N64Recomp::DependencySelf || str == N64Recomp::DependencyBaseRecomp) { |
| 631 | return true; |
| 632 | } |
| 633 | |
| 634 | // These following rules basically describe C identifiers. There's no specific reason to enforce them besides colon (currently), |
| 635 | // so this is just to prevent "weird" mod ids. |
| 636 | |
| 637 | // Check the first character, which must be alphabetical or an underscore. |
| 638 | if (!isalpha_nolocale(str[0]) && str[0] != '_') { |
| 639 | return false; |
| 640 | } |
| 641 | |
| 642 | // Check the remaining characters, which can be alphanumeric or underscore. |
| 643 | for (char c : str.substr(1)) { |
| 644 | if (!isalnum_nolocale(c) && c != '_') { |
| 645 | return false; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | return true; |
| 650 | } |
| 651 | |
| 652 | inline bool validate_mod_id(const std::string& str) { |
| 653 | return validate_mod_id(std::string_view{str}); |
no test coverage detected