diff options
author | Wim <wim@42.be> | 2018-05-11 21:54:32 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2018-05-11 21:54:32 +0200 |
commit | bf0b9959d1b81d6362a390baaee70f2102fb2d58 (patch) | |
tree | 61f2e71367884883cb9f68d7ac55cdcbb5dce908 /vendor/golang.org/x/text/encoding/simplifiedchinese/gbk.go | |
parent | 406a54b597271add1e297231e6f260895eff8f1d (diff) | |
download | matterbridge-msglm-bf0b9959d1b81d6362a390baaee70f2102fb2d58.tar.gz matterbridge-msglm-bf0b9959d1b81d6362a390baaee70f2102fb2d58.tar.bz2 matterbridge-msglm-bf0b9959d1b81d6362a390baaee70f2102fb2d58.zip |
Add vendor github.com/dfordsoft/golib/ic
Diffstat (limited to 'vendor/golang.org/x/text/encoding/simplifiedchinese/gbk.go')
-rw-r--r-- | vendor/golang.org/x/text/encoding/simplifiedchinese/gbk.go | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/vendor/golang.org/x/text/encoding/simplifiedchinese/gbk.go b/vendor/golang.org/x/text/encoding/simplifiedchinese/gbk.go index e0b15bbc..b89c45b0 100644 --- a/vendor/golang.org/x/text/encoding/simplifiedchinese/gbk.go +++ b/vendor/golang.org/x/text/encoding/simplifiedchinese/gbk.go @@ -5,7 +5,6 @@ package simplifiedchinese import ( - "errors" "unicode/utf8" "golang.org/x/text/encoding" @@ -40,11 +39,6 @@ var gbk18030 = internal.Encoding{ identifier.GB18030, } -var ( - errInvalidGB18030 = errors.New("simplifiedchinese: invalid GB18030 encoding") - errInvalidGBK = errors.New("simplifiedchinese: invalid GBK encoding") -) - type gbkDecoder struct { transform.NopResetter gb18030 bool @@ -66,8 +60,12 @@ loop: case c0 < 0xff: if nSrc+1 >= len(src) { - err = transform.ErrShortSrc - break loop + if !atEOF { + err = transform.ErrShortSrc + break loop + } + r, size = utf8.RuneError, 1 + goto write } c1 := src[nSrc+1] switch { @@ -77,18 +75,24 @@ loop: c1 -= 0x41 case d.gb18030 && 0x30 <= c1 && c1 < 0x40: if nSrc+3 >= len(src) { - err = transform.ErrShortSrc - break loop + if !atEOF { + err = transform.ErrShortSrc + break loop + } + // The second byte here is always ASCII, so we can set size + // to 1 in all cases. + r, size = utf8.RuneError, 1 + goto write } c2 := src[nSrc+2] if c2 < 0x81 || 0xff <= c2 { - err = errInvalidGB18030 - break loop + r, size = utf8.RuneError, 1 + goto write } c3 := src[nSrc+3] if c3 < 0x30 || 0x3a <= c3 { - err = errInvalidGB18030 - break loop + r, size = utf8.RuneError, 1 + goto write } size = 4 r = ((rune(c0-0x81)*10+rune(c1-0x30))*126+rune(c2-0x81))*10 + rune(c3-0x30) @@ -109,17 +113,13 @@ loop: r -= 189000 if 0 <= r && r < 0x100000 { r += 0x10000 - goto write - } - err = errInvalidGB18030 - break loop - default: - if d.gb18030 { - err = errInvalidGB18030 } else { - err = errInvalidGBK + r, size = utf8.RuneError, 1 } - break loop + goto write + default: + r, size = utf8.RuneError, 1 + goto write } r, size = '\ufffd', 2 if i := int(c0-0x81)*190 + int(c1); i < len(decode) { @@ -130,12 +130,7 @@ loop: } default: - if d.gb18030 { - err = errInvalidGB18030 - } else { - err = errInvalidGBK - } - break loop + r, size = utf8.RuneError, 1 } write: @@ -145,13 +140,6 @@ loop: } nDst += utf8.EncodeRune(dst[nDst:], r) } - if atEOF && err == transform.ErrShortSrc { - if d.gb18030 { - err = errInvalidGB18030 - } else { - err = errInvalidGBK - } - } return nDst, nSrc, err } |