}
int indent = (bFirstLine ? settings_.firstLineIndent() : settings_.indent());
bool bContinuation = (lineEnd < inputLength && input[lineEnd - 1] != '\n');
- // Strip trailing whitespace.
- if (!settings_.bKeepFinalSpaces_ || lineEnd < inputLength || input[inputLength - 1] == '\n')
+ // Remove explicit line breaks in input
+ // (the returned line should not contain line breaks).
+ while (lineEnd > lineStart && input[lineEnd - 1] == '\n')
+ {
+ --lineEnd;
+ }
+ // Strip trailing whitespace, unless they are explicit in the input and it
+ // has been requested to keep them.
+ if (bContinuation || !settings_.bKeepFinalSpaces_)
{
while (lineEnd > lineStart && std::isspace(input[lineEnd - 1]))
{
A quick brown
fox jumps
over the lazy
+dog]]></String>
+ <String Name="WrappedAt14WithTrailingWhitespace"><![CDATA[
+ A quick brown
+fox jumps
+ over the lazy
dog]]></String>
</ReferenceData>
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <String Name="Output"><![CDATA[
+Line
+Line
+Line
+Line
+Line
+Line
+]]></String>
+</ReferenceData>
wrapper.settings().setKeepFinalSpaces(true);
EXPECT_EQ("line ", wrapper.wrapToString("line "));
- EXPECT_EQ("line\n", wrapper.wrapToString("line \n"));
+ EXPECT_EQ("line \n", wrapper.wrapToString("line \n"));
}
TEST_F(TextLineWrapperTest, HandlesTrailingNewlines)
checkText(wrapper.wrapToString(g_wrapTextWhitespace),
"WrappedAt14");
+
+ wrapper.settings().setKeepFinalSpaces(true);
+ checkText(wrapper.wrapToString(g_wrapTextWhitespace),
+ "WrappedAt14WithTrailingWhitespace");
}
} // namespace
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015, by the GROMACS development team, led by
+ * Copyright (c) 2015,2017, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
checkOutput();
}
+TEST_F(TextWriterTest, PreservesTrailingWhitespace)
+{
+ writer_.writeString("Line ");
+ writer_.writeLine();
+ writer_.writeString(std::string("Line "));
+ writer_.writeLine();
+ writer_.writeLine("Line ");
+ writer_.writeLine(std::string("Line "));
+ writer_.writeString("Line \n");
+ writer_.writeString(std::string("Line \n"));
+ checkOutput();
+}
+
} // namespace