Skip to content

Commit cbf030d

Browse files
committed
simplify code
1 parent 7ff1640 commit cbf030d

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

src/main/java/org/htmlunit/xpath/functions/FuncNormalizeSpace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public class FuncNormalizeSpace extends FunctionDef1Arg {
2929
public XObject execute(final XPathContext xctxt) throws javax.xml.transform.TransformerException {
3030
final XString s1 = getArg0AsString(xctxt);
3131

32-
return s1.fixWhiteSpace(true, true, false);
32+
return s1.fixWhiteSpace();
3333
}
3434
}

src/main/java/org/htmlunit/xpath/objects/XString.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,11 @@ private static boolean isSpace(final char ch) {
396396

397397
/**
398398
* Conditionally trim all leading and trailing whitespace in the specified String. All strings of
399-
* white space are replaced by a single space character (#x20), except spaces after punctuation
400-
* which receive double spaces if doublePunctuationSpaces is true. This function may be useful to
401-
* a formatter, but to get first class results, the formatter should probably do it's own white
402-
* space handling based on the semantics of the formatting object.
399+
* white space are replaced by a single space character (#x20), except spaces after punctuation.
403400
*
404-
* @param trimHead Trim leading whitespace?
405-
* @param trimTail Trim trailing whitespace?
406-
* @param doublePunctuationSpaces Use double spaces for punctuation?
407401
* @return The trimmed string.
408402
*/
409-
public XString fixWhiteSpace(
410-
final boolean trimHead, final boolean trimTail, final boolean doublePunctuationSpaces) {
403+
public XString fixWhiteSpace() {
411404

412405
// %OPT% !!!!!!!
413406
final int len = this.length();
@@ -439,16 +432,7 @@ public XString fixWhiteSpace(
439432

440433
buf[d++] = ' ';
441434

442-
if (doublePunctuationSpaces && (s != 0)) {
443-
final char prevChar = buf[s - 1];
444-
445-
if (!((prevChar == '.') || (prevChar == '!') || (prevChar == '?'))) {
446-
pres = true;
447-
}
448-
}
449-
else {
450-
pres = true;
451-
}
435+
pres = true;
452436
}
453437
else {
454438
edit = true;
@@ -461,15 +445,15 @@ public XString fixWhiteSpace(
461445
}
462446
}
463447

464-
if (trimTail && 1 <= d && ' ' == buf[d - 1]) {
448+
if (1 <= d && ' ' == buf[d - 1]) {
465449
edit = true;
466450

467451
d--;
468452
}
469453

470454
int start = 0;
471455

472-
if (trimHead && 0 < d && ' ' == buf[0]) {
456+
if (0 < d && ' ' == buf[0]) {
473457
edit = true;
474458

475459
start++;

0 commit comments

Comments
 (0)