简体   繁体   中英

How to set the character encoding in a yaml file

We are working with the simple backend for the new Rails 2.2 i18n system, and I wanted to know the proper syntax for setting the encoding in a yaml file.

On other words what is the yaml for this xml:

<?xml encoding="UTF-8" ?>

You can't define the encoding in YAML. But there's also no need to, since the encoding is done at the file level and is transparent to the YAML and its parsing. When writing a YAML document, this is all you need to remember.

On the file level, YAML 1.1 supports UTF-8 and UTF-16 but not UTF-32. The full details of the 1.1 specification is that

All characters [...] are Unicode code points. Each such code point is written as one or more octets depending on the character encoding used. Note that in UTF-16, characters above #xFFFF are written as four octets, using a surrogate pair. A YAML processor must support the UTF-16 and UTF-8 character encodings. If a character stream does not begin with a byte order mark (#FEFF), the character encoding shall be UTF-8. Otherwise it shall be either UTF-8, UTF-16 LE or UTF-16 BE as indicated by the byte order mark. On output, it is recommended that a byte order mark should only be emitted for UTF-16 character encodings. Note that the UTF-32 encoding is explicitly not supported.

For YAML 1.2, UTF-32 is supported as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM