diff --git a/core/.classpath b/core/.classpath index c14d2909c..7b26f669d 100644 --- a/core/.classpath +++ b/core/.classpath @@ -27,7 +27,6 @@ - diff --git a/core/OpenRocket Core.iml b/core/OpenRocket Core.iml index 436fabf47..ece044f8a 100644 --- a/core/OpenRocket Core.iml +++ b/core/OpenRocket Core.iml @@ -134,24 +134,6 @@ - - - - - - - - - - - - - - - - - - diff --git a/core/lib/commons-text-1.10.0.jar b/core/lib/commons-text-1.10.0.jar deleted file mode 100644 index beada0274..000000000 Binary files a/core/lib/commons-text-1.10.0.jar and /dev/null differ diff --git a/core/src/net/sf/openrocket/util/StringUtils.java b/core/src/net/sf/openrocket/util/StringUtils.java index cf94b1a2c..92e866f78 100644 --- a/core/src/net/sf/openrocket/util/StringUtils.java +++ b/core/src/net/sf/openrocket/util/StringUtils.java @@ -1,5 +1,7 @@ package net.sf.openrocket.util; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class StringUtils { @@ -65,5 +67,35 @@ public class StringUtils { return Double.parseDouble(input); } + + /** + * Returns an escaped version of the String so that it can be safely used as a value in a CSV file. + * The goal is to surround the input string in double quotes if it contains any double quotes, commas, + * newlines, or carriage returns, and to escape any double quotes within the string by doubling them up. + * @param input the string to escape + * @return the escaped string that can be safely used in a CSV file + */ + public static String escapeCSV(String input) { + final List CSV_SEARCH_CHARS = new ArrayList<>(Arrays.asList(',', '"', '\r', '\n')); + + StringBuilder sb = new StringBuilder(); + boolean quoted = false; + for (int i = 0; i < input.length(); i++) { + char c = input.charAt(i); + if (CSV_SEARCH_CHARS.contains(c)) { + quoted = true; + sb.append('\"'); + } + if (c == '\"') { + sb.append('\"'); + } + sb.append(c); + } + if (quoted) { + sb.insert(0, '\"'); + sb.append('\"'); + } + return sb.toString(); + } } diff --git a/swing/.classpath b/swing/.classpath index d337ce0b8..d57e69a4c 100644 --- a/swing/.classpath +++ b/swing/.classpath @@ -32,7 +32,6 @@ - diff --git a/swing/OpenRocket Swing.iml b/swing/OpenRocket Swing.iml index 62a27d717..c9df46ca4 100644 --- a/swing/OpenRocket Swing.iml +++ b/swing/OpenRocket Swing.iml @@ -254,24 +254,6 @@ - - - - - - - - - - - - - - - - - - diff --git a/swing/build.xml b/swing/build.xml index 1f9315b43..d1945c272 100644 --- a/swing/build.xml +++ b/swing/build.xml @@ -117,7 +117,6 @@ - diff --git a/swing/src/net/sf/openrocket/file/SimulationTableCSVExport.java b/swing/src/net/sf/openrocket/file/SimulationTableCSVExport.java index 260eac1b7..279ccd09a 100644 --- a/swing/src/net/sf/openrocket/file/SimulationTableCSVExport.java +++ b/swing/src/net/sf/openrocket/file/SimulationTableCSVExport.java @@ -11,7 +11,6 @@ import javax.swing.JOptionPane; import javax.swing.JTable; import net.sf.openrocket.util.StringUtils; -import org.apache.commons.text.StringEscapeUtils; import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.aerodynamics.WarningSet; @@ -144,7 +143,7 @@ public class SimulationTableCSVExport { } else { valueString = o.toString(); } - rowColumnElement.add(StringEscapeUtils.escapeCsv(valueString)); + rowColumnElement.add(StringUtils.escapeCSV(valueString)); } else { rowColumnElement.add(""); nullCnt++; diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index 11418713b..cd88a003b 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -81,9 +81,6 @@ import net.sf.openrocket.utils.TableRowTraversalPolicy; @SuppressWarnings("serial") public class SimulationPanel extends JPanel { - private static final String SPACE = "SPACE"; - private static final String TAB = "TAB"; - private static final Logger log = LoggerFactory.getLogger(SimulationPanel.class); private static final Translator trans = Application.getTranslator();