Skip to content

Commit 9c886cc

Browse files
committed
cleanup, jdoc and replace some call to equalsIgnoreCase with equals
1 parent b7a66dc commit 9c886cc

6 files changed

Lines changed: 44 additions & 27 deletions

File tree

src/main/java/org/htmlunit/cyberneko/HTMLNamedEntitiesParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ protected void optimize() {
402402
if (offset_ > 0) {
403403
// that is just for later to tell us that we don't understand our
404404
// own code anymore and called that incorrectly
405-
throw new RuntimeException("Optimiize was called twice");
405+
throw new RuntimeException("Optimize was called twice");
406406
}
407407

408408
// ok, smallest char is the start

src/main/java/org/htmlunit/cyberneko/HTMLScanner.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ public void setProperty(final String propertyId, final Object value) throws XMLC
874874
* @throws IOException Thrown on i/o error.
875875
*/
876876
public void setInputSource(final XMLInputSource source) throws IOException {
877-
878877
// reset state
879878
fElementCount = 0;
880879
fElementDepth = -1;
@@ -947,14 +946,15 @@ public void setInputSource(final XMLInputSource source) throws IOException {
947946

948947
// set scanner and state
949948
if (fFragmentSpecialScannerTag_ != null) {
950-
if ("script".equalsIgnoreCase(fFragmentSpecialScannerTag_)) {
949+
final String scannerTagLC = fFragmentSpecialScannerTag_.toLowerCase(Locale.ROOT);
950+
if ("script".equals(scannerTagLC)) {
951951
setScanner(fScriptScanner);
952952
}
953-
else if ("plaintext".equalsIgnoreCase(fFragmentSpecialScannerTag_)) {
953+
else if ("plaintext".equals(scannerTagLC)) {
954954
setScanner(new PlainTextScanner());
955955
}
956956
else {
957-
setScanner(fSpecialScanner.setElementName(fFragmentSpecialScannerTag_));
957+
setScanner(fSpecialScanner.setElementName(fFragmentSpecialScannerTag_, scannerTagLC));
958958
setScannerState(STATE_CONTENT);
959959
}
960960

@@ -2367,7 +2367,7 @@ else if (ename != null) {
23672367
final Element elem =
23682368
htmlConfiguration_.getHtmlElements().getElementLC(enameLC, null);
23692369
if (elem != null && elem.isSpecial()) {
2370-
setScanner(fSpecialScanner.setElementName(ename));
2370+
setScanner(fSpecialScanner.setElementName(ename, enameLC));
23712371
setScannerState(STATE_CONTENT);
23722372
return SCAN_TRUE;
23732373
}
@@ -3436,11 +3436,11 @@ public class SpecialScanner implements Scanner {
34363436
private final XMLString charBuffer_ = new XMLString();
34373437

34383438
// Sets the element name.
3439-
public Scanner setElementName(final String ename) {
3439+
public Scanner setElementName(final String ename, final String enameLC) {
34403440
fElementName = ename;
3441-
fStyle = "style".equalsIgnoreCase(fElementName);
3442-
fTextarea = "textarea".equalsIgnoreCase(fElementName);
3443-
fTitle = "title".equalsIgnoreCase(fElementName);
3441+
fStyle = "style".equals(enameLC);
3442+
fTextarea = "textarea".equals(enameLC);
3443+
fTitle = "title".equals(enameLC);
34443444
return this;
34453445
}
34463446

src/main/java/org/htmlunit/cyberneko/HTMLTagBalancer.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.Iterator;
2020
import java.util.List;
21+
import java.util.Locale;
2122

2223
import org.htmlunit.cyberneko.HTMLElements.Element;
2324
import org.htmlunit.cyberneko.filters.NamespaceBinder;
@@ -352,21 +353,22 @@ public void reset(final XMLComponentManager manager)
352353
// use indexed loop to avoid Iterator allocation
353354
for (int i = 0; i < fragmentContextStack_.length; i++) {
354355
final QName qname = fragmentContextStack_[i];
355-
if ("html".equalsIgnoreCase(qname.getLocalpart())) {
356+
final String qnameLocalpartLC = qname.getLocalpart().toLowerCase(Locale.ROOT);
357+
if ("html".equals(qnameLocalpartLC)) {
356358
fSeenRootElement = true;
357359
fSeenRealHtmlElement = true;
358360
}
359-
else if ("body".equalsIgnoreCase(qname.getLocalpart())) {
361+
else if ("body".equals(qnameLocalpartLC)) {
360362
fSeenHeadElement = true;
361363
fSeenBodyElement = true;
362364
}
363-
else if ("form".equalsIgnoreCase(qname.getLocalpart())) {
365+
else if ("form".equals(qnameLocalpartLC)) {
364366
fOpenedForm = true;
365367
}
366-
else if ("select".equalsIgnoreCase(qname.getLocalpart())) {
368+
else if ("select".equals(qnameLocalpartLC)) {
367369
fOpenedSelect = true;
368370
}
369-
else if ("svg".equalsIgnoreCase(qname.getLocalpart())) {
371+
else if ("svg".equals(qnameLocalpartLC)) {
370372
fOpenedSvg = true;
371373
}
372374
}
@@ -549,7 +551,7 @@ public void endDocument(final Augmentations augs) throws XNIException {
549551
}
550552

551553
/**
552-
* Consume elements that have been buffered, like </body></html> that are first consumed
554+
* Consume elements that have been buffered, like &lt;/body&gt;&lt;/html&gt; that are first consumed
553555
* at the end of document
554556
*/
555557
private void consumeBufferedEndElements() {

src/main/java/org/htmlunit/cyberneko/LostText.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/**
2626
* Container for text that should be hold and re-feed later like text before &lt;html&gt; that will be re-feed
2727
* in &lt;body&gt;
28+
*
2829
* @author Marc Guillemot
2930
*/
3031
class LostText {

src/main/java/org/htmlunit/cyberneko/util/StringUtils.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,48 @@
1616
package org.htmlunit.cyberneko.util;
1717

1818
/**
19-
* String utilities class for utility functions not covered by third party libraries.
19+
* String utilities class providing utility functions not covered by third party libraries.
20+
*
21+
* <p>This class contains static utility methods for common string operations used
22+
* throughout the HtmlUnit NekoHtml parser. It focuses on lightweight, performance-oriented
23+
* string checks that avoid creating unnecessary String objects or using expensive operations.</p>
2024
*
2125
* @author Ronald Brill
2226
*/
2327
public final class StringUtils {
2428

2529
/**
26-
* Disallow instantiation of this class.
30+
* Private constructor to prevent instantiation of this utility class.
2731
*/
2832
private StringUtils() {
29-
// Empty.
33+
// Empty - utility class should not be instantiated
3034
}
3135

3236
/**
33-
* Returns true if the param is not null and empty. This is different from
34-
* org.apache.commons.lang3.StringUtils#isEmpty(CharSequence) because
35-
* this returns false if the provided string is null.
37+
* Checks if the provided character sequence is not null and has zero length.
38+
*
39+
* <p>This method differs from {@code org.apache.commons.lang3.StringUtils#isEmpty(CharSequence)}
40+
* in that it returns {@code false} if the provided string is {@code null}.</p>
3641
*
37-
* @param s the string to check
38-
* @return true if the param is not null and empty
42+
* @param s the character sequence to check, may be null
43+
* @return {@code true} if the sequence is not null AND has length of zero; {@code false} otherwise
3944
*/
4045
public static boolean isEmptyString(final CharSequence s) {
4146
return s != null && s.length() == 0;
4247
}
4348

4449
/**
45-
* @param expected the char that we expect
46-
* @param s the string to check
47-
* @return true if the provided string has only one char and this matches the expectation
50+
* Checks if the provided character sequence consists of exactly one character that matches
51+
* the expected character.
52+
*
53+
* <p>This is an optimized equality check for single-character strings, avoiding the overhead
54+
* of full string comparison. It's particularly useful during HTML parsing when checking for
55+
* single-character tokens or delimiters.</p>
56+
*
57+
* @param expected the character that we expect to match
58+
* @param s the character sequence to check, may be null
59+
* @return {@code true} if and only if the provided sequence is not null, has exactly one character,
60+
* and that character equals the expected character; {@code false} otherwise
4861
*/
4962
public static boolean equalsChar(final char expected, final CharSequence s) {
5063
return s != null && s.length() == 1 && expected == s.charAt(0);

src/main/java/org/htmlunit/cyberneko/xerces/xni/XMLString.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ public boolean endsWith(final String s) {
399399
*
400400
* @deprecated Use the new method {@link #trimToContent(String, String)} instead.
401401
*/
402+
@Deprecated
402403
public XMLString reduceToContent(final String startMarker, final String endMarker) {
403404
return trimToContent(startMarker, endMarker);
404405
}

0 commit comments

Comments
 (0)