LLVM: lib/Support/StringExtras.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
16#include
17
18using namespace llvm;
19
20
21
22
24 size_t N = s2.size(), M = s1.size();
25 if (N > M)
27 for (size_t i = 0, e = M - N + 1; i != e; ++i)
29 return i;
31}
32
33
34
35
36
37
38
41
43
44
46
47 return {Source.slice(Start, End), Source.substr(End)};
48}
49
50
51
55 std::pair<StringRef, StringRef> S = getToken(Source, Delimiters);
56 while (!S.first.empty()) {
58 S = getToken(S.second, Delimiters);
59 }
60}
61
63 for (unsigned char C : Name) {
64 if (C == '\\')
65 Out << '\\' << C;
67 Out << C;
68 else
70 }
71}
72
75 if (C == '&')
76 Out << "&";
77 else if (C == '<')
78 Out << "<";
79 else if (C == '>')
80 Out << ">";
81 else if (C == '\"')
82 Out << """;
83 else if (C == '\'')
84 Out << "'";
85 else
86 Out << C;
87 }
88}
89
94
96 if (input.empty())
97 return "";
98
99 std::string snakeCase;
100 snakeCase.reserve(input.size());
101 auto check = [&input](size_t j, function_ref<bool(int)> predicate) {
102 return j < input.size() && predicate(input[j]);
103 };
104 for (size_t i = 0; i < input.size(); ++i) {
105 snakeCase.push_back(tolower(input[i]));
106
107 if (check(i, isupper) && check(i + 1, isupper) && check(i + 2, islower))
108 snakeCase.push_back('_');
109 if ((check(i, islower) || check(i, isdigit)) && check(i + 1, isupper))
110 snakeCase.push_back('_');
111 }
112 return snakeCase;
113}
114
116 bool capitalizeFirst) {
117 if (input.empty())
118 return "";
119
120 std::string output;
121 output.reserve(input.size());
122
123
124 if (capitalizeFirst && std::islower(input.front()))
126 else
127 output.push_back(input.front());
128
129
130 for (size_t pos = 1, e = input.size(); pos < e; ++pos) {
131 if (input[pos] == '_' && pos != (e - 1) && std::islower(input[pos + 1]))
133 else
134 output.push_back(input[pos]);
135 }
136 return output;
137}
This file defines the SmallVector class.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
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).
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2)
StrInStrNoCase - Portable version of strcasestr. Locates the first occurrence of string 's1' in strin...
Definition StringExtras.cpp:23
char toLower(char x)
Returns the corresponding lowercase character if x is uppercase.
LLVM_ABI void printHTMLEscaped(StringRef String, raw_ostream &Out)
Print each character of the specified string, escaping HTML special characters.
Definition StringExtras.cpp:73
LLVM_ABI void printLowerCase(StringRef String, raw_ostream &Out)
printLowerCase - Print each character as lowercase if it is uppercase.
Definition StringExtras.cpp:90
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
Definition StringExtras.cpp:39
LLVM_ABI void printEscapedString(StringRef Name, raw_ostream &Out)
Print each character of the specified string, escaping it if it is not printable or if it is an escap...
Definition StringExtras.cpp:62
LLVM_ABI void SplitString(StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \t\n\v\f\r")
SplitString - Split up the specified string according to the specified delimiters,...
Definition StringExtras.cpp:52
LLVM_ABI std::string convertToSnakeFromCamelCase(StringRef input)
Converts a string from camel-case to snake-case by replacing all uppercase letters with '_' followed ...
Definition StringExtras.cpp:95
char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16).
char toUpper(char x)
Returns the corresponding uppercase character if x is lowercase.
LLVM_ABI std::string convertToCamelFromSnakeCase(StringRef input, bool capitalizeFirst=false)
Converts a string from snake-case to camel-case by replacing all occurrences of '_' followed by a low...
Definition StringExtras.cpp:115
bool isPrint(char C)
Checks whether character C is printable.