llvm.org GIT mirror llvm / 89d65d4
StringExtras.h Don't mark header functions as file-scope static This creates ODR violations if the function is called from another inline function in a header and also creates binary bloat from duplicate definitions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316473 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 2 years ago
1 changed file(s) with 16 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
3232
3333 /// hexdigit - Return the hexadecimal character for the
3434 /// given number \p X (which should be less than 16).
35 static inline char hexdigit(unsigned X, bool LowerCase = false) {
35 inline char hexdigit(unsigned X, bool LowerCase = false) {
3636 const char HexChar = LowerCase ? 'a' : 'A';
3737 return X < 10 ? '0' + X : HexChar + X - 10;
3838 }
3939
4040 /// Construct a string ref from a boolean.
41 static inline StringRef toStringRef(bool B) {
42 return StringRef(B ? "true" : "false");
43 }
41 inline StringRef toStringRef(bool B) { return StringRef(B ? "true" : "false"); }
4442
4543 /// Construct a string ref from an array ref of unsigned chars.
46 static inline StringRef toStringRef(ArrayRef Input) {
44 inline StringRef toStringRef(ArrayRef Input) {
4745 return StringRef(reinterpret_cast(Input.begin()), Input.size());
4846 }
4947
5149 /// value.
5250 ///
5351 /// If \p C is not a valid hex digit, -1U is returned.
54 static inline unsigned hexDigitValue(char C) {
52 inline unsigned hexDigitValue(char C) {
5553 if (C >= '0' && C <= '9') return C-'0';
5654 if (C >= 'a' && C <= 'f') return C-'a'+10U;
5755 if (C >= 'A' && C <= 'F') return C-'A'+10U;
5957 }
6058
6159 /// Checks if character \p C is one of the 10 decimal digits.
62 static inline bool isDigit(char C) { return C >= '0' && C <= '9'; }
60 inline bool isDigit(char C) { return C >= '0' && C <= '9'; }
6361
6462 /// Checks if character \p C is a hexadecimal numeric character.
65 static inline bool isHexDigit(char C) { return hexDigitValue(C) != -1U; }
63 inline bool isHexDigit(char C) { return hexDigitValue(C) != -1U; }
6664
6765 /// Checks if character \p C is a valid letter as classified by "C" locale.
68 static inline bool isAlpha(char C) {
66 inline bool isAlpha(char C) {
6967 return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z');
7068 }
7169
7270 /// Checks whether character \p C is either a decimal digit or an uppercase or
7371 /// lowercase letter as classified by "C" locale.
74 static inline bool isAlnum(char C) { return isAlpha(C) || isDigit(C); }
75
76 static inline std::string utohexstr(uint64_t X, bool LowerCase = false) {
72 inline bool isAlnum(char C) { return isAlpha(C) || isDigit(C); }
73
74 inline std::string utohexstr(uint64_t X, bool LowerCase = false) {
7775 char Buffer[17];
7876 char *BufPtr = std::end(Buffer);
7977
108106 return toHex(toStringRef(Input));
109107 }
110108
111 static inline uint8_t hexFromNibbles(char MSB, char LSB) {
109 inline uint8_t hexFromNibbles(char MSB, char LSB) {
112110 unsigned U1 = hexDigitValue(MSB);
113111 unsigned U2 = hexDigitValue(LSB);
114112 assert(U1 != -1U && U2 != -1U);
118116
119117 /// Convert hexadecimal string \p Input to its binary representation.
120118 /// The return string is half the size of \p Input.
121 static inline std::string fromHex(StringRef Input) {
119 inline std::string fromHex(StringRef Input) {
122120 if (Input.empty())
123121 return std::string();
124122
171169 return detail::to_float(T, Num, strtold);
172170 }
173171
174 static inline std::string utostr(uint64_t X, bool isNeg = false) {
172 inline std::string utostr(uint64_t X, bool isNeg = false) {
175173 char Buffer[21];
176174 char *BufPtr = std::end(Buffer);
177175
186184 return std::string(BufPtr, std::end(Buffer));
187185 }
188186
189 static inline std::string itostr(int64_t X) {
187 inline std::string itostr(int64_t X) {
190188 if (X < 0)
191189 return utostr(static_cast(-X), true);
192190 else
220218 // FIXME: Investigate whether a modified bernstein hash function performs
221219 // better: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
222220 // X*33+c -> X*33^c
223 static inline unsigned HashString(StringRef Str, unsigned Result = 0) {
221 inline unsigned HashString(StringRef Str, unsigned Result = 0) {
224222 for (StringRef::size_type i = 0, e = Str.size(); i != e; ++i)
225223 Result = Result * 33 + (unsigned char)Str[i];
226224 return Result;
227225 }
228226
229227 /// Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th).
230 static inline StringRef getOrdinalSuffix(unsigned Val) {
228 inline StringRef getOrdinalSuffix(unsigned Val) {
231229 // It is critically important that we do this perfectly for
232230 // user-written sequences with over 100 elements.
233231 switch (Val % 100) {