diff options
Diffstat (limited to 'ELF/Strings.cpp')
-rw-r--r-- | ELF/Strings.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/ELF/Strings.cpp b/ELF/Strings.cpp index a7aecf090..21d7f428e 100644 --- a/ELF/Strings.cpp +++ b/ELF/Strings.cpp @@ -11,6 +11,7 @@ #include "Error.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" +#include <algorithm> using namespace llvm; using namespace lld; @@ -55,3 +56,15 @@ std::vector<uint8_t> elf::parseHex(StringRef S) { } return Hex; } + +static bool isAlpha(char C) { + return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z') || C == '_'; +} + +static bool isAlnum(char C) { return isAlpha(C) || ('0' <= C && C <= '9'); } + +// Returns true if S is valid as a C language identifier. +bool elf::isValidCIdentifier(StringRef S) { + return !S.empty() && isAlpha(S[0]) && + std::all_of(S.begin() + 1, S.end(), isAlnum); +} |