Ejemplo n.º 1
0
//在命令行执行
func parseSgf(file string) {

	b, err := ioutil.ReadFile(file)

	rInNop := transform.NewReader(bytes.NewReader(b), encoding.Nop.NewDecoder())
	b, _ = ioutil.ReadAll(rInNop)
	NopB := string(b)

	b1 := tryFixSgf(NopB)
	c, err := sgf.ParseSgf(b1)
	if err != nil {
		log.Println("ERR")
	}
	node := c.GameTrees[0].Nodes[0]
	f := func(pName string) string {
		for _, prop := range node.Properties {
			if pName == prop.Ident {
				return strings.Join(prop.Values, ",")
			}
		}
		return ""
	}
	log.Println("dt ", f("DT"))
	log.Println("HA ", f("HA"))
	log.Println("BR ", f("BR"))
	log.Println("WR ", f("WR"))
	log.Println("PB ", f("PB"))
	log.Println("PW ", f("PW"))
	log.Println("RE ", f("RE"))
	log.Println("KM ", f("KM"))
	log.Println("====================")
}
Ejemplo n.º 2
0
func eucjp_to_utf8(str string) (string, error) {
	ret, err := ioutil.ReadAll(transform.NewReader(strings.NewReader(str), japanese.EUCJP.NewDecoder()))
	if err != nil {
		return "", err
	}
	return string(ret), err
}
Ejemplo n.º 3
0
// TestNonRepertoire tests that codes outside of an Encoding's repertoire are
// converted:
//   - to the Unicode replacement character '\ufffd' when decoding to UTF-8,
//   - to the ASCII substitute character '\x1a' when encoding from UTF-8.
func TestNonRepertoire(t *testing.T) {
	testCases := []struct {
		e          encoding.Encoding
		dSrc, eSrc string
	}{
		{charmap.Windows1252, "\x81", "갂"},
		{japanese.EUCJP, "\xfe\xfc", "갂"},
		{japanese.ISO2022JP, "\x1b$B\x7e\x7e", "갂"},
		{japanese.ShiftJIS, "\xef\xfc", "갂"},
		{korean.EUCKR, "\xfe\xfe", "א"},
		{simplifiedchinese.GBK, "\xfe\xfe", "갂"},
		{simplifiedchinese.HZGB2312, "~{z~", "갂"},
		{traditionalchinese.Big5, "\x81\x40", "갂"},
	}
	for _, tc := range testCases {
		for _, direction := range []string{"Decode", "Encode"} {
			enc, want, src := (transform.Transformer)(nil), "", ""
			if direction == "Decode" {
				enc, want, src = tc.e.NewDecoder(), "\ufffd", tc.dSrc
			} else {
				enc, want, src = tc.e.NewEncoder(), "\x1a", tc.eSrc
			}

			dst, err := ioutil.ReadAll(transform.NewReader(strings.NewReader(src), enc))
			if err != nil {
				t.Errorf("%s %v: %v", direction, tc.e, err)
				continue
			}
			if got := string(dst); got != want {
				t.Errorf("%s %v:\ngot  %q\nwant %q", direction, tc.e, got, want)
				continue
			}
		}
	}
}
Ejemplo n.º 4
0
func TransUTF8FromCode(src []byte, code int) ([]byte, error) {
	var rInUTF8 io.Reader
	switch code {
	case GBK:
		rInUTF8 = transform.NewReader(bytes.NewReader(src), simplifiedchinese.GBK.NewDecoder())
		break
	case GB2312:
		rInUTF8 = transform.NewReader(bytes.NewReader(src), simplifiedchinese.HZGB2312.NewDecoder())
		break
	default:
		return nil, NOT_SUPPORTED_CODE
	}

	out, _ := ioutil.ReadAll(rInUTF8)
	return out, nil
}
Ejemplo n.º 5
0
func Decode(s []byte) ([]byte, error) {
	f := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GBK.NewDecoder())
	d, e := ioutil.ReadAll(f)
	if e != nil {
		return nil, e
	}
	return d, nil
}
Ejemplo n.º 6
0
func TestBasics(t *testing.T) {
	for _, tc := range basicTestCases {
		for _, direction := range []string{"Decode", "Encode"} {
			newTransformer, want, src := (func() transform.Transformer)(nil), "", ""
			wPrefix, sPrefix := "", ""
			if direction == "Decode" {
				newTransformer, want, src = tc.e.NewDecoder, tc.utf8, tc.encoded
				wPrefix, sPrefix = "", tc.encPrefix
			} else {
				newTransformer, want, src = tc.e.NewEncoder, tc.encoded, tc.utf8
				wPrefix, sPrefix = tc.encPrefix, ""
			}

			dst := make([]byte, len(wPrefix)+len(want))
			nDst, nSrc, err := newTransformer().Transform(dst, []byte(sPrefix+src), true)
			if err != nil {
				t.Errorf("%v: %s: %v", tc.e, direction, err)
				continue
			}
			if nDst != len(wPrefix)+len(want) {
				t.Errorf("%v: %s: nDst got %d, want %d",
					tc.e, direction, nDst, len(wPrefix)+len(want))
				continue
			}
			if nSrc != len(sPrefix)+len(src) {
				t.Errorf("%v: %s: nSrc got %d, want %d",
					tc.e, direction, nSrc, len(sPrefix)+len(src))
				continue
			}
			if got := string(dst); got != wPrefix+want {
				t.Errorf("%v: %s:\ngot  %q\nwant %q",
					tc.e, direction, got, wPrefix+want)
				continue
			}

			for _, n := range []int{0, 1, 2, 10, 123, 4567} {
				input := sPrefix + strings.Repeat(src, n)
				sr := strings.NewReader(input)
				g, err := ioutil.ReadAll(transform.NewReader(sr, newTransformer()))
				if err != nil {
					t.Errorf("%v: %s: ReadAll: n=%d: %v", tc.e, direction, n, err)
					continue
				}
				if len(g) == 0 && len(input) == 0 {
					// If the input is empty then the output can be empty,
					// regardless of whatever wPrefix is.
					continue
				}
				got1, want1 := string(g), wPrefix+strings.Repeat(want, n)
				if got1 != want1 {
					t.Errorf("%v: %s: ReadAll: n=%d\ngot  %q\nwant %q",
						tc.e, direction, n, trim(got1), trim(want1))
					continue
				}
			}
		}
	}
}
Ejemplo n.º 7
0
Archivo: main.go Proyecto: kkdai/webpic
func BigDecodeUTF8(s []byte) ([]byte, error) {
	I := bytes.NewReader(s)
	O := transform.NewReader(I, traditionalchinese.Big5.NewDecoder())
	d, e := ioutil.ReadAll(O)
	if e != nil {
		return nil, e
	}
	return d, nil
}
Ejemplo n.º 8
0
func transfer(b []byte) string {
	rInUTF8 := transform.NewReader(bytes.NewReader(b), simplifiedchinese.GBK.NewDecoder())
	gbk, err := ioutil.ReadAll(rInUTF8)
	if err != nil {
		log.Println("[wanring]", err)
		return ""
	}
	return string(gbk)
}
Ejemplo n.º 9
0
func utf8_to_sjis(str string) string {
	iostr := strings.NewReader(str)
	rio := transform.NewReader(iostr, japanese.ShiftJIS.NewEncoder())
	ret, err := ioutil.ReadAll(rio)
	if err != nil {
		return ""
	}
	return string(ret)
}
Ejemplo n.º 10
0
func conUtf(s string) string {
	sr := strings.NewReader(s)
	tr := transform.NewReader(sr, charmap.Windows1251.NewDecoder())
	buf, err := ioutil.ReadAll(tr)
	if err != err {
		// обработка ошибки
	}

	return string(buf)
}
Ejemplo n.º 11
0
func benchmark(b *testing.B, direction string, enc encoding.Encoding) {
	_, src, newTransformer, err := load(direction, enc)
	if err != nil {
		b.Fatal(err)
	}
	b.SetBytes(int64(len(src)))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		r := transform.NewReader(bytes.NewReader(src), newTransformer())
		io.Copy(ioutil.Discard, r)
	}
}
Ejemplo n.º 12
0
func utf8DocByEucjpUrl(eucjpUrl string) *goquery.Document {
	resp, err := http.Get(eucjpUrl)
	defer resp.Body.Close()
	if err != nil {
		log.Fatal(err)
	}

	doc, err := goquery.NewDocumentFromReader(transform.NewReader(resp.Body, japanese.EUCJP.NewDecoder()))
	if err != nil {
		log.Fatal("Fail to ", err.Error(), ", for: ", eucjpUrl)
	}
	return doc
}
Ejemplo n.º 13
0
// TestBig5CircumflexAndMacron tests the special cases listed in
// http://encoding.spec.whatwg.org/#big5
// Note that these special cases aren't preserved by round-tripping through
// decoding and encoding (since
// http://encoding.spec.whatwg.org/index-big5.txt does not have an entry for
// U+0304 or U+030C), so we can't test this in TestBasics.
func TestBig5CircumflexAndMacron(t *testing.T) {
	src := "\x88\x5f\x88\x60\x88\x61\x88\x62\x88\x63\x88\x64\x88\x65\x88\x66 " +
		"\x88\xa2\x88\xa3\x88\xa4\x88\xa5\x88\xa6"
	want := "ÓǑÒ\u00ca\u0304Ế\u00ca\u030cỀÊ " +
		"ü\u00ea\u0304ế\u00ea\u030cề"
	dst, err := ioutil.ReadAll(transform.NewReader(
		strings.NewReader(src), traditionalchinese.Big5.NewDecoder()))
	if err != nil {
		t.Fatal(err)
	}
	if got := string(dst); got != want {
		t.Fatalf("\ngot  %q\nwant %q", got, want)
	}
}
Ejemplo n.º 14
0
//在命令行执行
func main() {
	//	userFile := "/Users/lihexing/Downloads/002/i.sgf"
	//	userFile := "/Users/lihexing/Downloads/002/m.sgf"
	//	userFile := "/Users/lihexing/Documents/kifu/ys.sgf"
	//	userFile := "/Users/lihexing/Documents/kifu/pa.sgf"
	//	userFile := "/Users/lihexing/Documents/kifu/cl.sgf"
	//	userFile := "/Users/lihexing/Documents/kifu/wt.sgf"
	//	userFile := "/Users/lihexing/Documents/12月1日处理/棋谱处理/已上传/LG杯/11/第11届LG杯32强赛_2006-05-15_朴永训_古力_62839.sgf"
	//	userFile := "/Users/lihexing/Documents/12月1日处理/棋谱处理/未上传/分好类待上传/中国晚报杯/2003成都晚报队选拔赛_2003-12-13_沈逢春_龙霖_61565.sgf"
	//	userFile := "/Users/lihexing/Documents/棋谱待解决问题/2/日本十段战/第51期日本十段战挑战赛五番棋第五局_2013-04-26_井山裕太_结城聪_107576.sgf"
	//	userFile := "/Users/lihexing/Documents/棋谱待解决问题/2/日本十段战/第8期十段战_1969-12-18_工藤纪夫_武宫正树_101715.sgf"
	//	userFile := "/Users/lihexing/Documents/棋谱待解决问题/2/应氏杯/第二届应氏杯第一轮_1992-07-13_王铭琬_石井邦生_51138.sgf"
	//	userFile := "/Users/lihexing/Documents/kifu/第9届理光杯第一轮_2008-12-22_彭荃_廖行文_48857.sgf"
	//	userFile := "/Users/lihexing/Downloads/第9届理光杯第一轮_2008-12-22_彭荃_廖行文_48857.sgf"

	//	userFile := "/Users/lihexing/Desktop/第24届富士通杯决赛(周睿羊讲解)_2011-08-14_朴廷桓_邱峻_73705.sgf"
	//	userFile := "/Users/lihexing/Downloads/第24届富士通杯决赛(周睿羊讲解)-73705.sgf"

	//	userFile := "/Users/lihexing/Desktop/第3期名人战三次预选_1978-11-30_山部俊郎_武宫正树_61320.sgf"
	//	userFile := "/Users/lihexing/Downloads/第3期名人战三次预选-61320.sgf"

	//	userFile := "/Users/lihexing/Desktop/DT_PB_PW_BR_WR_RE_第2届北林弘通杯围棋争霸赛8强赛_2013-12-08_别中华_杨宇轩_117622.sgf"
	//	userFile := "/Users/lihexing/Desktop/第42期本因坊战循环赛(日本每日新闻主办)_1987-03-05_山城宏_林海峰_50781.sgf"//给晓光处理手数
	//	userFile := "/Users/lihexing/Downloads/2012首届北林弘通杯围棋争霸赛3、4名决定战-92553.sgf" //弘通官网下载
	userFile := "/Users/lihexing/Desktop/2012首届北林弘通杯围棋争霸赛3、4名决定战_2012-10-14_陈其洲_李应硕_92553.sgf" //爬虫下载

	file, err := os.Open(userFile)
	defer file.Close()
	if err != nil {
		fmt.Println(userFile, err)
		return
	}

	b, err := ioutil.ReadAll(file)

	rInNop := transform.NewReader(bytes.NewReader(b), encoding.Nop.NewDecoder())
	b, _ = ioutil.ReadAll(rInNop)
	NopB := string(b)
	//	log.Println("string(b) ", NopB)
	parseKifu(NopB)

	//	rInGBK := transform.NewReader(bytes.NewReader(b), simplifiedchinese.GBK.NewDecoder())
	//	b, _ = ioutil.ReadAll(rInGBK)
	//	GbkB := string(b)
	////	log.Println("rInGBK ", GbkB)
	//	parseKifu(GbkB)

}
Ejemplo n.º 15
0
func read(userFile string) string {

	file, err := os.Open(userFile)
	defer file.Close()
	if err != nil {
		fmt.Println(userFile, err)
		return "fileOpenERR"
	}

	b, err := ioutil.ReadAll(file)

	rInNop := transform.NewReader(bytes.NewReader(b), encoding.Nop.NewDecoder())
	b, _ = ioutil.ReadAll(rInNop)
	NoOK := string(b)
	return parseKifu(NoOK)
}
Ejemplo n.º 16
0
// NewReader returns an io.Reader that converts the content of r to UTF-8.
// It calls DetermineEncoding to find out what r's encoding is.
func NewReader(r io.Reader, contentType string) (io.Reader, error) {
	preview := make([]byte, 1024)
	n, err := io.ReadFull(r, preview)
	switch {
	case err == io.ErrUnexpectedEOF:
		preview = preview[:n]
		r = bytes.NewReader(preview)
	case err != nil:
		return nil, err
	default:
		r = io.MultiReader(bytes.NewReader(preview), r)
	}

	if e, _, _ := DetermineEncoding(preview, contentType); e != encoding.Nop {
		r = transform.NewReader(r, e.NewDecoder())
	}
	return r, nil
}
Ejemplo n.º 17
0
func ParseIEpg(r io.Reader) (*IEpg, error) {
	var err error
	iepg := &IEpg{}
	iepg.Body = make([]byte, 0)
	rio := transform.NewReader(r, japanese.ShiftJIS.NewDecoder())
	scanner := bufio.NewScanner(rio)
	kv := make(map[string]string)
	for scanner.Scan() {
		line := scanner.Text()
		if line == "" {
			for scanner.Scan() {
				line = scanner.Text()
				iepg.Body = append(iepg.Body, []byte(line)...)
			}
			break
		}
		tmp := strings.Split(line, ": ")
		if len(tmp) != 2 {
			fmt.Printf("%q", line)
			continue
		}
		kv[tmp[0]] = tmp[1]
	}
	if err := scanner.Err(); err != nil {
		return nil, fmt.Errorf("IEPG scan error: %v", err)
	}
	iepg.StationId = kv["station"]
	iepg.StationName = kv["station-name"]
	iepg.ProgramTitle = kv["program-title"]
	if kv["program-id"] != "" {
		if iepg.ProgramId, err = strconv.Atoi(kv["program-id"]); err != nil {
			return nil, fmt.Errorf("Could not parse `program-id` - %q in %v: %v ", kv["program-id"], kv, err)
		}
	}
	start_time := fmt.Sprintf(datetime_format, kv["year"], kv["month"], kv["date"], kv["start"])
	if iepg.StartAt, err = time.Parse(datetime_layout, start_time); err != nil {
		return nil, fmt.Errorf("Could not parse start time - %q in %v: %v", start_time, kv, err)
	}
	end_time := fmt.Sprintf(datetime_format, kv["year"], kv["month"], kv["date"], kv["end"])
	if iepg.EndAt, err = time.Parse(datetime_layout, end_time); err != nil {
		return nil, fmt.Errorf("Could not parse end time - %q in %v: %v", end_time, kv, err)
	}
	return iepg, nil
}
Ejemplo n.º 18
0
func TestFiles(t *testing.T) {
	for _, dir := range []string{"Decode", "Encode"} {
		for _, tf := range testdataFiles {
			dst, src, newTransformer, err := load(dir, tf.enc)
			if err != nil {
				t.Errorf("%s, %s: load: %v", dir, tf.enc, err)
				continue
			}
			buf := bytes.NewBuffer(nil)
			r := transform.NewReader(bytes.NewReader(src), newTransformer())
			if _, err := io.Copy(buf, r); err != nil {
				t.Errorf("%s, %s: copy: %v", dir, tf.enc, err)
				continue
			}
			if !bytes.Equal(buf.Bytes(), dst) {
				t.Errorf("%s, %s: transformed bytes did not match golden file", dir, tf.enc)
				continue
			}
		}
	}
}
Ejemplo n.º 19
0
func TestReplacement(t *testing.T) {
	for _, direction := range []string{"Decode", "Encode"} {
		enc, want := (transform.Transformer)(nil), ""
		if direction == "Decode" {
			enc = encoding.Replacement.NewDecoder()
			want = "\ufffd"
		} else {
			enc = encoding.Replacement.NewEncoder()
			want = "AB\x00CD\ufffdYZ"
		}
		sr := strings.NewReader("AB\x00CD\x80YZ")
		g, err := ioutil.ReadAll(transform.NewReader(sr, enc))
		if err != nil {
			t.Errorf("%s: ReadAll: %v", direction, err)
			continue
		}
		if got := string(g); got != want {
			t.Errorf("%s:\ngot  %q\nwant %q", direction, got, want)
			continue
		}
	}
}
Ejemplo n.º 20
0
func encodingReader(body []byte, contentType string) (io.Reader, error) {
	preview := make([]byte, 1024)
	var r io.Reader = bytes.NewReader(body)
	n, err := io.ReadFull(r, preview)
	switch {
	case err == io.ErrUnexpectedEOF:
		preview = preview[:n]
		r = bytes.NewReader(preview)
	case err != nil:
		return nil, err
	default:
		r = io.MultiReader(bytes.NewReader(preview), r)
	}

	e, _, certain := charset.DetermineEncoding(preview, contentType)
	if !certain && e == charmap.Windows1252 && utf8.Valid(body) {
		e = encoding.Nop
	}
	if e != encoding.Nop {
		r = transform.NewReader(r, e.NewDecoder())
	}
	return r, nil
}
Ejemplo n.º 21
0
func New(reader io.Reader) *tokenizer {
	return &tokenizer{bufio.NewReader(transform.NewReader(reader, normalize)), 0}
}
Ejemplo n.º 22
0
// path: begin response output with noted subdirectory
// resume: resume from this point (takes precedence over path)
func (api Api) List(cpcode uint, storage_group, path, resume string, limit uint, bad_req chan ReqFail) (listResp ListResponse, err error) {
	host := storage_group + "-nsu.akamaihd.net"
	action := fmt.Sprintf("version=%s&action=list&format=xml&max_entries=%d", version, limit)
	var rel_path string
	if resume != "" {
		rel_path = resume
	} else {
		if strings.HasPrefix(path, "/") {
			path = path[1:]
		}
		rel_path = fmt.Sprintf("/%d/%s", cpcode, path)
	}
	ip_info, _ := net.LookupHost(host)
	ip := ip_info[0]
	abs_path := "http://" + host + rel_path
	req, err := http.NewRequest("GET", abs_path, nil)
	req.Header.Add("X-Akamai-ACS-Action", action)
	api.auth(req, rel_path, action)
	dumpReq, err := httputil.DumpRequestOut(req, true)
	if err != nil {
		dumpReq = []byte(fmt.Sprintf("ERROR: could not dump http request: %s", err.Error()))
	}
	resp, err := api.client.Do(req)
	defer resp.Body.Close()
	var dumpResp []byte
	if resp != nil {
		dumpResp, err = httputil.DumpResponse(resp, true)
		if err != nil {
			dumpResp = []byte(fmt.Sprintf("ERROR: could not dump http response: %s", err.Error()))
		}
	}
	if err != nil {
		errMsg := fmt.Sprintf("GET '%s' failed: %s", abs_path, err.Error())
		err = errors.New(errMsg)
		if bad_req != nil {
			bad_req <- ReqFail{ip, "ERROR: " + errMsg, dumpReq, dumpResp}
		}
		return
	}
	if resp.StatusCode != http.StatusOK {
		resp_bytes := make([]byte, 50)
		var bytes_read int
		bytes_read, err = resp.Body.Read(resp_bytes)
		resp_string := string(resp_bytes[:bytes_read])
		err = NewHTTPErrorWithText(resp, resp_string)
		if bad_req != nil {
			bad_req <- ReqFail{ip, "BAD STATUSCODE: " + err.Error(), dumpReq, dumpResp}
		}
		return
	}

	decoder := xml.NewDecoder(resp.Body)

	// from http://grokbase.com/t/gg/golang-nuts/13bds55y8f/go-nuts-xml-parser
	decoder.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
		// Windows-1252 is a superset of ISO-8859-1.
		if charset == "iso-8859-1" || charset == "ISO-8859-1" {
			return transform.NewReader(input, charmap.Windows1252.NewDecoder()), nil
		}
		return nil, fmt.Errorf("unsupported charset: %q", charset)
	}

	err = decoder.Decode(&listResp)
	if err != nil {
		err = errors.New(fmt.Sprintf("response of GET '%s' decode error: %s", abs_path, err.Error()))
		if bad_req != nil {
			bad_req <- ReqFail{ip, err.Error(), dumpReq, dumpResp}
		}
	}
	return
}
Ejemplo n.º 23
0
func transformString(t transform.Transformer, s string) (string, error) {
	r := transform.NewReader(strings.NewReader(s), t)
	b, err := ioutil.ReadAll(r)
	return string(b), err
}
Ejemplo n.º 24
0
func (jst *IDCGeneral) genIDC(port string, timeout int, readtype int) ([]byte, error) {
	os.Remove(string(wzfile))
	os.Remove(string(bmfile))

	//获得端口描述
	s, p, err := driverlayer.GetPortDescription(port)
	if err != nil {
		utils.Error("receive shensi port error %s  ", port)
		return nil, err
	}
	utils.Debug("begin to open port %s %d", s, p)
	var r uintptr
	if strings.EqualFold(s, "COM") {
		r, _, _ = dllinterop.CallProc(uintptr(jst.initcomm), uintptr(p))
	} else if strings.EqualFold(s, "USB") {
		p = p + 1000
		r, _, _ = dllinterop.CallProc(uintptr(jst.initcomm), uintptr(p))
	}
	if int32(r) != 144 {
		utils.Error("shensi init com error %d", int32(r))
		return nil, err
	}

	//关闭端口
	defer dllinterop.CallProc(uintptr(jst.closecomm), uintptr(p))
	var punc int32
	var punsn int64
	step := 1
	timed, _ := time.ParseDuration(strconv.Itoa(timeout) + "ms")

	remiantime := timed * time.Millisecond

	var (
		basemsg []byte
		bmpmsg  []byte
	)

	//检查二代证的放置位置
	for {
		switch step {
		case 1:
			{
				r, _, _ = dllinterop.CallProc(uintptr(jst.findcard), uintptr(p), uintptr(unsafe.Pointer(&punc)), uintptr(0))
				utils.Debug("start find card result %d", int32(r))
				if r == 159 {
					utils.Debug("find card success")
					step = 2
				}
			}
			break
		case 2:
			{
				r, _, _ = dllinterop.CallProc(uintptr(jst.selectcard), uintptr(p), uintptr(unsafe.Pointer(&punsn)), uintptr(0))
				if r == 144 {
					utils.Debug("select card success")
					step = 3
				} else {
					utils.Debug("start select card result %d", int32(r))
				}
			}
		case 3:
			{
				var (
					wzlen int
					bmlen int
				)
				basemsg = make([]byte, 1024, 1024)
				bmpmsg = make([]byte, 1024, 1024)
				r, _, _ = dllinterop.CallProc(uintptr(jst.readbasemsg), uintptr(p),
					uintptr(unsafe.Pointer(&basemsg[0])),
					uintptr(unsafe.Pointer(&wzlen)),
					uintptr(unsafe.Pointer(&bmpmsg[0])),
					uintptr(unsafe.Pointer(&bmlen)),
					uintptr(0))
				if r == 144 {
					utils.Debug("end idc card read")
					basemsg = basemsg[0:wzlen]
					bmpmsg = bmpmsg[0:bmlen]
					goto readsuccess
				} else {
					utils.Debug("start select card result %d", int32(r))
				}
			}

		}

		remiantime = remiantime - 1000*time.Millisecond
		if remiantime <= 0 {
			break
		}
		time.Sleep(1000 * time.Millisecond)
		if remiantime <= 0 {
			return nil, driverlayer.ErrIOTimeOut
		}
	}

readsuccess:

	outinfo := make([]byte, 0, 1000)

	rInUTF8 := transform.NewReader(bytes.NewReader(basemsg[0:30]), unicode.UTF16(true, false).NewDecoder())
	out, _ := ioutil.ReadAll(rInUTF8)

	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[30:32]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[32:36]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[36:52]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[52:122]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[122:158]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[158:188]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[188:204]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[204:220]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)

	//只读基础ixnxi
	if readtype == 1 {
		return outinfo, nil
	} else {
		outinfo = append(outinfo, '|')
		return outinfo, nil
	}
}
Ejemplo n.º 25
0
func readAll(r io.Reader) ([]byte, error) {
	r = transform.NewReader(r, tran)
	return ioutil.ReadAll(r)
}
Ejemplo n.º 26
0
func (meta *ResourceMetadata) DecodeBody() io.Reader {
	encoding := DetermineEncoding(meta.ParsedType, meta.res.Header())
	return transform.NewReader(meta.res.Body(), encoding.NewDecoder())
}
Ejemplo n.º 27
0
func ExampleDecodeWindows1252() {
	sr := strings.NewReader("Gar\xe7on !")
	tr := transform.NewReader(sr, charmap.Windows1252.NewDecoder())
	io.Copy(os.Stdout, tr)
	// Output: Garçon !
}