aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/libs/llvm12/include/llvm/ADT/StringExtras.h
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/llvm12/include/llvm/ADT/StringExtras.h')
-rw-r--r--contrib/libs/llvm12/include/llvm/ADT/StringExtras.h192
1 files changed, 96 insertions, 96 deletions
diff --git a/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h b/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h
index d7332d08a6..1ddaf13978 100644
--- a/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h
+++ b/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h
@@ -73,29 +73,29 @@ inline ArrayRef<uint8_t> arrayRefFromStringRef(StringRef Input) {
///
/// If \p C is not a valid hex digit, -1U is returned.
inline unsigned hexDigitValue(char C) {
- struct HexTable {
- unsigned LUT[255] = {};
- constexpr HexTable() {
- // Default initialize everything to invalid.
- for (int i = 0; i < 255; ++i)
- LUT[i] = ~0U;
- // Initialize `0`-`9`.
- for (int i = 0; i < 10; ++i)
- LUT['0' + i] = i;
- // Initialize `A`-`F` and `a`-`f`.
- for (int i = 0; i < 6; ++i)
- LUT['A' + i] = LUT['a' + i] = 10 + i;
- }
- };
- constexpr HexTable Table;
- return Table.LUT[static_cast<unsigned char>(C)];
+ struct HexTable {
+ unsigned LUT[255] = {};
+ constexpr HexTable() {
+ // Default initialize everything to invalid.
+ for (int i = 0; i < 255; ++i)
+ LUT[i] = ~0U;
+ // Initialize `0`-`9`.
+ for (int i = 0; i < 10; ++i)
+ LUT['0' + i] = i;
+ // Initialize `A`-`F` and `a`-`f`.
+ for (int i = 0; i < 6; ++i)
+ LUT['A' + i] = LUT['a' + i] = 10 + i;
+ }
+ };
+ constexpr HexTable Table;
+ return Table.LUT[static_cast<unsigned char>(C)];
}
/// Checks if character \p C is one of the 10 decimal digits.
inline bool isDigit(char C) { return C >= '0' && C <= '9'; }
/// Checks if character \p C is a hexadecimal numeric character.
-inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; }
+inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; }
/// Checks if character \p C is a valid letter as classified by "C" locale.
inline bool isAlpha(char C) {
@@ -184,70 +184,70 @@ inline std::string toHex(ArrayRef<uint8_t> Input, bool LowerCase = false) {
return toHex(toStringRef(Input), LowerCase);
}
-/// Store the binary representation of the two provided values, \p MSB and
-/// \p LSB, that make up the nibbles of a hexadecimal digit. If \p MSB or \p LSB
-/// do not correspond to proper nibbles of a hexadecimal digit, this method
-/// returns false. Otherwise, returns true.
-inline bool tryGetHexFromNibbles(char MSB, char LSB, uint8_t &Hex) {
+/// Store the binary representation of the two provided values, \p MSB and
+/// \p LSB, that make up the nibbles of a hexadecimal digit. If \p MSB or \p LSB
+/// do not correspond to proper nibbles of a hexadecimal digit, this method
+/// returns false. Otherwise, returns true.
+inline bool tryGetHexFromNibbles(char MSB, char LSB, uint8_t &Hex) {
unsigned U1 = hexDigitValue(MSB);
unsigned U2 = hexDigitValue(LSB);
- if (U1 == ~0U || U2 == ~0U)
- return false;
-
- Hex = static_cast<uint8_t>((U1 << 4) | U2);
- return true;
-}
-
-/// Return the binary representation of the two provided values, \p MSB and
-/// \p LSB, that make up the nibbles of a hexadecimal digit.
-inline uint8_t hexFromNibbles(char MSB, char LSB) {
- uint8_t Hex = 0;
- bool GotHex = tryGetHexFromNibbles(MSB, LSB, Hex);
- (void)GotHex;
- assert(GotHex && "MSB and/or LSB do not correspond to hex digits");
- return Hex;
-}
-
-/// Convert hexadecimal string \p Input to its binary representation and store
-/// the result in \p Output. Returns true if the binary representation could be
-/// converted from the hexadecimal string. Returns false if \p Input contains
-/// non-hexadecimal digits. The output string is half the size of \p Input.
-inline bool tryGetFromHex(StringRef Input, std::string &Output) {
+ if (U1 == ~0U || U2 == ~0U)
+ return false;
+
+ Hex = static_cast<uint8_t>((U1 << 4) | U2);
+ return true;
+}
+
+/// Return the binary representation of the two provided values, \p MSB and
+/// \p LSB, that make up the nibbles of a hexadecimal digit.
+inline uint8_t hexFromNibbles(char MSB, char LSB) {
+ uint8_t Hex = 0;
+ bool GotHex = tryGetHexFromNibbles(MSB, LSB, Hex);
+ (void)GotHex;
+ assert(GotHex && "MSB and/or LSB do not correspond to hex digits");
+ return Hex;
+}
+
+/// Convert hexadecimal string \p Input to its binary representation and store
+/// the result in \p Output. Returns true if the binary representation could be
+/// converted from the hexadecimal string. Returns false if \p Input contains
+/// non-hexadecimal digits. The output string is half the size of \p Input.
+inline bool tryGetFromHex(StringRef Input, std::string &Output) {
if (Input.empty())
- return true;
+ return true;
Output.reserve((Input.size() + 1) / 2);
if (Input.size() % 2 == 1) {
- uint8_t Hex = 0;
- if (!tryGetHexFromNibbles('0', Input.front(), Hex))
- return false;
-
- Output.push_back(Hex);
+ uint8_t Hex = 0;
+ if (!tryGetHexFromNibbles('0', Input.front(), Hex))
+ return false;
+
+ Output.push_back(Hex);
Input = Input.drop_front();
}
assert(Input.size() % 2 == 0);
while (!Input.empty()) {
- uint8_t Hex = 0;
- if (!tryGetHexFromNibbles(Input[0], Input[1], Hex))
- return false;
-
+ uint8_t Hex = 0;
+ if (!tryGetHexFromNibbles(Input[0], Input[1], Hex))
+ return false;
+
Output.push_back(Hex);
Input = Input.drop_front(2);
}
- return true;
-}
-
-/// Convert hexadecimal string \p Input to its binary representation.
-/// The return string is half the size of \p Input.
-inline std::string fromHex(StringRef Input) {
- std::string Hex;
- bool GotHex = tryGetFromHex(Input, Hex);
- (void)GotHex;
- assert(GotHex && "Input contains non hex digits");
- return Hex;
-}
-
+ return true;
+}
+
+/// Convert hexadecimal string \p Input to its binary representation.
+/// The return string is half the size of \p Input.
+inline std::string fromHex(StringRef Input) {
+ std::string Hex;
+ bool GotHex = tryGetFromHex(Input, Hex);
+ (void)GotHex;
+ assert(GotHex && "Input contains non hex digits");
+ return Hex;
+}
+
/// Convert the string \p S to an integer of the specified type using
/// the radix \p Base. If \p Base is 0, auto-detects the radix.
/// Returns true if the number was successfully converted, false otherwise.
@@ -298,7 +298,7 @@ inline std::string utostr(uint64_t X, bool isNeg = false) {
inline std::string itostr(int64_t X) {
if (X < 0)
- return utostr(static_cast<uint64_t>(1) + ~static_cast<uint64_t>(X), true);
+ return utostr(static_cast<uint64_t>(1) + ~static_cast<uint64_t>(X), true);
else
return utostr(static_cast<uint64_t>(X));
}
@@ -391,16 +391,16 @@ inline std::string join_impl(IteratorT Begin, IteratorT End,
size_t Len = (std::distance(Begin, End) - 1) * Separator.size();
for (IteratorT I = Begin; I != End; ++I)
- Len += (*I).size();
+ Len += (*I).size();
S.reserve(Len);
- size_t PrevCapacity = S.capacity();
- (void)PrevCapacity;
+ size_t PrevCapacity = S.capacity();
+ (void)PrevCapacity;
S += (*Begin);
while (++Begin != End) {
S += Separator;
S += (*Begin);
}
- assert(PrevCapacity == S.capacity() && "String grew during building");
+ assert(PrevCapacity == S.capacity() && "String grew during building");
return S;
}
@@ -472,30 +472,30 @@ inline std::string join_items(Sep Separator, Args &&... Items) {
return Result;
}
-/// A helper class to return the specified delimiter string after the first
-/// invocation of operator StringRef(). Used to generate a comma-separated
-/// list from a loop like so:
-///
-/// \code
-/// ListSeparator LS;
-/// for (auto &I : C)
-/// OS << LS << I.getName();
-/// \end
-class ListSeparator {
- bool First = true;
- StringRef Separator;
-
-public:
- ListSeparator(StringRef Separator = ", ") : Separator(Separator) {}
- operator StringRef() {
- if (First) {
- First = false;
- return {};
- }
- return Separator;
- }
-};
-
+/// A helper class to return the specified delimiter string after the first
+/// invocation of operator StringRef(). Used to generate a comma-separated
+/// list from a loop like so:
+///
+/// \code
+/// ListSeparator LS;
+/// for (auto &I : C)
+/// OS << LS << I.getName();
+/// \end
+class ListSeparator {
+ bool First = true;
+ StringRef Separator;
+
+public:
+ ListSeparator(StringRef Separator = ", ") : Separator(Separator) {}
+ operator StringRef() {
+ if (First) {
+ First = false;
+ return {};
+ }
+ return Separator;
+ }
+};
+
} // end namespace llvm
#endif // LLVM_ADT_STRINGEXTRAS_H