Adopted the standard withCString for C strings throughout the library.
This commit is contained in:
@@ -43,10 +43,10 @@ extension JSON {
|
||||
|
||||
/// Call before writing each table value.
|
||||
public func addTableMember(name: String) {
|
||||
name.withPlaydateUTF8 { bytes, count in
|
||||
name.withCString { cString in
|
||||
withUnsafeMutablePointer(to: &encoder) {
|
||||
$0.pointee.addTableMember.unsafelyUnwrapped(
|
||||
$0, bytes.assumingMemoryBound(to: CChar.self), Int32(count))
|
||||
$0, cString, Int32(name.utf8.count))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,10 +80,10 @@ extension JSON {
|
||||
|
||||
/// Writes a string value.
|
||||
public func writeString(_ value: String) {
|
||||
value.withPlaydateUTF8 { bytes, count in
|
||||
value.withCString { cString in
|
||||
withUnsafeMutablePointer(to: &encoder) {
|
||||
$0.pointee.writeString.unsafelyUnwrapped(
|
||||
$0, bytes.assumingMemoryBound(to: CChar.self), Int32(count))
|
||||
$0, cString, Int32(value.utf8.count))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ extension JSON {
|
||||
let unmanaged = Unmanaged.passUnretained(context)
|
||||
var decoder = makeDecoder(context: unmanaged)
|
||||
var outval = json_value()
|
||||
let ok = jsonString.withPlaydateCString { cString in
|
||||
let ok = jsonString.withCString { cString in
|
||||
withExtendedLifetime(context) {
|
||||
jsonAPI.pointee.decodeString.unsafelyUnwrapped(&decoder, cString, &outval) != 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user