summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/paulrosania/go-charset/charset/ascii.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-07-07 23:34:05 +0200
committerWim <wim@42.be>2017-07-07 23:34:05 +0200
commita0938d93869904ebf6d9938485c248b976150fac (patch)
treea12fad5acdceeec93a28efb600ca62b9fdfb40a5 /vendor/github.com/paulrosania/go-charset/charset/ascii.go
parent2338c69d402ad3779f4e2a2f38ac800ceca656b9 (diff)
downloadmatterbridge-msglm-a0938d93869904ebf6d9938485c248b976150fac.tar.gz
matterbridge-msglm-a0938d93869904ebf6d9938485c248b976150fac.tar.bz2
matterbridge-msglm-a0938d93869904ebf6d9938485c248b976150fac.zip
Add go-charset and chardet to vendor
Diffstat (limited to 'vendor/github.com/paulrosania/go-charset/charset/ascii.go')
-rw-r--r--vendor/github.com/paulrosania/go-charset/charset/ascii.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/github.com/paulrosania/go-charset/charset/ascii.go b/vendor/github.com/paulrosania/go-charset/charset/ascii.go
new file mode 100644
index 00000000..ccf3a35b
--- /dev/null
+++ b/vendor/github.com/paulrosania/go-charset/charset/ascii.go
@@ -0,0 +1,65 @@
+package charset
+
+import (
+ "bytes"
+ "fmt"
+ "unicode/utf8"
+)
+
+func init() {
+ registerClass("ascii", fromASCII, toASCII)
+}
+
+const errorByte = '?'
+
+type translateFromASCII bool
+
+type codePointError struct {
+ i int
+ cp rune
+ charset string
+}
+
+func (e *codePointError) Error() string {
+ return fmt.Sprintf("Parse error at index %n: Code point %n is undefined in %s", e.i, e.cp, e.charset)
+}
+
+func (strict translateFromASCII) Translate(data []byte, eof bool) (int, []byte, error) {
+ buf := bytes.NewBuffer(make([]byte, 0, len(data)))
+ for i, c := range data {
+ if c > 0 && c < 128 {
+ buf.WriteByte(c)
+ if c < 32 && c != 10 && c != 13 && c != 9 {
+ // badly formed
+ }
+ } else {
+ if strict {
+ return 0, nil, &codePointError{i, rune(c), "US-ASCII"}
+ }
+ buf.WriteRune(utf8.RuneError)
+ }
+ }
+ return len(data), buf.Bytes(), nil
+}
+
+type translateToASCII bool
+
+func (strict translateToASCII) Translate(data []byte, eof bool) (int, []byte, error) {
+ buf := bytes.NewBuffer(make([]byte, 0, len(data)))
+ for _, c := range data {
+ if c > 0 && c < 128 {
+ buf.WriteByte(c)
+ } else {
+ buf.WriteByte(errorByte)
+ }
+ }
+ return len(data), buf.Bytes(), nil
+}
+
+func fromASCII(arg string) (Translator, error) {
+ return new(translateFromASCII), nil
+}
+
+func toASCII(arg string) (Translator, error) {
+ return new(translateToASCII), nil
+}