-
Notifications
You must be signed in to change notification settings - Fork 40.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34804 from eydunn
* gh-34804: Polish "Fix asymmetry of equals when element has trailing dashes" Fix asymmetry of equals when element has trailing dashes Closes gh-34804
- Loading branch information
Showing
2 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2012-2022 the original author or authors. | ||
* Copyright 2012-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -406,7 +406,7 @@ private boolean dashIgnoringElementEquals(Elements e1, Elements e2, int i) { | |
int i2 = 0; | ||
while (i1 < l1) { | ||
if (i2 >= l2) { | ||
return false; | ||
return remainderIsDashes(e1, i, i1); | ||
} | ||
char ch1 = e1.charAt(i, i1); | ||
char ch2 = e2.charAt(i, i2); | ||
|
@@ -487,6 +487,21 @@ private boolean remainderIsNotAlphanumeric(Elements elements, int element, int i | |
return true; | ||
} | ||
|
||
private boolean remainderIsDashes(Elements elements, int element, int index) { | ||
if (elements.getType(element).isIndexed()) { | ||
return false; | ||
} | ||
int length = elements.getLength(element); | ||
do { | ||
char c = Character.toLowerCase(elements.charAt(element, index++)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wilkinsona
Author
Member
|
||
if (c != '-') { | ||
return false; | ||
} | ||
} | ||
while (index < length); | ||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hashCode = this.hashCode; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The
toLowerCase
conversion appears unnecessary here, since'-'
is the onlychar
whoseCharacter.toLowerCase
value produces'-'
.