Skip to content

Commit

Permalink
CsvPlainText: Export now strips spaces at the end of the line
Browse files Browse the repository at this point in the history
When exporting, often there may be strings of long spaces, which makes for spurious diffs. Now all lines are trimmed before exporting and appended with a new line.

Issue: DOTNET-167
  • Loading branch information
jcurl committed Sep 14, 2018
1 parent a9c0288 commit 063c869
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions EAExport/Model/CsvDoorsTreeExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ private void ExportElement(EATree element, bool includeElement, string parentId)
if (includeElement) {
string heading = (element.Heading == null) ? string.Empty : element.Heading.Trim();
string text = (element.Text == null) ? string.Empty : element.Text.Trim();
m_Writer.WriteLine("{0};{1};\"{2}\";\"{3}\"",
m_Writer.WriteLine("{0};{1};\"{2}\";\"{3}\"",
element.Id, parentId,
StringUtilities.SearchAndReplace(heading, m_Conversions),
StringUtilities.SearchAndReplace(heading, m_Conversions),
StringUtilities.SearchAndReplace(text, m_Conversions));
}

Expand Down
17 changes: 16 additions & 1 deletion EAExport/Model/CsvDoorsTreePlainExport.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace EAExport.Model
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using HtmlAgilityPack;
Expand Down Expand Up @@ -121,6 +122,20 @@ private string ConvertHtmlToPlainText(HtmlFormatPlainText format, string text)
html.LoadHtml(text);
ParseHtml(format, html.DocumentNode, sb);

return TrimLines(sb.ToString());
}

private string TrimLines(string text)
{
string[] lines = text.Split(new char[] { '\n' });

StringBuilder sb = new StringBuilder();
bool firstLine = true;
foreach (string line in lines) {
if (!firstLine) sb.Append('\n');
sb.Append(line.TrimEnd());
firstLine = false;
}
return sb.ToString();
}

Expand All @@ -147,7 +162,7 @@ private void ParseHtml(HtmlFormatPlainText format, HtmlNode node, StringBuilder
// Is it in fact a special closing node output as text?
break;
}

sb.Append(HtmlEntity.DeEntitize(html));
break;
case HtmlNodeType.Element:
Expand Down
4 changes: 2 additions & 2 deletions EAExport/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: AssemblyVersion("1.5.2.0")]
[assembly: AssemblyFileVersion("1.5.2.0")]
6 changes: 3 additions & 3 deletions EAExportUnitTest/CsvDoorsTreePlainExportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public void BothLists1()
Assert.That(sr.ReadLine(), Is.EqualTo(string.Empty));
Assert.That(sr.ReadLine(), Is.EqualTo(string.Empty));
Assert.That(sr.ReadLine(), Is.EqualTo(string.Empty));
Assert.That(sr.ReadLine(), Is.EqualTo("\t 1. Ordered List "));
Assert.That(sr.ReadLine(), Is.EqualTo("\t 1. Ordered List"));
Assert.That(sr.ReadLine(), Is.EqualTo(string.Empty));
Assert.That(sr.ReadLine(), Is.EqualTo("(Note we really wanted nested lists, but EA doesn't seem to let this happen)\""));
Assert.That(sr.ReadLine(), Is.Null);
Expand Down Expand Up @@ -441,8 +441,8 @@ public void BothLists2()
Assert.That(sr.ReadLine(), Is.EqualTo("EAPK_A34D21F7_B624_4f82_B6FD_DD6E60EAD764;;\"TC45-BothLists2\";\"\""));
Assert.That(sr.ReadLine(), Is.EqualTo("EAID_2EF736C4_FD48_472f_84E6_5FA4E0CC65BE;EAPK_A34D21F7_B624_4f82_B6FD_DD6E60EAD764;\"Requirement1\";\""));
Assert.That(sr.ReadLine(), Is.EqualTo("\t * Itemized List 1"));
Assert.That(sr.ReadLine(), Is.EqualTo("\t * "));
Assert.That(sr.ReadLine(), Is.EqualTo("\t * "));
Assert.That(sr.ReadLine(), Is.EqualTo("\t *"));
Assert.That(sr.ReadLine(), Is.EqualTo("\t *"));
Assert.That(sr.ReadLine(), Is.EqualTo("\t * Itemized List 2"));
Assert.That(sr.ReadLine(), Is.EqualTo("\t * Itemized List 3"));
Assert.That(sr.ReadLine(), Is.EqualTo(string.Empty));
Expand Down

0 comments on commit 063c869

Please sign in to comment.