I use goyamlas a tool to create YAML. By downloading and deleting a YAML file, I can format it. I will format the data from the YAML source file into a structure, marshal these bytes, and write the bytes to the output file. But the process converts my Unicode strings to a literal version of the quoted strings, and I don't know how to undo it.
Input Example subtitle.yaml:
line: 你好
I divided everything down to the smallest reproducible problem. Here's the code, using _to catch errors that don't pop up:
package main
import (
"io/ioutil"
//"unicode/utf8"
//"fmt"
"gopkg.in/yaml.v1"
)
type Subtitle struct {
Line string
}
func main() {
filename := "subtitle.yaml"
in, _ := ioutil.ReadFile(filename)
var subtitle Subtitle
_ = goyaml.Unmarshal(in, &subtitle)
out, _ := goyaml.Marshal(&subtitle)
_ = ioutil.WriteFile(filename, out, 0644)
}
Actual output subtitle.yaml:
line: "\u4F60\u597D"
I want to change weirdness in goyamlafter getting the variable out.
, , . , Unicode, 你, , :
l i n e : " \ u 4 F 6 0 \ u 5 9 7 D "
unquote out, , ( )?
subtitle.yaml:
line: "你好"
https://github.com/go-yaml/yaml/issues/11. , @bobince yaml_emitter_set_unicode . C, ( )! encode.go yaml_emitter_set_unicode(&e.emitter, true) 20, , . , API-.