Skip to content

Commit

Permalink
後方検索を実装した
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Aug 9, 2023
1 parent 2741ee4 commit 57114a7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/SwiftKilo/SwiftKilo.swift
Expand Up @@ -111,8 +111,8 @@ public class SwiftKilo {
raw.removeFirst(k)
}

mutating func dropFirst(_ k: Int = 1) -> String.SubSequence {
raw.dropFirst(k)
mutating func prefix(_ maxLength: Int = 1) -> Substring {
raw.prefix(maxLength)
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ public class SwiftKilo {
var rowsAfter = Array(rows[startPosition.y..<rows.endIndex])

if !rowsAfter.isEmpty {
rowsBefore.append(Row(raw: String(rowsAfter[0].dropFirst(startPosition.x))))
rowsBefore.append(Row(raw: String(rowsAfter[0].prefix(startPosition.x))))
rowsAfter[0].removeFirst(startPosition.x)
}

Expand Down Expand Up @@ -228,9 +228,9 @@ public class SwiftKilo {

guard let range = raw.range(of: str) else { continue }

let reversedX = raw.distance(from: raw.startIndex, to: range.lowerBound)
let x = raw.distance(from: range.upperBound, to: raw.endIndex)

return Position(x: raw.count - 1 - reversedX, y: rowsBefore.count - 1 - reversedY)
return Position(x: x, y: rowsBefore.count - 1 - reversedY)
}

for (reversedY, row) in rowsAfter.reversed().enumerated() {
Expand Down

0 comments on commit 57114a7

Please sign in to comment.