-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up Buffer.wordRange procedure for better readability
- Loading branch information
Showing
7 changed files
with
227 additions
and
138 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright © 2024 Christian Tietze. All rights reserved. Distributed under the MIT License. | ||
|
||
import Foundation | ||
|
||
extension NSRange { | ||
@inlinable | ||
func expanded( | ||
to other: NSRange, | ||
direction: Direction | ||
) -> NSRange { | ||
precondition(other.location <= self.location && other.endLocation >= self.endLocation, "Expansion requires other range to be larger") | ||
|
||
let startLocation = switch direction { | ||
case .upstream: other.location | ||
case .downstream: self.location | ||
} | ||
|
||
let endLocation = switch direction { | ||
case .upstream: self.endLocation | ||
case .downstream: other.endLocation | ||
} | ||
|
||
return NSRange( | ||
startLocation: startLocation, | ||
endLocation: endLocation | ||
) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright © 2024 Christian Tietze. All rights reserved. Distributed under the MIT License. | ||
|
||
import Foundation | ||
|
||
extension NSRange { | ||
/// - Returns: Subrange that ends before `other`. | ||
@inlinable | ||
func prefix(upTo other: NSRange) -> NSRange { | ||
return prefix(upTo: other.location) | ||
} | ||
|
||
/// - Returns: Subrange that ends before `location`. | ||
@inlinable | ||
func prefix(upTo location: Int) -> NSRange { | ||
precondition(self.location <= location && self.endLocation >= location, "Prefix requires range to reach up to or encompass location") | ||
|
||
return NSRange( | ||
startLocation: self.location, | ||
endLocation: location | ||
) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright © 2024 Christian Tietze. All rights reserved. Distributed under the MIT License. | ||
|
||
import Foundation | ||
|
||
extension NSRange { | ||
/// - Returns: Subrange that starts after `other`. | ||
@inlinable | ||
func suffix(after other: NSRange) -> NSRange { | ||
return suffix(after: other.endLocation) | ||
} | ||
|
||
/// - Returns: Subrange that starts after `location`. | ||
@inlinable | ||
func suffix(after location: Int) -> NSRange { | ||
precondition(self.location <= location && self.endLocation >= location, "Suffix requires range to start right after or encompass location") | ||
|
||
return NSRange( | ||
startLocation: location, | ||
endLocation: self.endLocation | ||
) | ||
} | ||
} |
Oops, something went wrong.