1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-10-28 03:38:54 +03:00

Guard against invalid positions

This commit is contained in:
Tae Won Ha 2016-07-05 19:00:27 +02:00
parent 292e2be410
commit 01cbb584be
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -198,6 +198,10 @@ class Grid: CustomStringConvertible {
}
func isCellEmpty(position: Position) -> Bool {
guard self.isSane(position: position) else {
return false
}
if self.cells[position.row][position.column].string.characters.count == 0 {
return true
}
@ -241,4 +245,12 @@ class Grid: CustomStringConvertible {
self.cells[i].replaceRange(region.left...region.right, with: clearedRow)
}
}
private func isSane(position position: Position) -> Bool {
guard position.row < self.size.height && position.column < self.size.width else {
return false
}
return true
}
}