Fix AssetBundleStringExtractor for Swift 5
Apparently I was never supposed to use withMemoryRebound like that and it finally started checking that in Swift 5
This commit is contained in:
@@ -20,9 +20,9 @@ guard CommandLine.arguments.count > 1 else {
|
|||||||
|
|
||||||
#if !swift(>=4.2)
|
#if !swift(>=4.2)
|
||||||
extension Collection {
|
extension Collection {
|
||||||
func firstIndex(where predicate: (Element) throws -> Bool) rethrows -> Index? {
|
func firstIndex(where predicate: (Element) throws -> Bool) rethrows -> Index? {
|
||||||
return try self.index(where: predicate)
|
return try self.index(where: predicate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -92,13 +92,12 @@ func stringFinder(data: Data, maxStringLength: Int = 100) -> [String] {
|
|||||||
let unicode = UnsafeBufferPointer(rebasing: ints[(index + 1)...].prefix(uint32Length))
|
let unicode = UnsafeBufferPointer(rebasing: ints[(index + 1)...].prefix(uint32Length))
|
||||||
// Ensure padding is all 0s
|
// Ensure padding is all 0s
|
||||||
guard padding == 0 || unicode.last!.littleEndian &>> (padding * 8) == 0 else { continue }
|
guard padding == 0 || unicode.last!.littleEndian &>> (padding * 8) == 0 else { continue }
|
||||||
let optionalStr = unicode.withMemoryRebound(to: UInt8.self) { (unicode) -> String? in
|
|
||||||
let stringUnicode = unicode[..<Int(int)]
|
let unicodeBytes = UnsafeRawBufferPointer(unicode).bindMemory(to: UInt8.self)
|
||||||
guard isValidUTF8(data: stringUnicode) else { return nil }
|
let stringUnicode = unicodeBytes[..<Int(int)]
|
||||||
return String(decoding: stringUnicode, as: UTF8.self)
|
guard isValidUTF8(data: stringUnicode) else { continue }
|
||||||
}
|
|
||||||
guard let str = optionalStr else { continue }
|
out.append(String(decoding: stringUnicode, as: UTF8.self))
|
||||||
out.append(str)
|
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user