aboutsummaryrefslogtreecommitdiff
path: root/strutil.cc
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2015-08-21 11:13:28 -0700
committerDan Willemsen <dwillemsen@google.com>2015-08-25 13:25:21 -0700
commite6f6858860e28b4336ae5d64d42b5080a6fbe4c1 (patch)
tree9a6f05480920bd82fd412ecd2e122b7f59994389 /strutil.cc
parentfcd7a98b3008c518a063140530366fc1ef57c0f1 (diff)
[C++] Fix newlines in $(info/warning/error)
Change-Id: Ia20a1ef563a6871ed843b9388fe27e87b8bd7020
Diffstat (limited to 'strutil.cc')
-rw-r--r--strutil.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/strutil.cc b/strutil.cc
index ea5d633..defb292 100644
--- a/strutil.cc
+++ b/strutil.cc
@@ -427,3 +427,24 @@ string ConcatDir(StringPiece b, StringPiece n) {
NormalizePath(&r);
return r;
}
+
+string EchoEscape(const string str) {
+ const char *in = str.c_str();
+ string buf;
+ for (; *in; in++) {
+ switch(*in) {
+ case '\\':
+ buf += "\\\\\\\\";
+ break;
+ case '\n':
+ buf += "\\n";
+ break;
+ case '"':
+ buf += "\\\"";
+ break;
+ default:
+ buf += *in;
+ }
+ }
+ return buf;
+}