diff options
| author | Dustin Mierau <dustin@mierau.me> | 2023-12-12 15:27:00 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2023-12-12 15:27:00 -0800 |
| commit | 248fcbbd5dca84747e6f3fd9d1d52c41ab8640c3 (patch) | |
| tree | f8f76c7b071aff2fe56c4e900c72dcbaddd3c62a /Hotline/Utility/FoundationExtensions.swift | |
| parent | f71c4cae3b21db506573bcdfa9fdb6cde41cc0ca (diff) | |
New category listing is working again. Added optionset for user access info. Some UI cleanup across the board.
Diffstat (limited to 'Hotline/Utility/FoundationExtensions.swift')
| -rw-r--r-- | Hotline/Utility/FoundationExtensions.swift | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/Hotline/Utility/FoundationExtensions.swift b/Hotline/Utility/FoundationExtensions.swift index 719df40..3797dea 100644 --- a/Hotline/Utility/FoundationExtensions.swift +++ b/Hotline/Utility/FoundationExtensions.swift @@ -5,24 +5,6 @@ enum Endianness { case little } -func detectStringEncoding(of data: Data) -> String.Encoding { -// var nsString: NSString? = nil -// guard case let rawValue = NSString.stringEncoding(for: data, encodingOptions: [.allowLossyKey: false], convertedString: nil, usedLossyConversion: nil) else { -// print("NO ENCODING") -// return nil -// } - - let rawValue = NSString.stringEncoding(for: data, encodingOptions: [.allowLossyKey: false], convertedString: nil, usedLossyConversion: nil) - -// let cfEnc: CFStringEncoding = CFStringConvertNSStringEncodingToEncoding(rawValue); - -// let encodingString: CFString? = CFStringGetNameOfEncoding(cfEnc) - - print("DETECTED ENCODING \(rawValue)") - - return String.Encoding(rawValue: rawValue) -} - extension Data { init(_ val: UInt8) { self.init() @@ -62,6 +44,18 @@ extension Data { return (UInt32(self[offset]) << 24) + (UInt32(self[offset + 1]) << 16) + (UInt32(self[offset + 2]) << 8) + UInt32(self[offset + 3]) } + func readUInt64(at offset: Int) -> UInt64? { + guard offset >= 0, offset + 8 <= self.count else { + return nil + } + + return withUnsafeBytes { $0.load(as: UInt64.self ) } + +// return 0 + +// return (UInt64(self[offset]) << 56) + (UInt64(self[offset + 1]) << 48) + (UInt64(self[offset + 2]) << 40) + (UInt64(self[offset + 3]) << 32) + (UInt64(self[offset + 4]) << 24) + (UInt64(self[offset + 5]) << 16) + (UInt64(self[offset + 6]) << 8) + UInt64(self[offset + 7]) + } + func readData(at offset: Int, length: Int) -> Data? { guard offset >= 0, offset + length <= self.count else { return nil |