Skip to content

Commit c4eb502

Browse files
committed
Takes the default separator into account in save CSV files
1 parent a56f8b0 commit c4eb502

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Diff for: msi.gama.core/src/msi/gaml/statements/save/CSVSaver.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*******************************************************************************************************
22
*
3-
* CSVSaver.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform (v.1.9.2).
3+
* CSVSaver.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform (v.2.0.0).
44
*
55
* (c) 2007-2023 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
66
*
7-
* Visit https://github.com/gama-platform/gama for license information and contacts.
7+
* Visit https://github.com/gama-platform/gama2 for license information and contacts.
88
*
99
********************************************************************************************************/
1010
package msi.gaml.statements.save;
@@ -23,6 +23,7 @@
2323
import msi.gama.runtime.exceptions.GamaRuntimeException;
2424
import msi.gama.util.GamaListFactory;
2525
import msi.gama.util.IList;
26+
import msi.gama.util.file.csv.AbstractCSVManipulator;
2627
import msi.gama.util.matrix.GamaMatrix;
2728
import msi.gaml.descriptions.SpeciesDescription;
2829
import msi.gaml.expressions.IExpression;
@@ -144,12 +145,12 @@ private void save(final IScope scope, final Writer fw, final boolean header, fin
144145
}
145146
if (itemType.id() == IType.MATRIX) {
146147
GamaMatrix<?> matrix = (GamaMatrix) value;
147-
matrix.rowByRow(scope, v -> fw.write(toCleanString(v)), () -> fw.write(","),
148-
() -> fw.write(Strings.LN));
148+
matrix.rowByRow(scope, v -> fw.write(toCleanString(v)),
149+
() -> fw.write(AbstractCSVManipulator.getDefaultDelimiter()), () -> fw.write(Strings.LN));
149150
} else {
150151
final int size = values.size();
151152
for (int i = 0; i < size; i++) {
152-
if (i > 0) { fw.write(','); }
153+
if (i > 0) { fw.write(AbstractCSVManipulator.getDefaultDelimiter()); }
153154
fw.write(toCleanString(values.get(i)));
154155
}
155156
}
@@ -172,6 +173,7 @@ private void save(final IScope scope, final Writer fw, final boolean header, fin
172173
* @return the string
173174
*/
174175
private String toCleanString(final Object o) {
176+
// Verify this (shouldn't we use AbstractCSVManipulator.getDefaultDelimiter() ?)
175177
String val = Cast.toGaml(o).replace(';', ',');
176178
if (val.startsWith("'") && val.endsWith("'") || val.startsWith("\"") && val.endsWith("\"")) {
177179
val = val.substring(1, val.length() - 1);

0 commit comments

Comments
 (0)