Minor cleanup of CFString.odin

This commit is contained in:
gingerBill
2024-08-27 11:22:28 +01:00
parent fb248056c9
commit 8694fa5f78
+6 -13
View File
@@ -181,23 +181,16 @@ foreign CoreFoundation {
STR :: StringMakeConstantString STR :: StringMakeConstantString
StringCopyToOdinString :: proc( StringCopyToOdinString :: proc(theString: String, allocator := context.allocator) -> (str: string, ok: bool) #optional_ok {
theString: String,
allocator := context.allocator,
) -> (
str: string,
ok: bool,
) #optional_ok {
length := StringGetLength(theString) length := StringGetLength(theString)
max := StringGetMaximumSizeForEncoding(length, StringEncoding(StringBuiltInEncodings.UTF8)) max := StringGetMaximumSizeForEncoding(length, StringEncoding(StringBuiltInEncodings.UTF8))
buf, err := make([]byte, max, allocator) buf, err := make([]byte, max, allocator)
if err != nil { return } if err != nil {
return
raw_str := runtime.Raw_String {
data = raw_data(buf),
} }
StringGetBytes(theString, {0, length}, StringEncoding(StringBuiltInEncodings.UTF8), 0, false, raw_data(buf), max, (^Index)(&raw_str.len))
return transmute(string)raw_str, true n: Index
StringGetBytes(theString, {0, length}, StringEncoding(StringBuiltInEncodings.UTF8), 0, false, raw_data(buf), Index(len(buf)), &n)
return string(buf[:n]), true
} }