github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/chardet/example_test.go (about) 1 package chardet_test 2 3 import ( 4 "fmt" 5 "github.com/insionng/yougam/plugins/chardet" 6 ) 7 8 var ( 9 zh_gb18030_text = []byte{ 10 71, 111, 202, 199, 71, 111, 111, 103, 108, 101, 233, 95, 176, 108, 181, 196, 210, 187, 214, 214, 190, 142, 215, 103, 208, 205, 163, 172, 129, 75, 176, 108, 11 208, 205, 163, 172, 178, 162, 190, 223, 211, 208, 192, 172, 187, 248, 187, 216, 202, 213, 185, 166, 196, 220, 181, 196, 177, 224, 179, 204, 211, 239, 209, 212, 12 161, 163, 10, 13 } 14 ) 15 16 func ExampleTextDetector() { 17 detector := chardet.NewTextDetector() 18 result, err := detector.DetectBest(zh_gb18030_text) 19 if err == nil { 20 fmt.Printf( 21 "Detected charset is %s, language is %s", 22 result.Charset, 23 result.Language) 24 } 25 // Output: 26 // Detected charset is GB-18030, language is zh 27 }