-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from p-x9/feature/ustring
Support table of UTF16 string
- Loading branch information
Showing
12 changed files
with
209 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Data+.swift | ||
// MachOKit | ||
// | ||
// Created by p-x9 on 2025/02/02 | ||
// | ||
// | ||
import Foundation | ||
|
||
extension Data { | ||
func byteSwapped<T: FixedWidthInteger>(_ type: T.Type) -> Data { | ||
guard count >= MemoryLayout<T>.size else { return self } | ||
|
||
let valueArray = self.withUnsafeBytes { | ||
Array($0.bindMemory(to: T.self)) | ||
} | ||
|
||
let swappedArray = valueArray.map { $0.byteSwapped } | ||
|
||
var swappedData = swappedArray.withUnsafeBufferPointer { | ||
Data(buffer: $0) | ||
} | ||
|
||
let remainingBytes = count % MemoryLayout<T>.size | ||
if remainingBytes > 0 { | ||
swappedData.append(self.suffix(remainingBytes)) | ||
} | ||
|
||
return swappedData | ||
} | ||
} |
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
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
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,11 @@ | ||
// | ||
// StringTable.swift | ||
// MachOKit | ||
// | ||
// Created by p-x9 on 2025/02/02 | ||
// | ||
// | ||
|
||
public protocol StringTable<Encoding>: Sequence<StringTableEntry> { | ||
associatedtype Encoding: _UnicodeEncoding | ||
} |
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
Oops, something went wrong.