Fix filename-escaping for Windows paths.

Change-Id: I0070d0f96093490c664545cd61a42137e374798f
diff --git a/slang_rs_reflection.cpp b/slang_rs_reflection.cpp
index c13689e..772545b 100644
--- a/slang_rs_reflection.cpp
+++ b/slang_rs_reflection.cpp
@@ -263,6 +263,17 @@
   return "";
 }
 
+// Replace all instances of "\" with "\\" in a single string to prevent
+// formatting errors due to unicode.
+static std::string SanitizeString(std::string s) {
+  size_t p = 0;
+  while ( ( p = s.find('\\', p)) != std::string::npos) {
+    s.replace(p, 1, "\\\\");
+    p+=2;
+  }
+  return s;
+}
+
 
 /********************** Methods to generate script class **********************/
 bool RSReflection::genScriptClass(Context &C,
@@ -2096,7 +2107,7 @@
 /************************** RSReflection::Context **************************/
 const char *const RSReflection::Context::ApacheLicenseNote =
     "/*\n"
-    " * Copyright (C) 2011-2012 The Android Open Source Project\n"
+    " * Copyright (C) 2011-2013 The Android Open Source Project\n"
     " *\n"
     " * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
     " * you may not use this file except in compliance with the License.\n"
@@ -2163,7 +2174,8 @@
   // Notice of generated file
   out() << "/*" << std::endl;
   out() << " * This file is auto-generated. DO NOT MODIFY!" << std::endl;
-  out() << " * The source Renderscript file: " << mInputRSFile << std::endl;
+  out() << " * The source Renderscript file: "
+        << SanitizeString(mInputRSFile) << std::endl;
   out() << " */" << std::endl;
 
   // Package
diff --git a/tests/P_str_escape/stderr.txt.expect b/tests/P_str_escape/stderr.txt.expect
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/P_str_escape/stderr.txt.expect
diff --git a/tests/P_str_escape/stdout.txt.expect b/tests/P_str_escape/stdout.txt.expect
new file mode 100644
index 0000000..fd90090
--- /dev/null
+++ b/tests/P_str_escape/stdout.txt.expect
@@ -0,0 +1 @@
+Generating ScriptC_strescape.java ...
diff --git "a/tests/P_str_escape/str\\\\escape.rs" "b/tests/P_str_escape/str\\\\escape.rs"
new file mode 100644
index 0000000..b2072d5
--- /dev/null
+++ "b/tests/P_str_escape/str\\\\escape.rs"
@@ -0,0 +1,2 @@
+#pragma version(1)
+#pragma rs java_package_name(foo)