gpt4 book ai didi

macos - OSX 中 CFString 的 native utf 编码是什么?

转载 作者:行者123 更新时间:2023-12-03 17:14:48 25 4
gpt4 key购买 nike

这应该很容易找到,但我似乎无法在任何地方找到它 - 所以如果这是理所当然的,请原谅。 CFString、UTF-16、UTF-8 等中使用的 native UTF 存储是什么?

为什么我要问的是,我正在连接一些lua代码,lua可以处理UTF-8字符串,但是如果我将它们转换为CFSTring,那么如果它在内部使用UTF-16,将会有性能损失?

我查看了 CFStringGetSystemEncoding,它返回 mac roman - 这似乎不正确。

区域设置返回

LANG="en_AU.UTF-8"...

这表明它是 utf-8 但随后是 docs似乎表明它是 16 位的?

蒂亚

最佳答案

有短章“String storage ” 在文档中说它内部可以有各种编码:

Although conceptually CFString objects store strings as arrays of Unicode characters, in practice they often store them more efficiently. The memory a CFString object requires to represent a string could often be less than that required by a simple UniChar array.

最后一段为那些担心额外转化的人提出了一个解决方案:

You can get further control over the backing store of a string with the CFStringCreateMutableWithExternalCharactersNoCopy function. This function creates a reference to a mutable CFString object but allows you to retain full ownership of the Unicode buffer holding the object’s characters; the object itself points to the buffer as its backing store.

关于macos - OSX 中 CFString 的 native utf 编码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9802634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com