You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
objc: Add function to convert NSString to Go string #438
A function that converts from NSString to a Go string
// NSStringToString returns a copy of the contents of an NSString into a Go string// If the ID is 0 then an empty string is returned.// If the ID is not an NSString class then the function panics.funcNSStringToString(strID) string {
ifstr==0 {
return""
}
ifstr.Send(selIsKindOf, nsStringClass) ==0 {
returnpanic("objc: provided ID is not an NSString")
}
returnstrings.GoString(uintptr(str.Send(selUTF8String)))
}
Why is this needed?
This is a common operation that people want to do and it is easy to do incorrectly.
I originally did it wrong in this PR by using length which is UTF-16 codepoint instead of utf8 length.
Technically, yes but I don't think it'd cause any issues since I don't think the NSAppearance returns any non-ascii characters. That is only the case where the UTF-16 code point length returned from the length selector would differ from the UTF-8 code point length.
Activity
hajimehoshi commentedon Mar 12, 2026
Oops, is this a bug..?
hajimehoshi commentedon Mar 12, 2026
I agree this should be a very useful utility function
TotallyGamerJet commentedon Mar 12, 2026
Technically, yes but I don't think it'd cause any issues since I don't think the NSAppearance returns any non-ascii characters. That is only the case where the UTF-16 code point length returned from the length selector would differ from the UTF-8 code point length.
hajimehoshi commentedon Mar 12, 2026
Sure. I'll fix this asap, but if NSStringToString is introduced, I'll use it.
internal/colormode: fix wrong byte length for NSString UTF-8 conversion
cstrings: add NSStringToString (ebitengine#447)
all: use cstrings.NSStringToString