jpsim / Yams

A Sweet and Swifty YAML parser.
https://jpsim.com/Yams
MIT License
1.11k stars 141 forks source link

Unicode chars #240

Open erkekin opened 4 years ago

erkekin commented 4 years ago

It doesn't work with emojis and Japanese characters.

jpsim commented 4 years ago

Can you please share more information for us to look into this as a possible issue?

For what it's worth we have tests validating some multi-byte unicode character use cases: https://github.com/jpsim/Yams/blob/5fa313eae1ca127ad3c706e14c564399989cb1b1/Tests/YamsTests/SpecTests.swift#L19-L36

Lakr233 commented 3 years ago

I got something [wrong/not working as expect] with it I think

(PTFoundation.CodeClip) $R0 = {
  name = "测试/1"
  code = "echo \'test\'"
  section = "测试栏目+:/\\!#@$%#^$*(*&)"
  executor = nil
  target = nil
  targetLink = 0 values {}
}

resulting

name: "\u6D4B\u8BD5/1"
code: echo 'test'
section: "\u6D4B\u8BD5\u680F\u76EE+:/\\!#@$%#^$*(*&)"
executor: unknown
target: unknown
link: []
leonidmelnyk commented 1 year ago

@Lakr233 as a workaround, you can apply a transformation to convert the Unicode codes into valid chars:

extension StringTransform {
    static let unicodeToAny = StringTransform("Hex-Any")
}

let yamlString = try? YAMLEncoder().encode(object)
return yamlString?.applyingTransform(.unicodeToAny, reverse: false)