Add raw_stream adaptors that write into an std::string and SmallVector/SmallString.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55265 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 9827ca7..b9beac2 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -268,3 +268,38 @@
OS.write(OutBufStart, OutBufCur-OutBufStart);
HandleFlush();
}
+
+//===----------------------------------------------------------------------===//
+// raw_string_ostream
+//===----------------------------------------------------------------------===//
+
+raw_string_ostream::~raw_string_ostream() {
+ flush();
+}
+
+/// flush_impl - The is the piece of the class that is implemented by
+/// subclasses. This outputs the currently buffered data and resets the
+/// buffer to empty.
+void raw_string_ostream::flush_impl() {
+ if (OutBufCur-OutBufStart)
+ OS.append(OutBufStart, OutBufCur-OutBufStart);
+ HandleFlush();
+}
+
+//===----------------------------------------------------------------------===//
+// raw_svector_ostream
+//===----------------------------------------------------------------------===//
+
+raw_svector_ostream::~raw_svector_ostream() {
+ flush();
+}
+
+/// flush_impl - The is the piece of the class that is implemented by
+/// subclasses. This outputs the currently buffered data and resets the
+/// buffer to empty.
+void raw_svector_ostream::flush_impl() {
+ if (OutBufCur-OutBufStart)
+ OS.append(OutBufStart, OutBufCur);
+ HandleFlush();
+}
+