Introduce LineBreak.getPlatformLineBreak
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 892f13e..c9f3f4c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -5,6 +5,9 @@
</properties>
<body>
<release version="1.2-SNAPSHOT" date="in Mercurial" description="development">
+ <action dev="py4fun" type="add">
+ Introduce LineBreak.getPlatformLineBreak (2009-04-18)
+ </action>
<action dev="py4fun" type="update">
Rename LineBreak.LINUX to LineBreak.UNIX (2009-04-18)
</action>
@@ -371,9 +374,9 @@
<action dev="py4fun" type="update">
Resolver.resolve() is using simple boolean argument instead of array of booleans
as in PyYAML. (2008-11-18)
- </action>
- <action dev="py4fun" type="fix">
- Fix: 'set' type works. (2008-11-18)
+ </action>
+ <action dev="py4fun" type="fix">
+ Fix: 'set' type works. (2008-11-18)
</action>
<action dev="py4fun" type="update">
Rewrite Parser from scratch. (2008-11-17)
@@ -395,22 +398,22 @@
</action>
<action dev="py4fun" type="update">
Tag v0.3.1 (2008-11-08)
- </action>
- <action dev="py4fun" type="update">
- MappingNode requires Map as a value and SequenceNode requires
- List as a value (2008-11-08)
- </action>
- <action dev="py4fun" type="update">
- Marks in a Token are required (2008-11-08)
- </action>
- <action dev="py4fun" type="remove">
- Remove prefixForward() method from Reader because it is not present
- in PyYAML (2008-11-08)
- </action>
- <action dev="py4fun" type="fix">
- Fix a deviation with PyYAML in method scanBlockScalar().
- 'chomping' can be null. Fix a bug in JvYaml that the trailing '\n' in a
- block scalar was removed.(2008-11-07)
+ </action>
+ <action dev="py4fun" type="update">
+ MappingNode requires Map as a value and SequenceNode requires
+ List as a value (2008-11-08)
+ </action>
+ <action dev="py4fun" type="update">
+ Marks in a Token are required (2008-11-08)
+ </action>
+ <action dev="py4fun" type="remove">
+ Remove prefixForward() method from Reader because it is not present
+ in PyYAML (2008-11-08)
+ </action>
+ <action dev="py4fun" type="fix">
+ Fix a deviation with PyYAML in method scanBlockScalar().
+ 'chomping' can be null. Fix a bug in JvYaml that the trailing '\n' in a
+ block scalar was removed.(2008-11-07)
</action>
<action dev="py4fun" type="fix">
Fix a deviation with PyYAML in method scanDirectiveIgnoredLine().
diff --git a/src/main/java/org/yaml/snakeyaml/DumperOptions.java b/src/main/java/org/yaml/snakeyaml/DumperOptions.java
index 3b8caef..f254e1f 100644
--- a/src/main/java/org/yaml/snakeyaml/DumperOptions.java
+++ b/src/main/java/org/yaml/snakeyaml/DumperOptions.java
@@ -67,6 +67,16 @@
public String toString() {
return "Line break: " + name();
}
+
+ public static LineBreak getPlatformLineBreak() {
+ String platformLineBreak = System.getProperty("line.separator");
+ for (LineBreak lb : values()) {
+ if (lb.lineBreak.equals(platformLineBreak)) {
+ return lb;
+ }
+ }
+ return LineBreak.UNIX;
+ }
}
public enum Version {
diff --git a/src/test/java/org/yaml/snakeyaml/DumperOptionsTest.java b/src/test/java/org/yaml/snakeyaml/DumperOptionsTest.java
index 45ae0ed..dfa770d 100644
--- a/src/test/java/org/yaml/snakeyaml/DumperOptionsTest.java
+++ b/src/test/java/org/yaml/snakeyaml/DumperOptionsTest.java
@@ -168,6 +168,21 @@
}
}
+ public void testLineBreakForPlatform() {
+ DumperOptions.LineBreak lineBreak = DumperOptions.LineBreak.getPlatformLineBreak();
+ assertEquals("Line break must match platform's default.", System
+ .getProperty("line.separator"), lineBreak.getString());
+ //
+ Yaml yaml = new Yaml();
+ List<Integer> list = new LinkedList<Integer>();
+ list.add(1);
+ list.add(2);
+ DumperOptions options = new DumperOptions();
+ options.setLineBreak(DumperOptions.LineBreak.getPlatformLineBreak());
+ yaml = new Yaml(options);
+ assertEquals("[1, 2]", yaml.dump(list).trim());
+ }
+
public void testExplicitStart() {
Yaml yaml = new Yaml();
List<Integer> list = new LinkedList<Integer>();