Erlang 中的字符串 - 我应该检查哪些库和技术?
我正在开展一个需要国际化支持的项目。我想开始使用 UTF 支持,我想知道在 Erlang 中处理 UTF 的最佳实践是什么?
从我目前的研究来看,Erlang 的内置字符串处理在某些用例中似乎存在一些问题(JSON 解析就是一个很好的例子)。
我一直在查看 Starling 并最近(在某处)读到它可能会是作为 UTF“标准”纳入标准 Erlang 版本。这是真的吗?我还应该考虑其他库或方法吗?
来自评论:
EEP(Erlang增强提案)10个细节在Erlang中表示Unicode字符
I am working on a project that will require internationalisation support down the track. I want to get started on the right foot with UTF support, and I was wondering what the best practice for handling UTF in Erlang is?
From my current research it seems there are a couple of issues with Erlang's built in string handling for some use cases (JSON parsing being a good example).
I have been looking at Starling and read (somewhere) recently that it is possibly going to be rolled into the standard Erlang release as the UTF 'standard'. Is this true? Are there other libraries or approaches I should be looking at?
From the comments:
EEP (Erlang Enhancement Proposal) 10 details Representing Unicode characters in Erlang
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此页面:
http://erlang.org/doc/highlights.html
...列表5.7/OTP R13A 版本的亮点。注意这段话:
我不喜欢宣布什么是最佳实践,但我经常发现有一个最小的、完整的示例来开始概括是很有帮助的。这是将 utf 放入 erlang 应用程序并将其再次发送到不同上下文的示例之一。假设您有一个 MySql 数据库,其表中的行字段包含 utf8 字符,则有一种方法可以将其取出并将其作为 json 通过管道传输到 Web 浏览器:
编辑 src/mywebdemo_resource.erl,使其看起来像这样:
构建所有内容并开始url 调度程序:
然后在网页中执行以下命令(或者更方便的东西,例如 MozRepl):
This page:
http://erlang.org/doc/highlights.html
...lists hightlights of release 5.7/OTP R13A. Note this passage:
I don't like to make pronouncements on what best practices would be, but I often find it helpful to have a minimal, complete example to start to generalize from. Here's one of getting utf into an erlang application and sending it out again to a different context. Assuming you had a MySql database with a row field in a table containing utf8 characters, here's one way to get it out and pipe it to a web browser as json:
Edit src/mywebdemo_resource.erl so it looks like this:
Build everything and start the url dispatcher:
Then execute the following in a web page (or something more convenient, like MozRepl):
正如之前的海报提到的,erlang 的最新版本原生支持 utf。如果您不能使用最新版本,那么我通常做的一件事就是使用二进制文件来存储字符串数据。它可以防止 erlang 破坏列表中的字节。它的副作用是使字符串列表也更容易处理。
As the previous poster mentioned the latest release of erlang supports utf natively. If you can't use the latest though then one thing I do usually is to use binaries for string data. It keeps erlang from mangling the bytes in a list. It has the side effect of making lists of strings easier to handle as well.