jpsim / jpsim/SourceKitten

strong type `byteRange` instead of just using NSRange

Open
#242 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
2.4k
Forks
237
PR merge metrics
No merged PRs in 30d

Description

   public let content: String
    /// UTF16 based range in entire String. Equivalent to Range<UTF16Index>
    public let range: NSRange
    /// Byte based range in entire String. Equivalent to Range<UTF8Index>
    public let byteRange: NSRange

Any way to strong type byteRange so that methods like below reject non byte ranges?

extension SyntaxMap {
    /// Returns array of SyntaxTokens intersecting with byte range
    ///
    /// - Parameter byteRange: byte based NSRange
    internal func tokensIn(byteRange: NSRange) -> [SyntaxToken] {....}

Right now we have to remember to use a method on nsstring in SourceKitten to convert the ranges in the contents of the file.

extension NSString {
    /**
        Converts an `NSRange` suitable for filtering `self` as an
        `NSString` to a range of byte offsets in `self`.

        - parameter start: Starting character index in the string.
        - parameter length: Number of characters to include in range.

        - returns: An equivalent `NSRange`.
        */
    public func NSRangeToByteRange(start start: Int, length: Int) -> NSRange?
...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing SyntaxMap.tokensIn(byteRange:) and the range and byteRange properties shown in the issue, then inspect NSString.NSRangeToByteRange. Determine how a distinct byte-range type would affect existing callers and conversions, and verify that ordinary NSRange values can no longer be passed where byte ranges are required.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.