JavaScriptCore:
[WebKit-https.git] / JavaScriptCore / kjs / function.cpp
index 294c2376b8aa0ab2d9adadc353346ec6a7ddc348..ffd611c53e9f6270deb5f23af7f19f437a32ab77 100644 (file)
@@ -918,4 +918,43 @@ JSValue *GlobalFuncImp::callAsFunction(ExecState *exec, JSObject */*thisObj*/, c
   return res;
 }
 
+UString escapeStringForPrettyPrinting(const UString& s)
+{
+    UString escapedString;
+    
+    for (int i = 0; i < s.size(); i++) {
+        unsigned short c = s.data()[i].unicode();
+        
+        switch (c) {
+        case '\"':
+            escapedString += "\\\"";
+            break;
+        case '\n':
+            escapedString += "\\n";
+            break;
+        case '\r':
+            escapedString += "\\r";
+            break;
+        case '\t':
+            escapedString += "\\t";
+            break;
+        case '\\':
+            escapedString += "\\\\";
+            break;
+        default:
+            if (c < 128 && WTF::Unicode::isPrintableChar(c))
+                escapedString.append(c);
+            else {
+                char hexValue[7];
+            
+                snprintf(hexValue, 7, "\\u%04x", c);
+                escapedString += hexValue;
+            }
+        }
+    }
+    
+    return escapedString;    
+}
+
+
 } // namespace