Skip to content

Commit 7d11ece

Browse files
committed
add trim() method to XML (removes #text nodes)
1 parent 02a2002 commit 7d11ece

3 files changed

Lines changed: 65 additions & 8 deletions

File tree

core/src/processing/data/XML.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import javax.xml.transform.*;
3434
import javax.xml.transform.dom.*;
3535
import javax.xml.transform.stream.*;
36+
import javax.xml.xpath.XPathConstants;
37+
import javax.xml.xpath.XPathExpression;
38+
import javax.xml.xpath.XPathFactory;
3639

3740
import processing.core.PApplet;
3841

@@ -582,6 +585,25 @@ public void removeChild(XML kid) {
582585
}
583586

584587

588+
public void trim() {
589+
try {
590+
XPathFactory xpathFactory = XPathFactory.newInstance();
591+
XPathExpression xpathExp =
592+
xpathFactory.newXPath().compile("//text()[normalize-space(.) = '']");
593+
NodeList emptyTextNodes = (NodeList)
594+
xpathExp.evaluate(node, XPathConstants.NODESET);
595+
596+
// Remove each empty text node from document.
597+
for (int i = 0; i < emptyTextNodes.getLength(); i++) {
598+
Node emptyTextNode = emptyTextNodes.item(i);
599+
emptyTextNode.getParentNode().removeChild(emptyTextNode);
600+
}
601+
} catch (Exception e) {
602+
throw new RuntimeException(e);
603+
}
604+
}
605+
606+
585607
// /** Remove whitespace nodes. */
586608
// public void trim() {
587609
////// public static boolean isWhitespace(XML xml) {

core/todo.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
0230 core (3.0a3)
22
X add another NaN check when sorting FloatList/Dict classes
33
X if all values were NaN, an ArrayIndexOutOfBoundsException was thrown
4+
X PShape for JAVA2D
5+
X https://github.com/processing/processing/pull/2756
6+
X add trim() method to the XML library
7+
8+
andres
9+
X maximizing window leads to erroneous mouse coordinates
10+
X https://github.com/processing/processing/issues/2562
411

512
earlier
613
X PShape disableStyle() does not work with createShape()
@@ -16,7 +23,8 @@ X Drawing RECT PShape with rounded corners crashes the sketch
1623
X https://github.com/processing/processing/issues/2648
1724
X Corrected a typo in Tessellator#addQuadraticVertex()
1825
X https://github.com/processing/processing/pull/2649
19-
26+
X fix tiny typo in Table writeHTML()
27+
X https://github.com/processing/processing/pull/2773
2028

2129
applet/component
2230
_ remove Applet as base class
@@ -32,6 +40,7 @@ _ make sure it works with retina/canvas/strategy as well
3240

3341

3442
processing.data
43+
_ lots of 'data' changes down below
3544
_ need a better method for "missing" data in Table
3645
_ if missing int is zero, can't just remove those values from saving a table
3746
_ but for NaN values, it's a necessity
@@ -86,6 +95,8 @@ _ draw(s) doesn't work on the returned PShape
8695
hidpi
8796
_ Text is half size in PGraphicsRetina2D
8897
_ https://github.com/processing/processing/issues/2738
98+
_ text not getting the correct font in Retina2D
99+
_ https://github.com/processing/processing/issues/2617
89100
_ saveFrame() with retina render is making black images
90101
_ zero alpha values still a problem with retina renderer
91102
_ https://github.com/processing/processing/issues/2030
@@ -100,7 +111,6 @@ _ no high-dpi support for core on Windows
100111
_ https://github.com/processing/processing/issues/2411
101112
_ retina sketches slow to start
102113
_ https://github.com/processing/processing/issues/2357
103-
_ glw? lwjgl? retina jogl?
104114
_ Text looks blurry in GL Retina
105115
_ https://github.com/processing/processing/issues/2739
106116

todo.txt

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ X fixes for mode/tool installation
1616
X https://github.com/processing/processing/pull/2705
1717
X fix mode updating to work properly
1818
X https://github.com/processing/processing/issues/2579
19-
X temp folders not always deleting
19+
X contrib manager temp folders not always deleting
2020
X https://github.com/processing/processing/issues/2606
2121
X problem when removing a mode
2222
X https://github.com/processing/processing/issues/2507
2323
X autocompletion dialog box sticking
2424
X https://github.com/processing/processing/issues/2741
2525
X Line warning indicators next to scrollbar break after moving around text
2626
X https://github.com/processing/processing/issues/2655
27+
X Code completion generates wrong code
28+
X https://github.com/processing/processing/issues/2753
29+
X Code completion: Hide overloaded methods unless inside parentheses
30+
X https://github.com/processing/processing/issues/2755
31+
X Close auto-completion suggestion box when deleting/backspacing code
32+
X https://github.com/processing/processing/issues/2757
2733
_ remove dependency on oscp5 library for tweak mode
2834
_ https://github.com/processing/processing/issues/2730
2935

@@ -57,6 +63,28 @@ X https://github.com/processing/processing/issues/2654
5763
X https://github.com/processing/processing/pull/2674
5864
X Style completion panel when using Nimbus LAF
5965
X https://github.com/processing/processing/pull/2718
66+
X enums not supported properly
67+
X https://github.com/processing/processing/issues/1390
68+
X http://code.google.com/p/processing/issues/detail?id=1352
69+
X https://github.com/processing/processing/pull/2774
70+
X combining char/int/etc casts in one statement causes preproc trouble
71+
X https://github.com/processing/processing/issues/1936
72+
X https://github.com/processing/processing/pull/2772
73+
X Update contributions.* strings to contrib
74+
X https://github.com/processing/processing/pull/2770
75+
X Style completion panel on windows
76+
X https://github.com/processing/processing/pull/2762
77+
X Update Spanish language strings
78+
X https://github.com/processing/processing/pull/2769
79+
X make --output optional in the command line version
80+
X https://github.com/processing/processing/pull/1866
81+
X https://github.com/processing/processing/issues/1855
82+
X https://github.com/processing/processing/issues/1816
83+
X Fix unneeded scroll bar display in code completion suggestion box
84+
X https://github.com/processing/processing/pull/2763
85+
86+
_ PDE erroneously detects changes in non-sketch files
87+
_ https://github.com/processing/processing/issues/2759
6088

6189
languages
6290
X Japanese https://github.com/processing/processing/pull/2688
@@ -388,13 +416,8 @@ _ it's never useful. students can use { } if they want an empty block
388416
_ missing brackets, unmatched brackets
389417
_ examples added to the bug report
390418
_ http://code.google.com/p/processing/issues/detail?id=6
391-
_ enums not supported properly
392-
_ https://github.com/processing/processing/issues/1390
393-
X http://code.google.com/p/processing/issues/detail?id=1352
394419

395420
low (features)
396-
_ combining char/int/etc casts in one statement causes preproc trouble
397-
_ https://github.com/processing/processing/issues/1936
398421
_ copy running code from /tmp/buildXXxxx on crash of p5
399422
_ should probably make a way to save/recover code
400423
_ make the buildXxxx folders relate to time/date?
@@ -429,6 +452,8 @@ _ http://code.google.com/p/processing/issues/detail?id=8
429452

430453
PDE / Editor
431454

455+
_ clean up /tmp folders used during build
456+
_ https://github.com/processing/processing/issues/1896
432457
_ 'recent' menu doesn't respect examples folder of other p5 versions
433458
_ could write that into the file, that it's an example
434459
_ or write the path as shown in the PDE to the file as simpler

0 commit comments

Comments
 (0)