diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -1583,7 +1583,7 @@ if (isInstantiation()) { // The instantiations are typedefs that drop the "basic_" prefix. assert(SV.startsWith("basic_")); - SV = SV.dropFront(sizeof("basic_") - 1); + SV = SV.substr(sizeof("basic_") - 1); } return SV; } @@ -1838,7 +1838,7 @@ OB += "0"; } else if (Offset[0] == 'n') { OB += "-"; - OB += Offset.dropFront(); + OB += Offset.substr(1); } else { OB += Offset; } @@ -2264,7 +2264,7 @@ OB.printClose(); if (Integer[0] == 'n') - OB << "-" << Integer.dropFront(1); + OB << '-' << Integer.substr(1); else OB << Integer; } @@ -2287,10 +2287,9 @@ OB.printClose(); } - if (Value[0] == 'n') { - OB += '-'; - OB += Value.dropFront(1); - } else + if (Value[0] == 'n') + OB << '-' << Value.substr(1); + else OB += Value; if (Type.size() <= 3) @@ -2632,7 +2631,7 @@ if (Kind < Unnameable) { assert(Res.startsWith("operator") && "operator name does not start with 'operator'"); - Res = Res.dropFront(sizeof("operator") - 1); + Res = Res.substr(sizeof("operator") - 1); Res.consumeFront(' '); } return Res; @@ -3706,7 +3705,7 @@ // extension ::= U # objc-type if (Qual.startsWith("objcproto")) { - StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto")); + StringView ProtoSourceName = Qual.substr(std::strlen("objcproto")); StringView Proto; { ScopedOverride SaveFirst(First, ProtoSourceName.begin()), diff --git a/llvm/include/llvm/Demangle/StringView.h b/llvm/include/llvm/Demangle/StringView.h --- a/llvm/include/llvm/Demangle/StringView.h +++ b/llvm/include/llvm/Demangle/StringView.h @@ -55,12 +55,6 @@ return npos; } - StringView dropFront(size_t N = 1) const { - if (N >= size()) - N = size(); - return StringView(First + N, Last); - } - void remove_prefix(size_t N) { assert(size() >= N); First += N; @@ -69,6 +63,11 @@ assert(size() >= N); Last -= N; } + StringView dropBack(size_t N = 1) const { + if (N >= size()) + N = size(); + return StringView(First, Last - N); + } char front() const { assert(!empty()); @@ -88,14 +87,14 @@ bool consumeFront(char C) { if (!startsWith(C)) return false; - *this = dropFront(1); + *this = substr(1); return true; } bool consumeFront(StringView S) { if (!startsWith(S)) return false; - *this = dropFront(S.size()); + *this = substr(S.size()); return true; } diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp --- a/llvm/lib/Demangle/MicrosoftDemangle.cpp +++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp @@ -168,11 +168,11 @@ // ambiguity is also why single digit encoded numbers use 0-9 rather than A-J. if (Candidate[0] < 'B' || Candidate[0] > 'P') return false; - Candidate.remove_prefix(1); + Candidate = Candidate.substr(1); while (!Candidate.empty()) { if (Candidate[0] < 'A' || Candidate[0] > 'P') return false; - Candidate.remove_prefix(1); + Candidate = Candidate.substr(1); } return true; @@ -486,7 +486,7 @@ IdentifierNode * Demangler::demangleFunctionIdentifierCode(StringView &MangledName) { assert(MangledName.startsWith('?')); - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); if (MangledName.empty()) { Error = true; return nullptr; @@ -765,7 +765,7 @@ return nullptr; } const char *Start = MangledName.begin(); - MangledName = MangledName.dropFront(MD5Last + 1); + MangledName = MangledName.substr(MD5Last + 1); // There are two additional special cases for MD5 names: // 1. For complete object locators where the object name is long enough @@ -902,7 +902,7 @@ if (startsWithDigit(MangledName)) { uint64_t Ret = MangledName[0] - '0' + 1; - MangledName = MangledName.dropFront(1); + MangledName = MangledName.substr(1); return {Ret, IsNegative}; } @@ -910,7 +910,7 @@ for (size_t i = 0; i < MangledName.size(); ++i) { char C = MangledName[i]; if (C == '@') { - MangledName = MangledName.dropFront(i + 1); + MangledName = MangledName.substr(i + 1); return {Ret, IsNegative}; } if ('A' <= C && C <= 'P') { @@ -965,7 +965,7 @@ return nullptr; } - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); return Backrefs.Names[I]; } @@ -1036,7 +1036,7 @@ if (!MangledName.startsWith('?')) return MangledName.popFront(); - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); if (MangledName.empty()) goto CharLiteralError; @@ -1050,14 +1050,14 @@ // Don't append the null terminator. uint8_t C1 = rebasedHexDigitToNumber(Nibbles[0]); uint8_t C2 = rebasedHexDigitToNumber(Nibbles[1]); - MangledName = MangledName.dropFront(2); + MangledName = MangledName.substr(2); return (C1 << 4) | C2; } if (startsWithDigit(MangledName)) { const char *Lookup = ",/\\:. \n\t'-"; char C = Lookup[MangledName[0] - '0']; - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); return C; } @@ -1067,7 +1067,7 @@ '\xEF', '\xF0', '\xF1', '\xF2', '\xF3', '\xF4', '\xF5', '\xF6', '\xF7', '\xF8', '\xF9', '\xFA'}; char C = Lookup[MangledName[0] - 'a']; - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); return C; } @@ -1077,7 +1077,7 @@ '\xCF', '\xD0', '\xD1', '\xD2', '\xD3', '\xD4', '\xD5', '\xD6', '\xD7', '\xD8', '\xD9', '\xDA'}; char C = Lookup[MangledName[0] - 'A']; - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); return C; } @@ -1310,7 +1310,7 @@ if (CrcEndPos == StringView::npos) goto StringLiteralError; CRC = MangledName.substr(0, CrcEndPos); - MangledName = MangledName.dropFront(CrcEndPos + 1); + MangledName = MangledName.substr(CrcEndPos + 1); if (MangledName.empty()) goto StringLiteralError; @@ -1391,7 +1391,7 @@ if (i == 0) break; S = MangledName.substr(0, i); - MangledName = MangledName.dropFront(i + 1); + MangledName = MangledName.substr(i + 1); if (Memorize) memorizeString(S); @@ -2124,7 +2124,7 @@ Error = true; return nullptr; } - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); *Current = Arena.alloc(); (*Current)->N = Backrefs.FunctionParams[N]; @@ -2206,7 +2206,7 @@ TP.N = TPRN = Arena.alloc(); TPRN->IsMemberPointer = true; - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); // 1 - single inheritance // H - multiple inheritance // I - virtual inheritance @@ -2252,7 +2252,7 @@ TP.N = TPRN = Arena.alloc(); // Data member pointer. - MangledName.remove_prefix(1); + MangledName = MangledName.substr(1); char InheritanceSpecifier = MangledName.popFront(); switch (InheritanceSpecifier) {