modify parameter labeling for clarity
func regionMatches in String extension
This commit is contained in:
parent
89e092bebd
commit
1b201f7e22
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
|
@ -1107,7 +1107,9 @@ open class Element: Node {
|
|||
if (classAttr.charAt(i).isWhitespace) {
|
||||
if (inClass) {
|
||||
// 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
|
||||
}
|
||||
inClass = false
|
||||
|
@ -1123,7 +1125,8 @@ open class Element: Node {
|
|||
|
||||
// check the last entry
|
||||
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
|
||||
|
|
|
@ -120,14 +120,15 @@ extension String {
|
|||
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)
|
||||
|| (selfOffset > self.count - length)
|
||||
|| (otherOffset > other.count - length)) {
|
||||
|| (selfOffset > self.count - targetLength)
|
||||
|| (otherOffset > other.count - targetLength)) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i in 0..<length {
|
||||
for i in 0..<targetLength {
|
||||
let charSelf: Character = self[i+selfOffset]
|
||||
let charOther: Character = other[i+otherOffset]
|
||||
if(ignoreCase) {
|
||||
|
|
|
@ -66,7 +66,8 @@ open class TokenQueue {
|
|||
* @return true if the next characters match.
|
||||
*/
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue