Beispiel #1
0
func main() {
	ss := Str("f**k your mother")

	le := ss.Encode(strings.CP_UTF16_LE)
	for _, ch := range le {
		Printf("%02X ", ch)
	}
	Println()
	Println(strings.Decode(le, strings.CP_UTF16_LE))

	be := ss.Encode(strings.CP_UTF16_BE)
	for _, ch := range be {
		Printf("%02X ", ch)
	}
	Println()
	Println(strings.Decode(be, strings.CP_UTF16_BE))

	session, _ := http.NewSession()
	session.SetProxy("localhost", 6789)
	session.SetTimeout(0.1)

	resp, err2 := session.Get("https://www.google.com/")

	if err, ok := err2.(*http.HttpError); ok {
		Println("timeout", err.Timeout, err)
	}

	if resp != nil {
		Println("resp", len(resp.Content))
	}

	Console.Pause("f**k")
}
Beispiel #2
0
func ReadTextToLines(filename strings.String) ([]strings.String, error) {
	file, err := os.Open(string(filename))
	if err != nil {
		return nil, err
	}

	defer file.Close()

	buf, err := ioutil.ReadAll(file)
	if err != nil {
		return nil, err
	}

	var text strings.String

	switch {
	case bytes.Equal(buf[:3], strings.BOM_UTF8):
		text = strings.Decode(buf[3:], strings.CP_UTF8)

	case bytes.Equal(buf[:2], strings.BOM_UTF16_LE):
		text = strings.Decode(buf[2:], strings.CP_UTF16_LE)

	case bytes.Equal(buf[:2], strings.BOM_UTF16_BE):
		text = strings.Decode(buf[2:], strings.CP_UTF16_BE)

	default:
		if isAnsiAsUtf8(buf) {
			text = strings.Decode(buf, strings.CP_UTF8)
		} else {
			text = strings.Decode(buf, strings.CP_GBK)
		}
	}

	return text.SplitLines(), nil
}
Beispiel #3
0
func openPage(session *http.Session, url String) (doc *goquery.Document) {
	resp := session.Get(url)

	doc, err := goquery.NewDocumentFromReader(strings.Decode(resp.Content, resp.Encoding).NewReader())
	RaiseIf(err)

	return
}
Beispiel #4
0
func (self *magicByteArray) UnmarshalJSON(data []byte) (err error) {
	str := strings.Decode(data, strings.CP_UTF8)
	str = str[1 : len(str)-1]
	if len(str) > len(self) {
		str = str[:len(self)]
	}
	copy(self[:], str[:])
	return
}
Beispiel #5
0
func (self *textByteArray) UnmarshalJSON(data []byte) (err error) {
	str := strings.Decode(data, strings.CP_UTF8).Encode(utility.ENCODING)
	str = str[1 : len(str)-1]
	if len(str) > len(self) {
		str = str[:len(self)]
	}
	copy(self[:], str[:])
	return
}
Beispiel #6
0
func openPage(session *http.Session, url String) (doc *goquery.Document, err error) {
	resp, err := session.Get(url)

	if err != nil {
		return nil, err
	}

	doc, err = goquery.NewDocumentFromReader(strings.Decode(resp.Content, resp.Encoding).NewReader())
	return
}
Beispiel #7
0
func testEncoding() {
	ss := Str("身喰らう蛇")

	Println("orig", ss)

	text := ss.Encode(strings.CP_UTF8)
	for _, ch := range text {
		Printf("%02X ", ch)
	}

	Println()
	Println(strings.Decode(text, strings.CP_UTF8))
	Println()

	text = ss.Encode(strings.CP_SHIFT_JIS)
	for _, ch := range text {
		Printf("%02X ", ch)
	}

	s := string(text)

	Println()

	v := url.Values{}

	v.Set("f**k", s)

	for i := 0; i != len(s); i++ {
		Printf("%02X ", s[i])
	}

	Println()
	Println(v.Encode())
	Println()

	gg := strings.Decode(text, strings.CP_GBK)
	Println(gg)

	gg = strings.Decode(text, strings.CP_SHIFT_JIS)
	Println(gg)
}