diff options
author | Wim <wim@42.be> | 2018-05-11 21:54:32 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2018-05-11 21:54:32 +0200 |
commit | bf0b9959d1b81d6362a390baaee70f2102fb2d58 (patch) | |
tree | 61f2e71367884883cb9f68d7ac55cdcbb5dce908 /vendor/github.com/dfordsoft/golib/ic/ic.go | |
parent | 406a54b597271add1e297231e6f260895eff8f1d (diff) | |
download | matterbridge-msglm-bf0b9959d1b81d6362a390baaee70f2102fb2d58.tar.gz matterbridge-msglm-bf0b9959d1b81d6362a390baaee70f2102fb2d58.tar.bz2 matterbridge-msglm-bf0b9959d1b81d6362a390baaee70f2102fb2d58.zip |
Add vendor github.com/dfordsoft/golib/ic
Diffstat (limited to 'vendor/github.com/dfordsoft/golib/ic/ic.go')
-rw-r--r-- | vendor/github.com/dfordsoft/golib/ic/ic.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/github.com/dfordsoft/golib/ic/ic.go b/vendor/github.com/dfordsoft/golib/ic/ic.go new file mode 100644 index 00000000..9e414e36 --- /dev/null +++ b/vendor/github.com/dfordsoft/golib/ic/ic.go @@ -0,0 +1,31 @@ +package ic + +import "log" + +// Convert convert bytes from CJK or UTF-8 to UTF-8 or CJK +func Convert(from string, to string, src []byte) []byte { + if to == "utf-8" { + out, e := ToUTF8(from, src) + if e == nil { + return out + } + log.Printf("converting from %s to UTF-8 failed: %v", from, e) + return src + } + + if from == "utf-8" { + out, e := FromUTF8(to, src) + if e == nil { + return out + } + log.Printf("converting from UTF-8 to %s failed: %v", to, e) + return src + } + log.Println("only converting between CJK encodings and UTF-8 is supported") + return src +} + +// ConvertString convert string from CJK or UTF-8 to UTF-8 or CJK +func ConvertString(from string, to string, src string) string { + return string(Convert(from, to, []byte(src))) +} |