skslc can now be compiled with no Skia dependencies, in preparation for its eventual

This reverts commit 9bd301d640ff63c280b202c7dd00bc00a3315ff4.

Bug: skia:
Change-Id: I5ad3f77ef33aa5ce2fd27fe383c9339c571663a1
Reviewed-on: https://skia-review.googlesource.com/10964
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLStringStream.h b/src/sksl/SkSLStringStream.h
new file mode 100644
index 0000000..9061432
--- /dev/null
+++ b/src/sksl/SkSLStringStream.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SKSL_STRINGSTREAM
+#define SKSL_STRINGSTREAM
+
+#include "SkSLOutputStream.h"
+
+#ifdef SKSL_STANDALONE
+
+namespace SkSL {
+
+class StringStream : public OutputStream {
+public:
+    void write8(uint8_t b) override {
+        fBuffer += (char) b;
+    }
+
+    void writeText(const char* s) override {
+        fBuffer += s;
+    }
+
+    void write(const void* s, size_t size) override {
+        fBuffer.append((const char*) s, size);
+    }
+
+    const char* data() const {
+        return fBuffer.c_str();
+    }
+
+    size_t size() const {
+        return fBuffer.size();
+    }
+
+    void reset() {
+        fBuffer = "";
+    }
+
+private:
+    String fBuffer;
+};
+
+#else
+
+#include "SkData.h"
+#include "SkStream.h"
+
+namespace SkSL {
+
+class StringStream : public OutputStream {
+public:
+    void write8(uint8_t b) override {
+        SkASSERT(!fData);
+        fStream.write8(b);
+    }
+
+    void writeText(const char* s) override {
+        SkASSERT(!fData);
+        fStream.writeText(s);
+    }
+
+    void write(const void* s, size_t size) override {
+        SkASSERT(!fData);
+        fStream.write(s, size);
+    }
+
+    const char* data() const {
+        if (!fData) {
+            fData = fStream.detachAsData();
+        }
+        return (const char*) fData->data();
+    }
+
+    size_t size() const {
+        if (!fData) {
+            fData = fStream.detachAsData();
+        }
+        return fData->size();
+    }
+
+    void reset() {
+        fStream.reset();
+        fData = nullptr;
+    }
+
+private:
+    mutable SkDynamicMemoryWStream fStream;
+    mutable sk_sp<SkData> fData;
+};
+
+#endif // SKSL_STANDALONE
+
+} // namespace
+
+#endif