re-land of switched skslc from std::string to SkString

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5084

Change-Id: Ib21c30afc0d8483392b417e660b7fecfcc30e617
Reviewed-on: https://skia-review.googlesource.com/5084
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp
index 3658992..d9fc814 100644
--- a/src/sksl/SkSLMain.cpp
+++ b/src/sksl/SkSLMain.cpp
@@ -10,13 +10,6 @@
 #include "SkSLCompiler.h"
 #include "GrContextOptions.h"
 
-bool endsWith(const std::string& s, const std::string& ending) {
-    if (s.length() >= ending.length()) {
-        return (0 == s.compare(s.length() - ending.length(), ending.length(), ending));
-    }
-    return false;
-}
-
 /**
  * Very simple standalone executable to facilitate testing.
  */
@@ -37,35 +30,36 @@
     }
 
     std::ifstream in(argv[1]);
-    std::string text((std::istreambuf_iterator<char>(in)),
-                     std::istreambuf_iterator<char>());
+    std::string stdText((std::istreambuf_iterator<char>(in)),
+                        std::istreambuf_iterator<char>());
+    SkString text(stdText.c_str());
     if (in.rdstate()) {
         printf("error reading '%s'\n", argv[1]);
         exit(2);
     }
-    std::string name(argv[2]);
-    if (endsWith(name, ".spirv")) {
-        std::ofstream out(argv[2], std::ofstream::binary);
+    SkString name(argv[2]);
+    if (name.endsWith(".spirv")) {
+        SkFILEWStream out(argv[2]);
         SkSL::Compiler compiler;
+        if (!out.isValid()) {
+            printf("error writing '%s'\n", argv[2]);
+            exit(4);
+        }
         if (!compiler.toSPIRV(kind, text, out)) {
             printf("%s", compiler.errorText().c_str());
             exit(3);
         }
-        if (out.rdstate()) {
+    } else if (name.endsWith(".glsl")) {
+        SkFILEWStream out(argv[2]);
+        SkSL::Compiler compiler;
+        if (!out.isValid()) {
             printf("error writing '%s'\n", argv[2]);
             exit(4);
         }
-    } else if (endsWith(name, ".glsl")) {
-        std::ofstream out(argv[2], std::ofstream::binary);
-        SkSL::Compiler compiler;
         if (!compiler.toGLSL(kind, text, *SkSL::GLSLCapsFactory::Default(), out)) {
             printf("%s", compiler.errorText().c_str());
             exit(3);
         }
-        if (out.rdstate()) {
-            printf("error writing '%s'\n", argv[2]);
-            exit(4);
-        }
     } else {
         printf("expected output filename to end with '.spirv' or '.glsl'");
     }