Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode chars #240

Open
erkekin opened this issue Jan 24, 2020 · 3 comments
Open

Unicode chars #240

erkekin opened this issue Jan 24, 2020 · 3 comments

Comments

@erkekin
Copy link

erkekin commented Jan 24, 2020

It doesn't work with emojis and Japanese characters.

@jpsim
Copy link
Owner

jpsim commented Mar 1, 2020

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:

func testMultibyteCharacters() throws {
let example = """
Bulbasaur: フシギダネ
Charmander: ヒトカゲ
Squirtle: ゼニガメ
"""
let object = try Yams.load(yaml: example)
let expectedObject = [
"Bulbasaur": "フシギダネ",
"Charmander": "ヒトカゲ",
"Squirtle": "ゼニガメ"
]
YamsAssertEqual(object, expectedObject)
let yaml = try Yams.dump(object: object, allowUnicode: true)
XCTAssertEqual(yaml, example)
}

@Lakr233
Copy link

Lakr233 commented Dec 24, 2020

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
Copy link

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants