mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Minor cleanup of CFString.odin
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user