本文整理汇总了Golang中github.com/axgle/mahonia.NewDecoder函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDecoder函数的具体用法?Golang NewDecoder怎么用?Golang NewDecoder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDecoder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Strconv
/*
1 Converts single-byte characters in cExpression to double-byte characters.
Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).
2 Converts double-byte characters in cExpression to single-byte characters.
Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).
3 Converts double-byte Katakana characters in cExpression to double-byte Hiragana characters.
Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).
4 Converts double-byte Hiragana characters in cExpression to double-byte Katakana characters.
Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).
5 Converts double-byte characters to UNICODE (wide characters).
6 Converts UNICODE (wide characters) to double-byte characters.
7 Converts cExpression to locale-specific lowercase.
Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).
8 Converts cExpression to locale-specific uppercase.
Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).
13 Converts single-byte characters in cExpression to encoded base64 binary.
14 Converts base64 encoded data in cExpression to original unencoded data.
15 Converts single-byte characters in cExpression to encoded hexBinary.
16 Converts single-byte characters in cExpression to decoded hexBinary
*/
func Strconv(zstr string, zconvertType int) string {
zcharset := ""
switch zconvertType {
case 9: //9 Converts double-byte characters in cExpression to UTF-8
zcharset = getCurrentCP()
dec := mahonia.NewDecoder(zcharset)
return dec.ConvertString(zstr)
case 10: //10 Converts Unicode characters in cExpression to UTF-8
zcharset = "utf16"
dec := mahonia.NewDecoder(zcharset)
return dec.ConvertString(zstr)
case 11: //11 Converts UTF-8 characters in cExpression to double-byte characters.
zcharset = getCurrentCP()
enc := mahonia.NewEncoder(zcharset)
return enc.ConvertString(zstr)
case 12: //12 Converts UTF-8 characters in cExpression to UNICODE characters.
zcharset = "utf16"
enc := mahonia.NewEncoder(zcharset)
return enc.ConvertString(zstr)
}
return zstr
}
示例2: getStockInfo
func getStockInfo(code string) (s *Stock, err error) {
var qturl = "http://qt.gtimg.cn/q=s_"
resp, _ := http.Get(qturl + code)
ctn, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
enc := mahonia.NewDecoder("gbk")
gbct := enc.ConvertString(string(ctn))
fmt.Println(gbct)
if strings.Contains(gbct, "none_match") {
return s, nil
}
inx1 := strings.Index(gbct, "\"")
inx2 := strings.LastIndex(gbct, "\"")
fmt.Println(gbct[inx1+1 : inx2])
ctns := strings.Split(gbct[inx1+1:inx2], "~")
s = &Stock{}
s.Name = ctns[1]
s.Code = code[2:]
s.Area = code[:2]
return
}
示例3: GuPiao
func GuPiao(no string) string {
client := &http.Client{}
url := ""
if strings.HasPrefix(no, "60") || strings.HasPrefix(no, "51") {
url = "http://hq.sinajs.cn/list=sh" + no
} else if strings.HasPrefix(no, "00") || strings.HasPrefix(no, "30") {
url = "http://hq.sinajs.cn/list=sz" + no
}
reqest, err := http.NewRequest("GET", url, nil)
if err != nil {
return "代碼錯誤"
}
reqest.Header.Add("Accept-Language", "zh-CN,zh;q=0.8")
reqest.Header.Add("Content-Type", "text/html; charset=utf-8")
resp, err := client.Do(reqest)
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "代碼錯誤"
}
dec := mahonia.NewDecoder("GBK")
s := dec.ConvertString(string(data))
s = s[strings.Index(s, "\"")+1 : strings.LastIndex(s, "\"")]
s = GuPiaoFormat(s)
fmt.Println(s)
return s
}
示例4: getStockInfoFromSina
func getStockInfoFromSina(s *Stock) {
var qturl = "http://hq.sinajs.cn/list="
resp, _ := http.Get(qturl + s.Area + s.Code)
ctn, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
enc := mahonia.NewDecoder("gbk")
gbct := enc.ConvertString(string(ctn))
if strings.Contains(gbct, "none_match") {
return
}
fmt.Println(s.Area, s.Code, ":", gbct)
inx1 := strings.Index(gbct, "\"")
inx2 := strings.LastIndex(gbct, "\"")
fmt.Println(gbct[inx1+1 : inx2])
ctns := strings.Split(gbct[inx1+1:inx2], ",")
s.Name = ctns[0]
fmt.Println(ctns)
}
示例5: enableInterface
func enableInterface() (name string, err error) {
for win := range system {
cmd := exec.Command("cmd.exe", "/c", `netsh interface show interface name=`+system[win])
out, _ := cmd.StdoutPipe()
err = cmd.Start()
if err != nil {
fmt.Println("enableInteface", err)
return "", err
}
ma := mahonia.NewDecoder("gbk")
buf := ma.NewReader(out)
data := make([]byte, 1<<16)
n, _ := buf.Read(data)
if strings.Contains(string(data[:n]), "管理状态: 已禁用") {
name = system[win]
fmt.Printf("网卡 [%s] 禁用状态,正在启用网卡,请稍等.\n", name)
err = enabled(true, name)
}
cmd.Wait()
}
return name, err
}
示例6: DisplayUrl
func DisplayUrl(zurl string) {
println("loading ...", zurl)
r, err1 := http.Get(zurl)
checkError(err1)
println("complete !", r.StatusCode)
decoder := mahonia.NewDecoder("gb18030") //gb18030可以适用于gb2312
//decoder := mahonia.NewDecoder("utf8")
//decoder := mahonia.NewDecoder("big5")
bs := make([]byte, 5056)
var buf []byte
defer r.Body.Close()
n, err1 := r.Body.Read(bs)
zi := 0
for n > 0 {
if n > 0 {
zi++
buf = append(buf, bs[:n]...)
}
n, err1 = r.Body.Read(bs)
}
println("read complete !", "times:", zi)
_, line, _ := decoder.Translate(buf, true)
println(n, string(line))
}
示例7: base64decode
func (account *Account) base64decode(str string) string {
data, _ := base64.StdEncoding.DecodeString(str)
str = fmt.Sprintf("%s", data)
enc := mahonia.NewDecoder("gbk")
gbk := enc.ConvertString(str)
gbk = strings.Replace(gbk, "\n", "", -1)
return gbk
}
示例8: gbk2utf8
//
// input a reader(gbk), output a reader(utf-8)
//
func gbk2utf8(charset string, r io.Reader) (io.Reader, error) {
if charset != "gb2312" {
return nil, fmt.Errorf("Unsupported charset")
}
decoder := mahonia.NewDecoder("gbk")
reader := decoder.NewReader(r)
return reader, nil
}
示例9: download
// Download the page with or without user specified headers.
func (p *Page) download() (doc *html.Node, err error) {
// Construct the request.
req, err := http.NewRequest("GET", p.ReqUrl.String(), nil)
if err != nil {
return nil, errutil.Err(err)
}
// If special headers were specified, add them to the request.
if p.Settings.Header != nil {
for key, val := range p.Settings.Header {
req.Header.Add(key, val)
}
}
// Do request and read response.
resp, err := http.DefaultClient.Do(req)
if err != nil {
if serr, ok := err.(*url.Error); ok {
if serr.Err == io.EOF {
return nil, errutil.NewNoPosf("Update was empty: %s", p.ReqUrl)
}
}
return nil, errutil.Err(err)
}
defer resp.Body.Close()
// If response contained a client or server error, fail with that error.
if resp.StatusCode >= 400 {
return nil, errutil.Newf("%s: (%d) - %s", p.ReqUrl.String(), resp.StatusCode, resp.Status)
}
// Read the response body to []byte.
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, errutil.Err(err)
}
// Fix charset problems with servers that doesn't use utf-8
charset := "utf-8"
content := string(buf)
types := strings.Split(resp.Header.Get("Content-Type"), ` `)
for _, typ := range types {
if strings.Contains(typ, "charset") {
keyval := strings.Split(typ, `=`)
if len(keyval) == 2 {
charset = keyval[1]
}
}
}
if charset != "utf-8" {
content = mahonia.NewDecoder(charset).ConvertString(content)
}
// Parse response into html.Node.
return html.Parse(strings.NewReader(content))
}
示例10: main
func main() {
enc := mahonia.NewEncoder("gbk")
gbk := enc.ConvertString("失落伐克欧洲杯")
fmt.Println(gbk)
//enc = mahonia.NewEncoder("utf8")
dec := mahonia.NewDecoder("gbk")
utf8 := dec.ConvertString(gbk)
fmt.Println(utf8)
}
示例11: getResult
func getResult(out io.ReadCloser) (result string, err error) {
n := 0
buf := make([]byte, 1<<16)
if runtime.GOOS == "windows" {
gbk := mahonia.NewDecoder("gbk")
reader := gbk.NewReader(out)
n, err = reader.Read(buf)
} else {
n, err = out.Read(buf)
}
return string(buf[:n]), err
}
示例12: getNormalizedFieldName
func (dt *DbfTable) getNormalizedFieldName(name string) (s string) {
e := mahonia.NewEncoder(dt.fileEncoding)
b := []byte(e.ConvertString(name))
if len(b) > 10 {
b = b[0:10]
}
d := mahonia.NewDecoder(dt.fileEncoding)
s = d.ConvertString(string(b))
return
}
示例13: Find
func (this *QQwry) Find(ip string) {
if this.filepath == "" {
return
}
file, err := os.OpenFile(this.filepath, os.O_RDONLY, 0400)
defer file.Close()
if err != nil {
return
}
this.file = file
this.Ip = ip
offset := this.searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4()))
// log.Println("loc offset:", offset)
if offset <= 0 {
return
}
var country []byte
var area []byte
mode := this.readMode(offset + 4)
// log.Println("mode", mode)
if mode == REDIRECT_MODE_1 {
countryOffset := this.readUInt24()
mode = this.readMode(countryOffset)
// log.Println("1 - mode", mode)
if mode == REDIRECT_MODE_2 {
c := this.readUInt24()
country = this.readString(c)
countryOffset += 4
} else {
country = this.readString(countryOffset)
countryOffset += uint32(len(country) + 1)
}
area = this.readArea(countryOffset)
} else if mode == REDIRECT_MODE_2 {
countryOffset := this.readUInt24()
country = this.readString(countryOffset)
area = this.readArea(offset + 8)
} else {
country = this.readString(offset + 4)
area = this.readArea(offset + uint32(5+len(country)))
}
enc := mahonia.NewDecoder("gbk")
this.Country = enc.ConvertString(string(country))
this.City = enc.ConvertString(string(area))
}
示例14: request
func request(method string, url string, cl *http.Client, params url.Values) (string, http.Header, http.Request) {
var err error
var req *http.Request
// ...
//req.Header.Add("If-None-Match", `W/"wyzzy"`)
if method == "post" {
req, err = http.NewRequest("POST", url, strings.NewReader(params.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
} else {
req, err = http.NewRequest("GET", url+"?"+params.Encode(), nil)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36")
req.Header.Set("Origin", "www.campus.rwth-aachen.de")
req.Header.Set("Referer", "https://www.campus.rwth-aachen.de/office/views/campus/redirect.asp")
req.Header.Set("Accept-Language", "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
// for _, c := range cookieJar.cookies {
// req.AddCookie(c)
// }
var resp *http.Response
resp, err = cl.Do(req)
// if cl.Jar != nil {
if rc := readSetCookies(resp.Header); len(rc) > 0 {
cookieJar.SetCookies(req.URL, rc)
}
// }
// spew.Dump(resp.Header)
defer resp.Body.Close()
if err != nil {
fmt.Printf("Error from client.Do: %s\n", err)
}
var bodyString string
//var err2 error
if resp.StatusCode == 200 { // OK
bodyBytes, _ := ioutil.ReadAll(resp.Body)
if utf8.Valid(bodyBytes) {
bodyString = string(bodyBytes)
} else {
enc := mahonia.NewDecoder("latin-1")
bodyString = enc.ConvertString(string(bodyBytes))
}
}
return bodyString, resp.Header, *req
}
示例15: GetCmdResult
func (m *iManIP) GetCmdResult(out io.ReadCloser) (result string, err error) {
if m.Cmd == nil {
return "", errors.New("The cmd not create!")
}
gbk := mahonia.NewDecoder("gbk")
reader := gbk.NewReader(out)
buf := make([]byte, 1<<16)
n, err := reader.Read(buf)
result = string(buf[:n])
return
}