Use PrintableString in oatdump.

And enhance PrintableString to assume modified UTF-8, which is all we ever give
it. \u0000 is more readable than \xc0\x80 to most people.

Change-Id: I45bd8d65694eda0ef4ef03abc40f41a76f07a671
diff --git a/src/utils.cc b/src/utils.cc
index 127c18f..e80de5b 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -404,6 +404,31 @@
   }
 }
 
+std::string PrintableString(const std::string& utf) {
+  std::string result;
+  result += '"';
+  const char* p = utf.c_str();
+  size_t char_count = CountModifiedUtf8Chars(p);
+  for (size_t i = 0; i < char_count; ++i) {
+    uint16_t ch = GetUtf16FromUtf8(&p);
+    if (ch == '\\') {
+      result += "\\\\";
+    } else if (ch == '\n') {
+      result += "\\n";
+    } else if (ch == '\r') {
+      result += "\\r";
+    } else if (ch == '\t') {
+      result += "\\t";
+    } else if (NeedsEscaping(ch)) {
+      StringAppendF(&result, "\\u%04x", ch);
+    } else {
+      result += ch;
+    }
+  }
+  result += '"';
+  return result;
+}
+
 // See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules.
 std::string MangleForJni(const std::string& s) {
   std::string result;