* @brief Checks if the string is a valid C language identifier. * * Empty string is not valid identifier. */
| 918 | * Empty string is not valid identifier. |
| 919 | */ |
| 920 | bool isIdentifier(const std::string &str) |
| 921 | { |
| 922 | if (str.empty()) |
| 923 | return false; |
| 924 | |
| 925 | if (str[0] != '_' && !isalpha(static_cast<unsigned char>(str[0]))) |
| 926 | return false; |
| 927 | |
| 928 | for (std::size_t i = 1; i < str.size(); ++i) { |
| 929 | if (str[i] != '_' && !isalnum(static_cast<unsigned char>(str[i]))) |
| 930 | return false; |
| 931 | } |
| 932 | |
| 933 | return true; |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * @brief Checks if the string is printable. |