The API data field only supports ASCII encoding -- but I need to support Unicode (emoji, foreign characters, etc.)
I'd like to encode the user's text input as an escaped unicode string:
let textContainingUnicode = """ Let's go 🏊 in the 🌊. And some new lines. """ let result = textContainingUnicode.unicodeScalars.map { $0.escaped(asASCII: true)} .joined(separator: "") .replacingOccurrences( of: "\\\\u\\{(.+?(?=\\}))\\}", <- converting swift format \\u{****} with: "\\\\U$1", <- into format python expects options: .regularExpression) result here is "Let\'s go \U0001F3CA in the \U0001F30A.\n And some new lines."
And on the server decoding with python:
codecs.decode("Let\\'s go \\U0001F3CA in the \\U0001F30A.\\n And some new lines.\n", 'unicode_escape')
But this smells funny -- do i really need to do so much string manipulation in swift to get the escaped unicode? Are these formats not standardized across languages.