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

Supporting Unicode languages #8

Open
JafarH96 opened this issue Jan 24, 2022 · 1 comment
Open

Supporting Unicode languages #8

JafarH96 opened this issue Jan 24, 2022 · 1 comment

Comments

@JafarH96
Copy link

CBOR Swift does not support Unicode languages and to solve this problem you should implement as follows:

In "Extensions" :

public var ascii_bytes: [UInt8] {
        // To supporting unicode languages it should return with .utf8 encoding
        return self.data(using: .ascii)?.bytes ?? self.data(using: .utf8)!.bytes
    }

In "Encoder":

@objc override func encode() -> String {
        
        // To support Unicode languages, the string encoding must be specified before giving the string length
        let asciiBytes = self.ascii_bytes
        let encodedArray = Encoder.prepareByteArray(major: .major3, measure: asciiBytes.count)
        let headerData  = Data(bytes: encodedArray).binary_decimal.hex
        let strData     = Data(bytes: asciiBytes).hexString
        
        return headerData.appending(strData)
    }
@hassan-shahbazi
Copy link
Owner

Thanks for the report. Can you apply changes and make a PR for it?

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

2 participants