14
14
#include " llvm/ADT/StringMap.h"
15
15
#include " llvm/Support/FormatVariadic.h"
16
16
#include " llvm/Support/raw_ostream.h"
17
- #include < cctype>
18
17
#include < optional>
19
18
20
19
namespace llvm {
@@ -32,16 +31,15 @@ class StringToOffsetTable {
32
31
size_t size () const { return AggregateString.size (); }
33
32
34
33
unsigned GetOrAddStringOffset (StringRef Str, bool appendZero = true ) {
35
- auto IterBool =
36
- StringOffset.insert (std::make_pair (Str, AggregateString.size ()));
37
- if (IterBool.second ) {
34
+ auto [II, Inserted] = StringOffset.insert ({Str, size ()});
35
+ if (Inserted) {
38
36
// Add the string to the aggregate if this is the first time found.
39
37
AggregateString.append (Str.begin (), Str.end ());
40
38
if (appendZero)
41
39
AggregateString += ' \0 ' ;
42
40
}
43
41
44
- return IterBool. first ->second ;
42
+ return II ->second ;
45
43
}
46
44
47
45
// Returns the offset of `Str` in the table if its preset, else return
@@ -78,37 +76,35 @@ class StringToOffsetTable {
78
76
}
79
77
80
78
// Emit the string as one single string.
81
- void EmitString (raw_ostream &O) {
79
+ void EmitString (raw_ostream &O) const {
82
80
// Escape the string.
83
- SmallString<256 > Str;
84
- raw_svector_ostream (Str).write_escaped (AggregateString);
85
- AggregateString = std::string (Str);
81
+ SmallString<256 > EscapedStr;
82
+ raw_svector_ostream (EscapedStr).write_escaped (AggregateString);
86
83
87
84
O << " \" " ;
88
85
unsigned CharsPrinted = 0 ;
89
- for (unsigned i = 0 , e = AggregateString .size (); i != e; ++i) {
86
+ for (unsigned i = 0 , e = EscapedStr .size (); i != e; ++i) {
90
87
if (CharsPrinted > 70 ) {
91
88
O << " \"\n \" " ;
92
89
CharsPrinted = 0 ;
93
90
}
94
- O << AggregateString [i];
91
+ O << EscapedStr [i];
95
92
++CharsPrinted;
96
93
97
94
// Print escape sequences all together.
98
- if (AggregateString [i] != ' \\ ' )
95
+ if (EscapedStr [i] != ' \\ ' )
99
96
continue ;
100
97
101
- assert (i + 1 < AggregateString.size () && " Incomplete escape sequence!" );
102
- if (isdigit (AggregateString[i + 1 ])) {
103
- assert (isdigit (AggregateString[i + 2 ]) &&
104
- isdigit (AggregateString[i + 3 ]) &&
98
+ assert (i + 1 < EscapedStr.size () && " Incomplete escape sequence!" );
99
+ if (isDigit (EscapedStr[i + 1 ])) {
100
+ assert (isDigit (EscapedStr[i + 2 ]) && isDigit (EscapedStr[i + 3 ]) &&
105
101
" Expected 3 digit octal escape!" );
106
- O << AggregateString [++i];
107
- O << AggregateString [++i];
108
- O << AggregateString [++i];
102
+ O << EscapedStr [++i];
103
+ O << EscapedStr [++i];
104
+ O << EscapedStr [++i];
109
105
CharsPrinted += 3 ;
110
106
} else {
111
- O << AggregateString [++i];
107
+ O << EscapedStr [++i];
112
108
++CharsPrinted;
113
109
}
114
110
}
0 commit comments