https://github.com/schollz/utfdecode
A simple library to decode a string that contains escaped UTF-16/32 characters into unescaped UTF-16.
https://github.com/schollz/utfdecode
decode golang strings unicode utf-16 utf-32
Last synced: about 1 year ago
JSON representation
A simple library to decode a string that contains escaped UTF-16/32 characters into unescaped UTF-16.
- Host: GitHub
- URL: https://github.com/schollz/utfdecode
- Owner: schollz
- License: mit
- Created: 2020-07-06T13:54:30.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-06T22:36:19.000Z (almost 6 years ago)
- Last Synced: 2025-04-22T10:34:58.635Z (about 1 year ago)
- Topics: decode, golang, strings, unicode, utf-16, utf-32
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# utfdecode
[](https://travis-ci.org/schollz/utfdecode)
[](https://goreportcard.com/report/github.com/schollz/utfdecode)
[](https://gocover.io/github.com/schollz/utfdecode)
[](https://godoc.org/github.com/schollz/utfdecode)
I wanted to convert text containing escaped UTF-16 and/or UTF-32 codes to just UTF-16. This library helps do that. It rejexes for unicde strings and then converts them to UTF-16 [using the standard formula](https://en.wikipedia.org/wiki/UTF-16). The code is small enough that you might just consider copy and pasting :)
For example, the following Go code ([on Go play](https://play.golang.org/p/-NioHUeLZZv)):
```golang
jsonData := `{"text":"utf-16:\u2764\u1F47D\u1F680 utf-32:\u2764\ud83d\udc7d\ud83d\ude80"}`
fmt.Println(utfdecode.Decode(jsonData))
```
will print
```
{"text":"utf-16:❤👽🚀 utf-32:❤👽🚀"}
```
## Contributing
Pull requests are welcome. Feel free to...
- Revise documentation
- Add new features
- Fix bugs
- Suggest improvements
## License
MIT