Skip to content

Commit ce3773c

Browse files
committed
fix XML indentation and Android issues (issue processing#1512)
1 parent cfa9e52 commit ce3773c

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

android/core/src/processing/data/XML.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -829,25 +829,23 @@ public String format(int indent) {
829829
// least the Giants are getting blown out by the Falcons.
830830

831831
final String decl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
832-
833-
// needed for splitting or when adding decl below?
834-
//System.getProperty("line.separator")
832+
final String sep = System.getProperty("line.separator");
835833

836834
StringWriter tempWriter = new StringWriter();
837835
StreamResult tempResult = new StreamResult(tempWriter);
838836
transformer.transform(new DOMSource(node), tempResult);
839-
String[] tempLines = PApplet.split(tempWriter.toString(), '\n');
840-
PApplet.println(tempLines);
841-
if (tempLines[0].startsWith(decl)) {
837+
String[] tempLines = PApplet.split(tempWriter.toString(), sep);
838+
// PApplet.println(tempLines);
839+
if (tempLines[0].startsWith("<?xml")) {
842840
// Remove XML declaration from the top before slamming into one line
843841
int declEnd = tempLines[0].indexOf("?>") + 2;
844842
//if (tempLines[0].length() == decl.length()) {
845843
if (tempLines[0].length() == declEnd) {
846844
// If it's all the XML declaration, remove it
847-
PApplet.println("removing first line");
845+
// PApplet.println("removing first line");
848846
tempLines = PApplet.subset(tempLines, 1);
849847
} else {
850-
PApplet.println("removing part of first line");
848+
// PApplet.println("removing part of first line");
851849
// If the first node has been moved to this line, be more careful
852850
//tempLines[0] = tempLines[0].substring(decl.length());
853851
tempLines[0] = tempLines[0].substring(declEnd);
@@ -866,7 +864,7 @@ public String format(int indent) {
866864
// DOMSource source = new DOMSource(node);
867865
Source source = new StreamSource(new StringReader(singleLine));
868866
transformer.transform(source, xmlOutput);
869-
return decl + "\n" + stringWriter.toString();
867+
return decl + sep + stringWriter.toString();
870868
// return xmlOutput.getWriter().toString();
871869

872870
} catch (Exception e) {

core/src/processing/data/XML.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -829,25 +829,23 @@ public String format(int indent) {
829829
// least the Giants are getting blown out by the Falcons.
830830

831831
final String decl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
832-
833-
// needed for splitting or when adding decl below?
834-
//System.getProperty("line.separator")
832+
final String sep = System.getProperty("line.separator");
835833

836834
StringWriter tempWriter = new StringWriter();
837835
StreamResult tempResult = new StreamResult(tempWriter);
838836
transformer.transform(new DOMSource(node), tempResult);
839-
String[] tempLines = PApplet.split(tempWriter.toString(), '\n');
840-
PApplet.println(tempLines);
841-
if (tempLines[0].startsWith(decl)) {
837+
String[] tempLines = PApplet.split(tempWriter.toString(), sep);
838+
// PApplet.println(tempLines);
839+
if (tempLines[0].startsWith("<?xml")) {
842840
// Remove XML declaration from the top before slamming into one line
843841
int declEnd = tempLines[0].indexOf("?>") + 2;
844842
//if (tempLines[0].length() == decl.length()) {
845843
if (tempLines[0].length() == declEnd) {
846844
// If it's all the XML declaration, remove it
847-
PApplet.println("removing first line");
845+
// PApplet.println("removing first line");
848846
tempLines = PApplet.subset(tempLines, 1);
849847
} else {
850-
PApplet.println("removing part of first line");
848+
// PApplet.println("removing part of first line");
851849
// If the first node has been moved to this line, be more careful
852850
//tempLines[0] = tempLines[0].substring(decl.length());
853851
tempLines[0] = tempLines[0].substring(declEnd);
@@ -866,7 +864,7 @@ public String format(int indent) {
866864
// DOMSource source = new DOMSource(node);
867865
Source source = new StreamSource(new StringReader(singleLine));
868866
transformer.transform(source, xmlOutput);
869-
return decl + "\n" + stringWriter.toString();
867+
return decl + sep + stringWriter.toString();
870868
// return xmlOutput.getWriter().toString();
871869

872870
} catch (Exception e) {

core/todo.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ o 3) we deprecate our nice short getFloat/getInt/etc and go with
8787
o getXxxxAttribute() and getXxxxContent() methods.
8888
X not gonna do getFloatContent() since it's not really any shorter
8989
X beginning slash in getChild() threw an NPE
90-
_ XML.format(0) throws error
91-
_ http://code.google.com/p/processing/issues/detail?id=1512
90+
X XML.format(0) throws error
91+
X http://code.google.com/p/processing/issues/detail?id=1512
92+
X fix XML problems on Android as well
9293

9394
decisions on data
9495
X are we comfortable with setInt/Float/etc instead of just set(int, blah)

0 commit comments

Comments
 (0)