Parcourir la source

Allow non-ASCII characters in plain strings.

Fixes #11.
Gustavo Niemeyer il y a 11 ans
Parent
commit
de3643d77b
2 fichiers modifiés avec 7 ajouts et 0 suppressions
  1. 1 0
      encode.go
  2. 6 0
      encode_test.go

+ 1 - 0
encode.go

@@ -20,6 +20,7 @@ func newEncoder() (e *encoder) {
 	e = &encoder{}
 	e = &encoder{}
 	e.must(yaml_emitter_initialize(&e.emitter))
 	e.must(yaml_emitter_initialize(&e.emitter))
 	yaml_emitter_set_output_string(&e.emitter, &e.out)
 	yaml_emitter_set_output_string(&e.emitter, &e.out)
+	yaml_emitter_set_unicode(&e.emitter, true)
 	e.must(yaml_stream_start_event_initialize(&e.event, yaml_UTF8_ENCODING))
 	e.must(yaml_stream_start_event_initialize(&e.event, yaml_UTF8_ENCODING))
 	e.emit()
 	e.emit()
 	e.must(yaml_document_start_event_initialize(&e.event, nil, nil, true))
 	e.must(yaml_document_start_event_initialize(&e.event, nil, nil, true))

+ 6 - 0
encode_test.go

@@ -250,6 +250,12 @@ var marshalTests = []struct {
 		&yaml.MapSlice{{"b", 2}, {"a", 1}, {"d", 4}, {"c", 3}, {"sub", yaml.MapSlice{{"e", 5}}}},
 		&yaml.MapSlice{{"b", 2}, {"a", 1}, {"d", 4}, {"c", 3}, {"sub", yaml.MapSlice{{"e", 5}}}},
 		"b: 2\na: 1\nd: 4\nc: 3\nsub:\n  e: 5\n",
 		"b: 2\na: 1\nd: 4\nc: 3\nsub:\n  e: 5\n",
 	},
 	},
+
+	// Encode unicode as utf-8 rather than in escaped form.
+	{
+		map[string]string{"a": "你好"},
+		"a: 你好\n",
+	},
 }
 }
 
 
 func (s *S) TestMarshal(c *C) {
 func (s *S) TestMarshal(c *C) {