MCPcopy Create free account
hub / github.com/avast/retdec / isIdentifier

Function isIdentifier

src/utils/string.cpp:920–934  ·  view source on GitHub ↗

* @brief Checks if the string is a valid C language identifier. * * Empty string is not valid identifier. */

Source from the content-addressed store, hash-verified

918 * Empty string is not valid identifier.
919 */
920bool 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.

Callers 1

TEST_FFunction · 0.85

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.68