-
-
Save eonist/d2d3cee8ac0a2cee7599480bb2913847 to your computer and use it in GitHub Desktop.
Prospective Range+Extensions for swift 3 intensityAttributingKit
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
// | |
// Range+Extensions.swift | |
// IntensityAttributingKit | |
// | |
// Created by Evan Mckee on 3/23/16. | |
// Copyright © 2016 McKeeMaKer. All rights reserved. | |
// | |
import Foundation | |
extension Range { | |
// ///Returns true if there's any overlap between the two ranges, false otherwise. | |
// func intersects(_ range:Range<Element>)->Bool { | |
// //cases: contains, is contained in, bottom half overlaps, top half overlaps | |
// if self.lowerBound >= range.upperBound || self.upperBound <= range.lowerBound { | |
// return false | |
// } | |
// return true | |
// } | |
///Returns true if this range wholly contains the provided range, false otherwise. A range with zero length will not be contained in anything. | |
func whollyContains(_ range:Range<Element>)->Bool { | |
return range.lowerBound >= self.lowerBound && range.upperBound <= self.upperBound | |
} | |
} | |
extension ClosedRange { | |
///Returns true if this range wholly contains the provided range, false otherwise. A range with zero length will not be contained in anything. | |
func whollyContains(_ range:Range<Element>)->Bool { | |
return range.lowerBound >= self.lowerBound && range.upperBound <= self.upperBound | |
} | |
} | |
extension CountableRange { | |
var nsRange:NSRange { | |
let start = self.lowerBound as! Int | |
let end = self.upperBound as! Int | |
return NSRange(location: start, length: end - start) | |
} | |
///Returns true if this range wholly contains the provided range, false otherwise. A range with zero length will not be contained in anything. | |
func whollyContains(_ range:Range<Element>)->Bool { | |
return range.lowerBound >= self.lowerBound && range.upperBound <= self.upperBound | |
} | |
} | |
extension CountableClosedRange { | |
var nsRange:NSRange { | |
let start = self.lowerBound as! Int | |
let end = self.upperBound as! Int | |
return NSRange(location: start, length: end - start) | |
} | |
///Returns true if this range wholly contains the provided range, false otherwise. A range with zero length will not be contained in anything. | |
func whollyContains(_ range:Range<Element>)->Bool { | |
return range.lowerBound >= self.lowerBound && range.upperBound <= self.upperBound | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment