Skip to content

Commit

Permalink
modify parameter labeling for clarity
Browse files Browse the repository at this point in the history
func regionMatches in String extension
  • Loading branch information
mediter committed Apr 28, 2021
1 parent 89e092b commit 1b201f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Sources/Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions Sources/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/TokenQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down

0 comments on commit 1b201f7

Please sign in to comment.