aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2008-01-31 23:02:33 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2008-01-31 23:02:33 +0000
commitec3e5c8a39c3dae7457d0eb18f98685decb23fcd (patch)
treede896f070c2d440a98737bcf511206bb94c6d04a
parent334dc1f58d617dcff969a2e107febaae42bbc883 (diff)
Add convenient std::string helpers to StringMap. Patch by Mikhail Glushenkov!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46625 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/StringMap.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h
index 81a55456df..dd040f927d 100644
--- a/include/llvm/ADT/StringMap.h
+++ b/include/llvm/ADT/StringMap.h
@@ -16,6 +16,7 @@
#include "llvm/Support/Allocator.h"
#include <cstring>
+#include <string>
namespace llvm {
template<typename ValueT>
@@ -268,24 +269,36 @@ public:
if (Bucket == -1) return end();
return iterator(TheTable+Bucket);
}
+ iterator find(const char *Key) {
+ return find(Key, Key + strlen(Key));
+ }
+ iterator find(const std::string &Key) {
+ const char* key_start = &Key[0];
+ return find(key_start, key_start + Key.size());
+ }
const_iterator find(const char *KeyStart, const char *KeyEnd) const {
int Bucket = FindKey(KeyStart, KeyEnd);
if (Bucket == -1) return end();
return const_iterator(TheTable+Bucket);
}
-
- iterator find(const char *Key) {
- return find(Key, Key + strlen(Key));
- }
const_iterator find(const char *Key) const {
return find(Key, Key + strlen(Key));
}
+ const_iterator find(const std::string &Key) const {
+ const char* key_start = &Key[0];
+ return find(key_start, key_start + Key.size());
+ }
ValueTy& operator[](const char *Key) {
value_type& entry = GetOrCreateValue(Key, Key + strlen(Key));
return entry.getValue();
}
+ ValueTy& operator[](const std::string &Key) {
+ const char* key_start = &Key[0];
+ value_type& entry = GetOrCreateValue(key_start, key_start + Key.size());
+ return entry.getValue();
+ }
size_type count(const char *KeyStart, const char *KeyEnd) const {
return find(KeyStart, KeyEnd) == end() ? 0 : 1;
@@ -293,6 +306,10 @@ public:
size_type count(const char *Key) const {
return count(Key, Key + strlen(Key));
}
+ size_type count(const std::string &Key) const {
+ const char* key_start = &Key[0];
+ return count(key_start, key_start + Key.size());
+ }
/// insert - Insert the specified key/value pair into the map. If the key
/// already exists in the map, return false and ignore the request, otherwise