modify parameter labeling for clarity

func regionMatches in String extension
This commit is contained in:
Jun Yuan 2021-04-28 10:49:59 +08:00
parent 89e092bebd
commit 1b201f7e22
4 changed files with 19 additions and 7 deletions

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View File

@ -1107,7 +1107,9 @@ open class Element: Node {
if (classAttr.charAt(i).isWhitespace) { if (classAttr.charAt(i).isWhitespace) {
if (inClass) { if (inClass) {
// white space ends a class name, compare it with the requested one, ignore case // white space ends a class name, compare it with the requested one, ignore case
if (i - start == wantLen && classAttr.regionMatches(true, start, className, 0, wantLen)) { if (i - start == wantLen && classAttr.regionMatches(ignoreCase: true, selfOffset: start,
other: className, otherOffset: 0,
targetLength: wantLen)) {
return true return true
} }
inClass = false inClass = false
@ -1123,7 +1125,8 @@ open class Element: Node {
// check the last entry // check the last entry
if (inClass && len - start == wantLen) { if (inClass && len - start == wantLen) {
return classAttr.regionMatches(true, start, className, 0, wantLen) return classAttr.regionMatches(ignoreCase: true, selfOffset: start,
other: className, otherOffset: 0, targetLength: wantLen)
} }
return false return false

View File

@ -120,14 +120,15 @@ extension String {
return String.split(self, beginIndex, count) return String.split(self, beginIndex, count)
} }
func regionMatches(_ ignoreCase: Bool, _ selfOffset: Int, _ other: String, _ otherOffset: Int, _ length: Int ) -> Bool { func regionMatches(ignoreCase: Bool, selfOffset: Int,
other: String, otherOffset: Int, targetLength: Int ) -> Bool {
if ((otherOffset < 0) || (selfOffset < 0) if ((otherOffset < 0) || (selfOffset < 0)
|| (selfOffset > self.count - length) || (selfOffset > self.count - targetLength)
|| (otherOffset > other.count - length)) { || (otherOffset > other.count - targetLength)) {
return false return false
} }
for i in 0..<length { for i in 0..<targetLength {
let charSelf: Character = self[i+selfOffset] let charSelf: Character = self[i+selfOffset]
let charOther: Character = other[i+otherOffset] let charOther: Character = other[i+otherOffset]
if(ignoreCase) { if(ignoreCase) {

View File

@ -66,7 +66,8 @@ open class TokenQueue {
* @return true if the next characters match. * @return true if the next characters match.
*/ */
open func matches(_ seq: String) -> Bool { open func matches(_ seq: String) -> Bool {
return queue.regionMatches(true, pos, seq, 0, seq.count) return queue.regionMatches(ignoreCase: true, selfOffset: pos,
other: seq, otherOffset: 0, targetLength: seq.count)
} }
/** /**