Skip to content

Commit

Permalink
Support arguments in single quotes at CsvSource (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Oct 19, 2024
1 parent 5368196 commit 99ee636
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/main/java/gr/uom/java/xmi/util/CsvUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@
public class CsvUtils {
public static List<String> extractParametersFromCsv(String s) {
List<String> parameters = new ArrayList<>();
String[] tokens = s.split(",");
for (String token : tokens) {
String trimmed = token.trim();
if (trimmed.startsWith("\"")) {
trimmed = trimmed.substring(1, trimmed.length());
}
if (trimmed.endsWith("\"")) {
trimmed = trimmed.substring(0, trimmed.length() - 1);
}
parameters.add(trimmed);
//fix for arguments with single quotes
if(s.contains("'")) {
String[] tokens = s.split("'");
for (String token : tokens) {
if(!token.equals("\"") && !token.matches("\s*,\s*")) {
parameters.add(token);
}
}
}
else {
String[] tokens = s.split(",");
for (String token : tokens) {
String trimmed = token.trim();
if (trimmed.startsWith("\"")) {
trimmed = trimmed.substring(1, trimmed.length());
}
if (trimmed.endsWith("\"")) {
trimmed = trimmed.substring(0, trimmed.length() - 1);
}
parameters.add(trimmed);
}
}
return parameters;
}
Expand Down

0 comments on commit 99ee636

Please sign in to comment.