llvm.org GIT mirror llvm / ca107c5
Remove llvm::EscapeString, raw_ostream::write_escaped is much faster. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84357 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 10 years ago
2 changed file(s) with 0 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
221221 /// \num (where num is a 1-3 byte octal value).
222222 void UnescapeString(std::string &Str);
223223
224 /// EscapeString - Modify the argument string, turning '\\' and anything that
225 /// doesn't satisfy std::isprint into an escape sequence.
226 void EscapeString(std::string &Str);
227
228224 /// HashString - Hash funtion for strings.
229225 ///
230226 /// This is the Bernstein hash function.
8585 }
8686 }
8787 }
88
89 /// EscapeString - Modify the argument string, turning '\\' and anything that
90 /// doesn't satisfy std::isprint into an escape sequence.
91 void llvm::EscapeString(std::string &Str) {
92 for (unsigned i = 0; i != Str.size(); ++i) {
93 if (Str[i] == '\\') {
94 ++i;
95 Str.insert(Str.begin()+i, '\\');
96 } else if (Str[i] == '\t') {
97 Str[i++] = '\\';
98 Str.insert(Str.begin()+i, 't');
99 } else if (Str[i] == '"') {
100 Str.insert(Str.begin()+i++, '\\');
101 } else if (Str[i] == '\n') {
102 Str[i++] = '\\';
103 Str.insert(Str.begin()+i, 'n');
104 } else if (!std::isprint(Str[i])) {
105 // Always expand to a 3-digit octal escape.
106 unsigned Char = Str[i];
107 Str[i++] = '\\';
108 Str.insert(Str.begin()+i++, '0'+((Char/64) & 7));
109 Str.insert(Str.begin()+i++, '0'+((Char/8) & 7));
110 Str.insert(Str.begin()+i , '0'+( Char & 7));
111 }
112 }
113 }