Skip to content

Commit

Permalink
These field names are part of the API :(
Browse files Browse the repository at this point in the history
  • Loading branch information
jhy committed Dec 14, 2024
1 parent 37169b1 commit ae606bf
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/main/java/org/jsoup/select/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,14 @@ public String toString() {


public static abstract class CssNthEvaluator extends Evaluator {
protected final int step, offset;
/** Step */
protected final int a;
/** Offset */
protected final int b;

public CssNthEvaluator(int step, int offset) {
this.step = step;
this.offset = offset;
this.a = step;
this.b = offset;
}

public CssNthEvaluator(int offset) {
Expand All @@ -544,18 +547,18 @@ public boolean matches(Element root, Element element) {
if (p == null || (p instanceof Document)) return false;

final int pos = calculatePosition(root, element);
if (step == 0) return pos == offset;
if (a == 0) return pos == b;

return (pos - offset) * step >= 0 && (pos - offset) % step == 0;
return (pos - b) * a >= 0 && (pos - b) % a == 0;
}

@Override
public String toString() {
if (step == 0)
return String.format(":%s(%d)", getPseudoClass(), offset);
if (offset == 0)
return String.format(":%s(%dn)", getPseudoClass(), step);
return String.format(":%s(%dn%+d)", getPseudoClass(), step, offset);
if (a == 0)
return String.format(":%s(%d)", getPseudoClass(), b);
if (b == 0)
return String.format(":%s(%dn)", getPseudoClass(), a);
return String.format(":%s(%dn%+d)", getPseudoClass(), a, b);
}

protected abstract String getPseudoClass();
Expand Down

0 comments on commit ae606bf

Please sign in to comment.