diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-08-18 18:26:35 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-08-18 18:26:35 +0000 |
commit | 4a719da74b64e510f957f473dbe71677c2002036 (patch) | |
tree | 3e546f1a41a93abb66d7e95091fd123f8e788316 /include/llvm/ADT | |
parent | 82f74320e2974d0511cdae2e437bf46e019eaba8 (diff) | |
download | external_llvm-4a719da74b64e510f957f473dbe71677c2002036.zip external_llvm-4a719da74b64e510f957f473dbe71677c2002036.tar.gz external_llvm-4a719da74b64e510f957f473dbe71677c2002036.tar.bz2 |
Add StringRef::count({char,StringRef})
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79354 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r-- | include/llvm/ADT/StringRef.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index 40689a9..5433056 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -172,6 +172,28 @@ namespace llvm { return npos; } + /// count - Return the number of occurrences of \arg C in the string. + size_t count(char C) const { + size_t Count = 0; + for (size_t i = 0, e = Length; i != e; ++i) + if (Data[i] == C) + return i; + return Count; + } + + /// count - Return the number of non-overlapped occurrences of \arg Str in + /// the string. + size_t count(const StringRef &Str) const { + size_t Count = 0; + size_t N = Str.size(); + if (N > Length) + return 0; + for (size_t i = 0, e = Length - N + 1; i != e; ++i) + if (substr(i, N).equals(Str)) + ++Count; + return Count; + } + /// @} /// @name Substring Operations /// @{ |