summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Strings.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-06-29 09:08:02 +0000
committerRui Ueyama <ruiu@google.com>2016-06-29 09:08:02 +0000
commitfbbde548cfcc25613c5f87928215fc73eff5e766 (patch)
tree61796b64e70a74bfe5cbc041b64eb910e23a7da2 /lld/ELF/Strings.cpp
parent9fc1d4ed7586afbe15bd29ffb08ac616f3e59ea8 (diff)
downloadbcm5719-llvm-fbbde548cfcc25613c5f87928215fc73eff5e766.tar.gz
bcm5719-llvm-fbbde548cfcc25613c5f87928215fc73eff5e766.zip
Move isValidCIdentifier to Strings.cpp.
llvm-svn: 274112
Diffstat (limited to 'lld/ELF/Strings.cpp')
-rw-r--r--lld/ELF/Strings.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lld/ELF/Strings.cpp b/lld/ELF/Strings.cpp
index a7aecf09035..21d7f428e85 100644
--- a/lld/ELF/Strings.cpp
+++ b/lld/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);
+}
OpenPOWER on IntegriCloud