Skip to content

Commit

Permalink
Improve endianness detection (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
woxtu authored Jan 16, 2025
1 parent 77a793c commit 8e38c78
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sources/SwiftTreeSitter/String+Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import Foundation

extension String {
static var nativeUTF16Encoding: String.Encoding {
let dataA = "abc".data(using: .utf16LittleEndian)
let dataB = "abc".data(using: .utf16)?.suffix(from: 2)

return dataA == dataB ? .utf16LittleEndian : .utf16BigEndian
#if _endian(little)
return .utf16LittleEndian
#else
return .utf16BigEndian
#endif
}

func data(at byteOffset: Int, limit: Int, using encoding: String.Encoding, chunkSize: Int) -> Data? {
Expand Down

0 comments on commit 8e38c78

Please sign in to comment.