Use NSRange properly
This commit is contained in:
parent
f1a1812ff2
commit
2ce6ec5db5
|
@ -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)
|
||||
)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue