diff --git a/CSVLintNppPlugin/CsvLint/CsvDefinition.cs b/CSVLintNppPlugin/CsvLint/CsvDefinition.cs index 6450cfc..85b0593 100644 --- a/CSVLintNppPlugin/CsvLint/CsvDefinition.cs +++ b/CSVLintNppPlugin/CsvLint/CsvDefinition.cs @@ -979,7 +979,7 @@ public int SkipCommentLinesAtStart(StreamReader strdata) /// when editing, sorting or copying a data file, also copy the first comment lines /// /// csv data - public void CopyCommentLinesAtStart(StreamReader strdata, StringBuilder sb, string prefix) + public void CopyCommentLinesAtStart(StreamReader strdata, StringBuilder sb, string prefix, string CRLF) { // how many lines of comment to skip int skip = (this.SkipLines >= 0 ? this.SkipLines : 0); @@ -992,7 +992,7 @@ public void CopyCommentLinesAtStart(StreamReader strdata, StringBuilder sb, stri // copy and add prefix and line feed sb.Append(prefix); sb.Append(line); - sb.Append("\n"); + sb.Append(CRLF); skip--; } diff --git a/CSVLintNppPlugin/CsvLint/CsvEdit.cs b/CSVLintNppPlugin/CsvLint/CsvEdit.cs index e94b0c8..bf5ba06 100644 --- a/CSVLintNppPlugin/CsvLint/CsvEdit.cs +++ b/CSVLintNppPlugin/CsvLint/CsvEdit.cs @@ -91,6 +91,16 @@ public static string RemoveQuotesToString(string strinput) return res; } + private static string getEditorEOLchars(EndOfLine EOL) + { + switch (EOL) + { + case EndOfLine.CR: return "\r"; + case EndOfLine.LF: return "\n"; + default: return "\r\n"; // default is EndOfLine.CRLF + } + } + /// /// reformat file for date, decimal and separator /// @@ -129,6 +139,7 @@ public static void ReformatDataFile(CsvDefinition csvdef, string reformatSeparat // handle to editor ScintillaGateway scintillaGateway = PluginBase.CurrentScintillaGateway; + var CRLF = getEditorEOLchars(scintillaGateway.GetEOLMode()); // use stringreader to go line by line var strdata = ScintillaStreams.StreamAllText(); @@ -155,7 +166,7 @@ public static void ReformatDataFile(CsvDefinition csvdef, string reformatSeparat } // copy any comment lines - csvdef.CopyCommentLinesAtStart(strdata, datanew, ""); + csvdef.CopyCommentLinesAtStart(strdata, datanew, "", CRLF); // read all lines while (!strdata.EndOfStream) @@ -266,7 +277,7 @@ public static void ReformatDataFile(CsvDefinition csvdef, string reformatSeparat }; // add line break - datanew.Append("\n"); + datanew.Append(CRLF); }; } @@ -450,6 +461,7 @@ public static void ConvertToSQL(CsvDefinition csvdef) if (enumcols1 != "") sb.Append(string.Format("-- Enumeration columns (optional)\r\n/*\r\n{0}{1}*/\r\n", enumcols1, enumcols2)); // add comment table + comment.Insert(0, "Table imported using"); var tabcomment = string.Join("\r\n", comment).Replace("'", "''"); sb.Append("-- Table comment\r\n"); switch (Main.Settings.DataConvertSQL) @@ -475,7 +487,7 @@ public static void ConvertToSQL(CsvDefinition csvdef) int lastend = -1; // last line end character // copy any comment lines - csvdef.CopyCommentLinesAtStart(strdata, sb, "-- "); + csvdef.CopyCommentLinesAtStart(strdata, sb, "-- ", "\r\n"); while (!strdata.EndOfStream) { @@ -663,7 +675,7 @@ public static void ConvertToXML(CsvDefinition csvdef) // copy any comment lines if (csvdef.SkipLines > 0) { sb.Append("\t\n"); } @@ -1013,6 +1025,10 @@ public static void SortData(CsvDefinition csvdef, int SortIdx, bool AscDesc, boo return; } + // handle to editor + ScintillaGateway scintillaGateway = PluginBase.CurrentScintillaGateway; + var CRLF = getEditorEOLchars(scintillaGateway.GetEOLMode()); + // examine data and keep list of all data lines // Note: can be a dictionary, not a list, because the sortable values are guaranteed to be unique Dictionary sortlines = new Dictionary(); @@ -1031,7 +1047,7 @@ public static void SortData(CsvDefinition csvdef, int SortIdx, bool AscDesc, boo StringBuilder sbsort = new StringBuilder(); // copy any comment lines - csvdef.CopyCommentLinesAtStart(strdata, sbsort, ""); + csvdef.CopyCommentLinesAtStart(strdata, sbsort, "", CRLF); // if first line is header column names if (csvdef.ColNameHeader) { @@ -1040,7 +1056,7 @@ public static void SortData(CsvDefinition csvdef, int SortIdx, bool AscDesc, boo sbsort.Append(csvdef.ConstructLine(values, iscomm)); - sbsort.Append("\n"); + sbsort.Append(CRLF); } string sortval = ""; @@ -1084,11 +1100,10 @@ public static void SortData(CsvDefinition csvdef, int SortIdx, bool AscDesc, boo // add all lines, sort by count foreach (KeyValuePair rec in sortlines) { - sbsort.Append(string.Format("{0}\n", rec.Value)); + sbsort.Append(string.Format("{0}{1}", rec.Value, CRLF)); } // update text in editor - ScintillaGateway scintillaGateway = PluginBase.CurrentScintillaGateway; scintillaGateway.SetText(sbsort.ToString()); } @@ -1101,6 +1116,7 @@ public static void ColumnSplit(CsvDefinition csvdef, int ColumnIndex, int SplitC { // handle to editor ScintillaGateway scintillaGateway = PluginBase.CurrentScintillaGateway; + var CRLF = getEditorEOLchars(scintillaGateway.GetEOLMode()); // use stringreader to go line by line var strdata = ScintillaStreams.StreamAllText(); @@ -1161,7 +1177,7 @@ public static void ColumnSplit(CsvDefinition csvdef, int ColumnIndex, int SplitC } // copy any comment lines - csvdef.CopyCommentLinesAtStart(strdata, datanew, ""); + csvdef.CopyCommentLinesAtStart(strdata, datanew, "", CRLF); // list for building new columns List newcols = new List(); @@ -1180,7 +1196,7 @@ public static void ColumnSplit(CsvDefinition csvdef, int ColumnIndex, int SplitC datanew.Append(csvnew.ConstructLine(newcols, false)); - datanew.Append("\n"); + datanew.Append(CRLF); } // read all lines @@ -1324,7 +1340,7 @@ public static void ColumnSplit(CsvDefinition csvdef, int ColumnIndex, int SplitC datanew.Append(csvnew.ConstructLine(newcols, iscomm)); // add line break - datanew.Append("\n"); + datanew.Append(CRLF); } }; diff --git a/CSVLintNppPlugin/bin/Release-x64/CSVLint.dll b/CSVLintNppPlugin/bin/Release-x64/CSVLint.dll index 2d96012..2e3a87d 100644 Binary files a/CSVLintNppPlugin/bin/Release-x64/CSVLint.dll and b/CSVLintNppPlugin/bin/Release-x64/CSVLint.dll differ diff --git a/CSVLintNppPlugin/bin/Release/CSVLint.dll b/CSVLintNppPlugin/bin/Release/CSVLint.dll index dc6615c..c065387 100644 Binary files a/CSVLintNppPlugin/bin/Release/CSVLint.dll and b/CSVLintNppPlugin/bin/Release/CSVLint.dll differ