Skip to content

Commit

Permalink
Merge pull request #53 from patricklam/master
Browse files Browse the repository at this point in the history
Make local copy of methods "isWhiteSpace" and "in" from jsoup.
  • Loading branch information
sutra committed Oct 25, 2021
2 parents ddc488b + 5bd5085 commit c97a9e0
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/us/codecraft/xsoup/XTokenQueue.java
Expand Up @@ -5,7 +5,6 @@
import java.util.regex.Pattern;

import org.jsoup.helper.Validate;
import org.jsoup.internal.StringUtil;

/**
* A character queue with parsing helpers.
Expand Down Expand Up @@ -58,7 +57,7 @@ public static String unescape(String in) {
public static String trimQuotes(String str) {
Validate.isTrue(str != null && str.length() > 0);
String quote = str.substring(0, 1);
if (StringUtil.in(quote, "\"", "'")) {
if (in(quote, "\"", "'")) {
Validate.isTrue(str.endsWith(quote), "Quote" + " for " + str + " is incomplete!");
str = str.substring(1, str.length() - 1);
}
Expand Down Expand Up @@ -199,7 +198,7 @@ public boolean matchChomp(String seq) {
* @return if starts with whitespace
*/
public boolean matchesWhitespace() {
return !isEmpty() && StringUtil.isWhitespace(queue.charAt(pos));
return !isEmpty() && isWhitespace(queue.charAt(pos));
}

/**
Expand Down Expand Up @@ -564,4 +563,25 @@ else if (matchesAny(quotes)) {
}
return params;
}

/**
* Tests if a code point is "whitespace" as defined in the HTML spec. Used for output HTML.
* Copied from jsoup's org.jsoup.internal.StringUtil.
* @param c code point to test
* @return true if code point is whitespace, false otherwise
* @see #isActuallyWhitespace(int)
*/
private static boolean isWhitespace(int c){
return c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r';
}

// also copied from jsoup's org.jsoup.internal.StringUtil.
private static boolean in(final String needle, final String... haystack) {
final int len = haystack.length;
for (int i = 0; i < len; i++) {
if (haystack[i].equals(needle))
return true;
}
return false;
}
}

0 comments on commit c97a9e0

Please sign in to comment.