diff options
Diffstat (limited to 'Godeps/_workspace/src/golang.org/x/text/encoding/japanese/iso2022jp.go')
-rw-r--r-- | Godeps/_workspace/src/golang.org/x/text/encoding/japanese/iso2022jp.go | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/Godeps/_workspace/src/golang.org/x/text/encoding/japanese/iso2022jp.go b/Godeps/_workspace/src/golang.org/x/text/encoding/japanese/iso2022jp.go index eb2bc1946..b63e7d5d8 100644 --- a/Godeps/_workspace/src/golang.org/x/text/encoding/japanese/iso2022jp.go +++ b/Godeps/_workspace/src/golang.org/x/text/encoding/japanese/iso2022jp.go @@ -154,9 +154,6 @@ func (e *iso2022JPEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc in // Decode a 1-byte rune. if r < utf8.RuneSelf { size = 1 - if r == asciiEsc { - r = encoding.ASCIISub - } } else { // Decode a multi-byte rune. @@ -209,7 +206,22 @@ func (e *iso2022JPEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc in goto writeJIS } } - r = encoding.ASCIISub + + // Switch back to ASCII state in case of error so that an ASCII + // replacement character can be written in the correct state. + if *e != asciiState { + if nDst+3 > len(dst) { + err = transform.ErrShortDst + break + } + *e = asciiState + dst[nDst+0] = asciiEsc + dst[nDst+1] = '(' + dst[nDst+2] = 'B' + nDst += 3 + } + err = internal.ErrASCIIReplacement + break } if *e != asciiState { @@ -269,5 +281,16 @@ func (e *iso2022JPEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc in nDst++ continue } + if atEOF && err == nil && *e != asciiState { + if nDst+3 > len(dst) { + err = transform.ErrShortDst + } else { + *e = asciiState + dst[nDst+0] = asciiEsc + dst[nDst+1] = '(' + dst[nDst+2] = 'B' + nDst += 3 + } + } return nDst, nSrc, err } |