[demangler] Add StringView conversion operator
The OutputBuffer class tries to present a NUL-terminated string API to
consumers. But several of them would prefer a StringView. In
particular the Microsoft demangler, juggles between NUL-terminated and
StringView, which is confusing.
This adds a StringView conversion, and adjusts the Demanglers that can
benefit from that.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D120990
GitOrigin-RevId: 1066e397fa907629f0da370f9721821c838ed30a
diff --git a/src/demangle/Utility.h b/src/demangle/Utility.h
index 7633085..1390f14 100644
--- a/src/demangle/Utility.h
+++ b/src/demangle/Utility.h
@@ -75,6 +75,8 @@
OutputBuffer(const OutputBuffer &) = delete;
OutputBuffer &operator=(const OutputBuffer &) = delete;
+ operator StringView() const { return StringView(Buffer, CurrentPosition); }
+
void reset(char *Buffer_, size_t BufferCapacity_) {
CurrentPosition = 0;
Buffer = Buffer_;