Index: libcxxabi/src/demangle/Utility.h =================================================================== --- libcxxabi/src/demangle/Utility.h +++ libcxxabi/src/demangle/Utility.h @@ -14,6 +14,7 @@ #define DEMANGLE_UTILITY_H #include "StringView.h" +#include "llvm/Demangle/MicrosoftDemangleNodes.h" #include #include #include @@ -93,6 +94,23 @@ return *this; } + OutputString prepend(StringView R) + { + char *TempBuffer; + size_t Size = R.size(); + + if (Size != 0) { + grow(Size); + for (TempBuffer = (Buffer + CurrentPosition) - 1; TempBuffer >= Buffer; --TempBuffer) { + TempBuffer[Size] = TempBuffer[0]; + } + std::memcpy(Buffer, R.begin(), Size); + CurrentPosition += Size; + } + + return *this; + } + OutputString &operator<<(StringView R) { return (*this += R); } OutputString &operator<<(char C) { return (*this += C); } Index: llvm/include/llvm/Demangle/Utility.h =================================================================== --- llvm/include/llvm/Demangle/Utility.h +++ llvm/include/llvm/Demangle/Utility.h @@ -14,6 +14,7 @@ #define DEMANGLE_UTILITY_H #include "StringView.h" +#include "llvm/Demangle/MicrosoftDemangleNodes.h" #include #include #include @@ -93,6 +94,23 @@ return *this; } + OutputString prepend(StringView R) + { + char *TempBuffer; + size_t Size = R.size(); + + if (Size != 0) { + grow(Size); + for (TempBuffer = (Buffer + CurrentPosition) - 1; TempBuffer >= Buffer; --TempBuffer) { + TempBuffer[Size] = TempBuffer[0]; + } + std::memcpy(Buffer, R.begin(), Size); + CurrentPosition += Size; + } + + return *this; + } + OutputString &operator<<(StringView R) { return (*this += R); } OutputString &operator<<(char C) { return (*this += C); } Index: llvm/unittests/Demangle/OutputStringTest.cpp =================================================================== --- llvm/unittests/Demangle/OutputStringTest.cpp +++ llvm/unittests/Demangle/OutputStringTest.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Demangle/MicrosoftDemangleNodes.h" #include "llvm/Demangle/Utility.h" #include "gtest/gtest.h" #include @@ -59,3 +60,12 @@ std::free(OS.getBuffer()); } + +TEST(OutputStringTest, Prepend) +{ + OutputString OS; + + OS << "abc"; + OS.prepend("def"); + EXPECT_EQ("defabc", toString(OS)); +}