llvm.org GIT mirror llvm / 10a049e
raw_ostream::write_escaped: Add a UseHexEscapes argument. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120200 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 9 years ago
2 changed file(s) with 16 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
195195
196196 /// write_escaped - Output \arg Str, turning '\\', '\t', '\n', '"', and
197197 /// anything that doesn't satisfy std::isprint into an escape sequence.
198 raw_ostream &write_escaped(StringRef Str);
198 raw_ostream &write_escaped(StringRef Str, bool UseHexEscapes = false);
199199
200200 raw_ostream &write(unsigned char C);
201201 raw_ostream &write(const char *Ptr, size_t Size);
1414 #include "llvm/Support/Format.h"
1515 #include "llvm/System/Program.h"
1616 #include "llvm/System/Process.h"
17 #include "llvm/ADT/StringExtras.h"
1718 #include "llvm/ADT/SmallVector.h"
1819 #include "llvm/Config/config.h"
1920 #include "llvm/Support/Compiler.h"
166167 return write(CurPtr, EndPtr-CurPtr);
167168 }
168169
169 raw_ostream &raw_ostream::write_escaped(StringRef Str) {
170 raw_ostream &raw_ostream::write_escaped(StringRef Str,
171 bool UseHexEscapes) {
170172 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
171173 unsigned char c = Str[i];
172174
189191 break;
190192 }
191193
192 // Always expand to a 3-character octal escape.
193 *this << '\\';
194 *this << char('0' + ((c >> 6) & 7));
195 *this << char('0' + ((c >> 3) & 7));
196 *this << char('0' + ((c >> 0) & 7));
194 // Write out the escaped representation.
195 if (UseHexEscapes) {
196 *this << '\\' << 'x';
197 *this << hexdigit((c >> 4 & 0xF));
198 *this << hexdigit((c >> 0) & 0xF);
199 } else {
200 // Always use a full 3-character octal escape.
201 *this << '\\';
202 *this << char('0' + ((c >> 6) & 7));
203 *this << char('0' + ((c >> 3) & 7));
204 *this << char('0' + ((c >> 0) & 7));
205 }
197206 }
198207 }
199208