Skip to content

Commit

Permalink
support DOS newlines in NSString.lineAndCharacterForByteOffset(_:)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Mar 10, 2016
1 parent 66f0ef0 commit 3ff57ab
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Source/SourceKittenFramework/String+SourceKitten.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ extension NSString {
if length == line.byteRange.length {
character = content.utf16.count
} else {
let endIndex = content.utf8.startIndex.advancedBy(length)
.samePositionIn(content.utf16) ?? content.utf16.endIndex
character = content.utf16.startIndex.distanceTo(endIndex)
let fullLength = content.utf8.startIndex.distanceTo(content.utf8.endIndex)
if fullLength < length {
character = fullLength
} else {
let endIndex = content.utf8.startIndex.advancedBy(length)
.samePositionIn(content.utf16) ?? content.utf16.endIndex
character = content.utf16.startIndex.distanceTo(endIndex)
}
}
return (line: line.index, character: character)
}
Expand Down

0 comments on commit 3ff57ab

Please sign in to comment.