1//===- llvm/ADT/SmallString.h - 'Normally small' strings --------*- C++ -*-===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
10/// This file defines the SmallString class.
12//===----------------------------------------------------------------------===//
14#ifndef LLVM_ADT_SMALLSTRING_H
15#define LLVM_ADT_SMALLSTRING_H
23/// SmallString - A SmallString is just a SmallVector with methods and accessors
24/// that make it work better as a string (e.g. operator+ etc).
25template<
unsigned InternalLen>
28 /// Default ctor - Initialize to empty.
31 /// Initialize from a StringRef.
34 /// Initialize by concatenating a list of StringRefs.
40 /// Initialize with a range.
41 template<
typename ItTy>
45 /// @name String Assignment
50 /// Assign from a StringRef.
55 /// Assign from a list of StringRefs.
56 void assign(std::initializer_list<StringRef> Refs) {
62 /// @name String Concatenation
67 /// Append from a StringRef.
72 /// Append from a list of StringRefs.
73 void append(std::initializer_list<StringRef> Refs) {
74 size_t CurrentSize = this->
size();
75 size_t SizeNeeded = CurrentSize;
77 SizeNeeded +=
Ref.size();
80 std::copy(
Ref.begin(),
Ref.end(), this->begin() + CurrentSize);
81 CurrentSize +=
Ref.size();
87 /// @name String Comparison
90 /// Check for string equality. This is more efficient than compare() when
91 /// the relative ordering of inequal strings isn't needed.
94 /// Check for string equality, ignoring case.
99 /// compare - Compare two strings; the result is negative, zero, or positive
100 /// if this string is lexicographically less than, equal to, or greater than
104 /// compare_insensitive - Compare two strings, ignoring case.
109 /// compare_numeric - Compare two strings, treating sequences of digits as
116 /// @name String Predicates
119 /// starts_with - Check if this string starts with the given \p Prefix.
124 /// ends_with - Check if this string ends with the given \p Suffix.
130 /// @name String Searching
133 /// find - Search for the first character \p C in the string.
135 /// \return - The index of the first occurrence of \p C, or npos if not
137 [[nodiscard]]
size_t find(
char C,
size_t From = 0)
const {
141 /// Search for the first string \p Str in the string.
143 /// \returns The index of the first occurrence of \p Str, or npos if not
149 /// Search for the last character \p C in the string.
151 /// \returns The index of the last occurrence of \p C, or npos if not
157 /// Search for the last string \p Str in the string.
159 /// \returns The index of the last occurrence of \p Str, or npos if not
163 /// Find the first character in the string that is \p C, or npos if not
164 /// found. Same as find.
169 /// Find the first character in the string that is in \p Chars, or npos if
172 /// Complexity: O(size() + Chars.size())
177 /// Find the first character in the string that is not \p C or npos if not
183 /// Find the first character in the string that is not in the string
184 /// \p Chars, or npos if not found.
186 /// Complexity: O(size() + Chars.size())
188 size_t From = 0)
const {
192 /// Find the last character in the string that is \p C, or npos if not
199 /// Find the last character in the string that is in \p C, or npos if not
202 /// Complexity: O(size() + Chars.size())
209 /// @name Helpful Algorithms
212 /// Return the number of occurrences of \p C in the string.
215 /// Return the number of non-overlapped occurrences of \p Str in the
220 /// @name Substring Operations
223 /// Return a reference to the substring from [Start, Start + N).
225 /// \param Start The index of the starting character in the substring; if
226 /// the index is npos or greater than the length of the string then the
227 /// empty substring will be returned.
229 /// \param N The number of characters to included in the substring. If \p N
230 /// exceeds the number of characters remaining in the string, the string
231 /// suffix (starting with \p Start) will be returned.
237 /// Return a reference to the substring from [Start, End).
239 /// \param Start The index of the starting character in the substring; if
240 /// the index is npos or greater than the length of the string then the
241 /// empty substring will be returned.
243 /// \param End The index following the last character to include in the
244 /// substring. If this is npos, or less than \p Start, or exceeds the
245 /// number of characters remaining in the string, the string suffix
246 /// (starting with \p Start) will be returned.
253 /// Explicit conversion to StringRef.
258 // TODO: Make this const, if it's safe...
265 /// Implicit conversion to StringRef.
268 explicit operator std::string()
const {
269 return std::string(this->
data(), this->
size());
288}
// end namespace llvm
290#endif // LLVM_ADT_SMALLSTRING_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the SmallVector class.
size_t rfind(StringRef Str) const
Search for the last string Str in the string.
size_t find_first_of(StringRef Chars, size_t From=0) const
Find the first character in the string that is in Chars, or npos if not found.
SmallString(StringRef S)
Initialize from a StringRef.
size_t find_last_of(StringRef Chars, size_t From=StringRef::npos) const
Find the last character in the string that is in C, or npos if not found.
size_t find_last_of(char C, size_t From=StringRef::npos) const
Find the last character in the string that is C, or npos if not found.
SmallString & operator=(StringRef RHS)
void assign(std::initializer_list< StringRef > Refs)
Assign from a list of StringRefs.
SmallString()=default
Default ctor - Initialize to empty.
size_t find(char C, size_t From=0) const
find - Search for the first character C in the string.
bool ends_with(StringRef Suffix) const
ends_with - Check if this string ends with the given Suffix.
size_t find(StringRef Str, size_t From=0) const
Search for the first string Str in the string.
bool equals(StringRef RHS) const
Check for string equality.
size_t count(StringRef Str) const
Return the number of non-overlapped occurrences of Str in the string.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
size_t rfind(char C, size_t From=StringRef::npos) const
Search for the last character C in the string.
void append(std::initializer_list< StringRef > Refs)
Append from a list of StringRefs.
SmallString & operator+=(char C)
void assign(StringRef RHS)
Assign from a StringRef.
SmallString & operator+=(StringRef RHS)
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
int compare_numeric(StringRef RHS) const
compare_numeric - Compare two strings, treating sequences of digits as numbers.
int compare(StringRef RHS) const
compare - Compare two strings; the result is negative, zero, or positive if this string is lexicograp...
bool starts_with(StringRef Prefix) const
starts_with - Check if this string starts with the given Prefix.
StringRef substr(size_t Start, size_t N=StringRef::npos) const
Return a reference to the substring from [Start, Start + N).
size_t find_first_not_of(StringRef Chars, size_t From=0) const
Find the first character in the string that is not in the string Chars, or npos if not found.
void append(StringRef RHS)
Append from a StringRef.
SmallString(ItTy S, ItTy E)
Initialize with a range.
int compare_insensitive(StringRef RHS) const
compare_insensitive - Compare two strings, ignoring case.
size_t count(char C) const
Return the number of occurrences of C in the string.
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
SmallString(std::initializer_list< StringRef > Refs)
Initialize by concatenating a list of StringRefs.
StringRef str() const
Explicit conversion to StringRef.
size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
void resize_for_overwrite(size_type N)
void assign(size_type NumElts, ValueParamT Elt)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const char &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
LLVM_ABI int compare_numeric(StringRef RHS) const
compare_numeric - Compare two strings, treating sequences of digits as numbers.
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
size_t count(char C) const
Return the number of occurrences of C in the string.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
int compare(StringRef RHS) const
compare - Compare two strings; the result is negative, zero, or positive if this string is lexicograp...
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
LLVM_ABI size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
LLVM_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
@ Ref
The access may reference the value stored in memory.