Skip to content

Commit

Permalink
Revert "Revert "add swift version control and adapted to older versio…
Browse files Browse the repository at this point in the history
…ns.""

This reverts commit 6c0edd6.
  • Loading branch information
kobeumut committed Jun 5, 2018
1 parent 6c0edd6 commit 3252bbc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/Kanna/CSS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ private let matchSubContains = firstMatch("contains\\([\"\'](.*?)[\"\']\\)")

private func substringWithRangeAtIndex(_ result: AKTextCheckingResult, str: String, at: Int) -> String {
if result.numberOfRanges > at {
#if swift(>=4.0)
let range = result.range(at: at)
#else
let range = result.rangeAt(at)
#endif
if range.length > 0 {
let startIndex = str.index(str.startIndex, offsetBy: range.location)
let endIndex = str.index(startIndex, offsetBy: range.length)
Expand Down Expand Up @@ -321,7 +325,11 @@ private func getAttrNot(_ str: inout String, skip: Bool = true) -> String? {
if let attr = getAttribute(&one, skip: false) {
return attr
} else if let sub = matchElement(one) {
#if swift(>=4.0)
let range = sub.range(at: 1)
#else
let range = sub.rangeAt(1)
#endif
let startIndex = one.index(one.startIndex, offsetBy: range.location)
let endIndex = one.index(startIndex, offsetBy: range.length)

Expand Down

0 comments on commit 3252bbc

Please sign in to comment.