Use NSRange properly

This commit is contained in:
Zhiyu Zhu/朱智语 2019-04-05 15:02:15 -04:00
parent f1a1812ff2
commit 2ce6ec5db5
2 changed files with 4 additions and 3 deletions

View File

@ -72,7 +72,7 @@ public struct Period {
let mark: Character = ""
str = regexp.stringByReplacingMatches(
in: str,
range: NSRange(location: 0, length: str.count),
range: NSRange(str.startIndex..., in: str),
withTemplate: String(mark)
)

View File

@ -50,10 +50,11 @@ public struct Time {
// swiftlint:disable force_try
let regexp = try! NSRegularExpression(pattern: pattern, options: [])
let nsString = NSString(string: string)
guard let matches = regexp.matches(
in: string,
options: [],
range: NSRange(location: 0, length: string.count)).first
range: NSRange(location: 0, length: nsString.length)).first
else {
return nil
}
@ -65,7 +66,7 @@ public struct Time {
for i in 0..<matches.numberOfRanges {
let range = matches.range(at: i)
if range.length == 0 { continue }
let captured = NSString(string: string).substring(with: range)
let captured = nsString.substring(with: range)
hasAM = ["am", "AM"].contains(captured)
hasPM = ["pm", "PM"].contains(captured)
if let value = Int(captured) {