@@ -280,12 +280,15 @@ static vector<InstructionTextToken> ParseStringToken(
280
280
vector<InstructionTextToken> result;
281
281
size_t curStart = 0 , curEnd = 0 ;
282
282
283
+ string scratch;
284
+ scratch.reserve (maxParsingLength);
285
+
283
286
auto ConstructToken = [&](size_t start, size_t end) {
287
+ scratch.assign (src.data () + start, end - start);
284
288
InstructionTextToken token = unprocessedStringToken;
285
- const string newTxt = string (src.substr (start, end - start));
286
- token.text = newTxt;
287
- token.width = newTxt.size ();
288
- result.emplace_back (token);
289
+ token.text .swap (scratch);
290
+ token.width = token.text .size ();
291
+ result.emplace_back (std::move (token));
289
292
};
290
293
291
294
auto flushToken = [&](size_t start, size_t end)
@@ -791,7 +794,7 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
791
794
{
792
795
case BraceToken:
793
796
// Beginning of string
794
- if (trimmedText == " \" " && currentLine.tokens [tokenIndex + 1 ].type == StringToken)
797
+ if (trimmedText == " \" " && tokenIndex + 1 <= currentLine. tokens . size () && currentLine.tokens [tokenIndex + 1 ].type == StringToken)
795
798
{
796
799
// Create a ContainerContents item and place it onto the item stack. This will hold anything
797
800
// inside the container once the end of the container is found.
@@ -803,7 +806,7 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
803
806
items.push_back (Item {StartOfContainer, {}, {token}, 0 });
804
807
}
805
808
// End of string
806
- else if (trimmedText == " \" " && currentLine.tokens [tokenIndex - 1 ].type == StringToken)
809
+ else if (trimmedText == " \" " && tokenIndex > 0 && currentLine.tokens [tokenIndex - 1 ].type == StringToken)
807
810
{
808
811
items.push_back (Item {EndOfContainer, {}, {token}, 0 });
809
812
@@ -940,7 +943,7 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
940
943
stack<ItemLayoutStackEntry> layoutStack;
941
944
layoutStack.push ({items, additionalContinuationIndentation, desiredWidth, desiredContinuationWidth, desiredStringWidth, false });
942
945
943
- auto newLine = [&](bool forString = false ) {
946
+ auto newLine = [&](const bool forString = false ) {
944
947
if (!firstTokenOfLine)
945
948
{
946
949
string lastTokenText = outputLine.tokens .back ().text ;
@@ -990,10 +993,26 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
990
993
{
991
994
if (item->type == StringComponent && currentWidth + item->width > desiredStringWidth)
992
995
{
993
- // If a string is too wide to fit on the current line, create a newline
994
- // without additional indentation
996
+ auto next = item;
997
+ ++next;
998
+
999
+ if (next != items.end ())
1000
+ {
1001
+ layoutStack.push ({vector (next, items.end ()), additionalContinuationIndentation,
1002
+ desiredWidth, desiredContinuationWidth, desiredStringWidth, false });
1003
+ }
1004
+
995
1005
newLine (true );
996
- continue ;
1006
+
1007
+ additionalContinuationIndentation += settings.tabWidth ;
1008
+ if (desiredContinuationWidth < settings.minimumContentLength + settings.tabWidth )
1009
+ desiredContinuationWidth = settings.minimumContentLength ;
1010
+ else
1011
+ desiredContinuationWidth -= settings.tabWidth ;
1012
+
1013
+ layoutStack.push ({item->items , additionalContinuationIndentation, desiredWidth,
1014
+ desiredContinuationWidth, desiredStringWidth, false });
1015
+ break ;
997
1016
}
998
1017
if (currentWidth + item->width > desiredWidth && item->type != StringWhitespace && item->type != StringComponent)
999
1018
{
0 commit comments