Created
March 28, 2017 11:30
-
-
Save suapapa/5d231e77f19bb02b367169a54f369c9f to your computer and use it in GitHub Desktop.
encoding to euckr in go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// https://github.com/gophercon/2016-talks/blob/master/MarcelVanLohuizen-TextSubrepo/slides.pdf | |
import ( | |
"log" | |
"golang.org/x/text/encoding/korean" | |
"golang.org/x/text/transform" | |
) | |
func main() { | |
src := "아름다운 우리말" | |
exp := "\xbe\xc6\xb8\xa7\xb4\xd9\xbf\xee \xbf\xec\xb8\xae\xb8\xbb" | |
got, n, err := transform.String(korean.EUCKR.NewEncoder(), src) | |
if err != nil { | |
panic(err) | |
} | |
if got != exp { | |
panic("no match") | |
} | |
log.Println([]byte(got), n) // 22 <= 3(UTF-8) * 7(chars) + 1(a space char) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment