|
@@ -446,7 +446,8 @@ bool Output::outputting() {
|
|
|
|
|
|
void Output::beginMapping() {
|
|
|
StateStack.push_back(inMapFirstKey);
|
|
|
- NeedsNewLine = true;
|
|
|
+ PaddingBeforeContainer = Padding;
|
|
|
+ Padding = "\n";
|
|
|
}
|
|
|
|
|
|
bool Output::mapTag(StringRef Tag, bool Use) {
|
|
@@ -474,7 +475,7 @@ bool Output::mapTag(StringRef Tag, bool Use) {
|
|
|
}
|
|
|
// Tags inside maps in sequences should act as keys in the map from a
|
|
|
// formatting perspective, so we always want a newline in a sequence.
|
|
|
- NeedsNewLine = true;
|
|
|
+ Padding = "\n";
|
|
|
}
|
|
|
}
|
|
|
return Use;
|
|
@@ -482,8 +483,12 @@ bool Output::mapTag(StringRef Tag, bool Use) {
|
|
|
|
|
|
void Output::endMapping() {
|
|
|
// If we did not map anything, we should explicitly emit an empty map
|
|
|
- if (StateStack.back() == inMapFirstKey)
|
|
|
+ if (StateStack.back() == inMapFirstKey) {
|
|
|
+ Padding = PaddingBeforeContainer;
|
|
|
+ newLineCheck();
|
|
|
output("{}");
|
|
|
+ Padding = "\n";
|
|
|
+ }
|
|
|
StateStack.pop_back();
|
|
|
}
|
|
|
|
|
@@ -548,14 +553,19 @@ void Output::endDocuments() {
|
|
|
|
|
|
unsigned Output::beginSequence() {
|
|
|
StateStack.push_back(inSeqFirstElement);
|
|
|
- NeedsNewLine = true;
|
|
|
+ PaddingBeforeContainer = Padding;
|
|
|
+ Padding = "\n";
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
void Output::endSequence() {
|
|
|
// If we did not emit anything, we should explicitly emit an empty sequence
|
|
|
- if (StateStack.back() == inSeqFirstElement)
|
|
|
+ if (StateStack.back() == inSeqFirstElement) {
|
|
|
+ Padding = PaddingBeforeContainer;
|
|
|
+ newLineCheck();
|
|
|
output("[]");
|
|
|
+ Padding = "\n";
|
|
|
+ }
|
|
|
StateStack.pop_back();
|
|
|
}
|
|
|
|
|
@@ -746,7 +756,7 @@ void Output::outputUpToEndOfLine(StringRef s) {
|
|
|
output(s);
|
|
|
if (StateStack.empty() || (!inFlowSeqAnyElement(StateStack.back()) &&
|
|
|
!inFlowMapAnyKey(StateStack.back())))
|
|
|
- NeedsNewLine = true;
|
|
|
+ Padding = "\n";
|
|
|
}
|
|
|
|
|
|
void Output::outputNewLine() {
|
|
@@ -759,11 +769,13 @@ void Output::outputNewLine() {
|
|
|
//
|
|
|
|
|
|
void Output::newLineCheck() {
|
|
|
- if (!NeedsNewLine)
|
|
|
+ if (Padding != "\n") {
|
|
|
+ output(Padding);
|
|
|
+ Padding = {};
|
|
|
return;
|
|
|
- NeedsNewLine = false;
|
|
|
-
|
|
|
+ }
|
|
|
outputNewLine();
|
|
|
+ Padding = {};
|
|
|
|
|
|
if (StateStack.size() == 0)
|
|
|
return;
|
|
@@ -797,9 +809,9 @@ void Output::paddedKey(StringRef key) {
|
|
|
output(":");
|
|
|
const char *spaces = " ";
|
|
|
if (key.size() < strlen(spaces))
|
|
|
- output(&spaces[key.size()]);
|
|
|
+ Padding = &spaces[key.size()];
|
|
|
else
|
|
|
- output(" ");
|
|
|
+ Padding = " ";
|
|
|
}
|
|
|
|
|
|
void Output::flowKey(StringRef Key) {
|