@@ -203,6 +203,8 @@ struct ItemLayoutStackEntry
203
203
size_t additionalContinuationIndentation;
204
204
size_t desiredWidth;
205
205
size_t desiredContinuationWidth;
206
+ size_t desiredStringWidth;
207
+ size_t desiredStringContinuationWidth;
206
208
bool newLineOnReenteringScope;
207
209
};
208
210
@@ -318,7 +320,18 @@ static vector<InstructionTextToken> ParseStringToken(
318
320
ConstructToken (start, curEnd);
319
321
curStart = curEnd;
320
322
}
321
- else if (c == ' ,' || c == ' .' || c == ' :' || c == ' ;' || isspace (c))
323
+ else if (isspace (c))
324
+ {
325
+ // Flush before whitespace
326
+ flushToken (curStart, curEnd);
327
+
328
+ size_t start = curEnd;
329
+ while (curEnd < tail && isspace (src[curEnd]))
330
+ curEnd++;
331
+ ConstructToken (start, curEnd);
332
+ curStart = curEnd;
333
+ }
334
+ else if (c == ' ,' || c == ' .' || c == ' :' || c == ' ;' )
322
335
{
323
336
// Flush before punctuation
324
337
flushToken (curStart, curEnd);
@@ -731,6 +744,24 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
731
744
desiredContinuationWidth = remainingWidth;
732
745
}
733
746
747
+ // Compute target string width for this line
748
+ size_t desiredStringWidth = settings.stringWrappingWidth ;
749
+ if (indentation < settings.desiredLineLength )
750
+ {
751
+ size_t remainingStringWidth = desiredStringWidth - indentation;
752
+ if (remainingStringWidth > desiredStringWidth)
753
+ desiredStringWidth = remainingStringWidth;
754
+ }
755
+
756
+ // Compute target width for continuation string wrapping lines
757
+ size_t desiredStringContinuationWidth = settings.stringWrappingWidth ;
758
+ if (continuationIndentation < settings.desiredLineLength )
759
+ {
760
+ size_t remainingStringWidth = desiredStringContinuationWidth - continuationIndentation;
761
+ if (remainingStringWidth > desiredStringContinuationWidth)
762
+ desiredStringContinuationWidth = remainingStringWidth;
763
+ }
764
+
734
765
// Gather the indentation tokens at the beginning of the line
735
766
vector<InstructionTextToken> indentationTokens = currentLine.GetAddressAndIndentationTokens ();
736
767
size_t tokenIndex = indentationTokens.size ();
@@ -831,7 +862,7 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
831
862
string trimmedSubText = TrimString (subToken.text );
832
863
if (trimmedSubText.empty ())
833
864
items.push_back (Item {StringWhitespace, {}, {subToken}, 0 });
834
- if (trimmedSubText[0 ] == ' %' )
865
+ else if (trimmedSubText[0 ] == ' %' )
835
866
items.push_back (Item {FormatSpecifier, {}, {subToken}, 0 });
836
867
else if (!trimmedSubText.empty () && trimmedSubText[0 ] == ' \\ ' )
837
868
items.push_back (Item {EscapeSequence, {}, {subToken}, 0 });
@@ -892,7 +923,7 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
892
923
bool firstTokenOfLine = true ;
893
924
894
925
stack<ItemLayoutStackEntry> layoutStack;
895
- layoutStack.push ({items, additionalContinuationIndentation, desiredWidth, desiredContinuationWidth, false });
926
+ layoutStack.push ({items, additionalContinuationIndentation, desiredWidth, desiredContinuationWidth, desiredStringWidth, desiredStringContinuationWidth, false });
896
927
897
928
auto newLine = [&]() {
898
929
if (!firstTokenOfLine)
@@ -917,6 +948,7 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
917
948
outputLine.tokens .emplace_back (TextToken, string (additionalContinuationIndentation, ' ' ));
918
949
currentWidth = 0 ;
919
950
desiredWidth = desiredContinuationWidth;
951
+ desiredStringWidth = desiredStringContinuationWidth;
920
952
firstTokenOfLine = true ;
921
953
};
922
954
@@ -929,6 +961,8 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
929
961
additionalContinuationIndentation = layoutStackEntry.additionalContinuationIndentation ;
930
962
desiredWidth = layoutStackEntry.desiredWidth ;
931
963
desiredContinuationWidth = layoutStackEntry.desiredContinuationWidth ;
964
+ desiredStringWidth = layoutStackEntry.desiredStringWidth ;
965
+ desiredStringContinuationWidth = layoutStackEntry.desiredStringContinuationWidth ;
932
966
933
967
// Check to see if the scope we are returning to needs a new line. This is used when an argument
934
968
// spans multiple lines. The rest of the arguments are placed on separate lines from the long argument.
@@ -937,13 +971,14 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
937
971
938
972
for (auto item = items.begin (); item != items.end ();)
939
973
{
940
- if (item->type == StringComponent && currentWidth + item->width > desiredWidth )
974
+ if (item->type == StringComponent && currentWidth + item->width > desiredStringWidth )
941
975
{
942
976
// If a string is too wide to fit on the current line, create a newline
943
977
// without additional indentation
944
978
newLine ();
979
+ continue ;
945
980
}
946
- else if (currentWidth + item->width > desiredWidth && item->type != StringWhitespace)
981
+ if (currentWidth + item->width > desiredWidth && item->type != StringWhitespace)
947
982
{
948
983
// Current item is too wide to fit on the current line, will need to start a new line.
949
984
// Whitespace is allowed to be too wide; we push it on as the preceding word is wrapped.
@@ -962,7 +997,7 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
962
997
if (next != items.end ())
963
998
{
964
999
layoutStack.push ({vector (next, items.end ()), additionalContinuationIndentation,
965
- desiredWidth, desiredContinuationWidth, true });
1000
+ desiredWidth, desiredContinuationWidth, desiredStringWidth, desiredStringContinuationWidth, true });
966
1001
}
967
1002
968
1003
newLine ();
@@ -973,8 +1008,13 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
973
1008
else
974
1009
desiredContinuationWidth -= settings.tabWidth ;
975
1010
1011
+ if (desiredStringContinuationWidth < settings.minimumContentLength + settings.tabWidth )
1012
+ desiredStringContinuationWidth = settings.minimumContentLength ;
1013
+ else
1014
+ desiredStringContinuationWidth -= settings.tabWidth ;
1015
+
976
1016
layoutStack.push ({item->items , additionalContinuationIndentation, desiredWidth,
977
- desiredContinuationWidth, false });
1017
+ desiredContinuationWidth, desiredStringWidth, desiredStringContinuationWidth, false });
978
1018
break ;
979
1019
}
980
1020
@@ -984,10 +1024,10 @@ vector<DisassemblyTextLine> GenericLineFormatter::FormatLines(
984
1024
if (next != items.end ())
985
1025
{
986
1026
layoutStack.push ({vector (next, items.end ()), additionalContinuationIndentation,
987
- desiredWidth, desiredContinuationWidth, false });
1027
+ desiredWidth, desiredContinuationWidth, desiredStringWidth, desiredStringContinuationWidth, false });
988
1028
}
989
1029
layoutStack.push ({item->items , additionalContinuationIndentation, desiredWidth,
990
- desiredContinuationWidth, false });
1030
+ desiredContinuationWidth, desiredStringWidth, desiredStringContinuationWidth, false });
991
1031
break ;
992
1032
}
993
1033
0 commit comments