// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package japanese

import (
	

	
	
	
	
)

// ShiftJIS is the Shift JIS encoding, also known as Code Page 932 and
// Windows-31J.
var ShiftJIS encoding.Encoding = &shiftJIS

var shiftJIS = internal.Encoding{
	&internal.SimpleEncoding{shiftJISDecoder{}, shiftJISEncoder{}},
	"Shift JIS",
	identifier.ShiftJIS,
}

type shiftJISDecoder struct{ transform.NopResetter }

func (shiftJISDecoder) (,  []byte,  bool) (,  int,  error) {
	,  := rune(0), 0
:
	for ;  < len();  +=  {
		switch  := []; {
		case  < utf8.RuneSelf:
			,  = rune(), 1

		case 0xa1 <=  &&  < 0xe0:
			,  = rune()+(0xff61-0xa1), 1

		case (0x81 <=  &&  < 0xa0) || (0xe0 <=  &&  < 0xfd):
			if  <= 0x9f {
				 -= 0x70
			} else {
				 -= 0xb0
			}
			 = 2* - 0x21

			if +1 >= len() {
				if ! {
					 = transform.ErrShortSrc
					break 
				}
				,  = '\ufffd', 1
				goto 
			}
			 := [+1]
			switch {
			case  < 0x40:
				,  = '\ufffd', 1 // c1 is ASCII so output on next round
				goto 
			case  < 0x7f:
				--
				 -= 0x40
			case  == 0x7f:
				,  = '\ufffd', 1 // c1 is ASCII so output on next round
				goto 
			case  < 0x9f:
				--
				 -= 0x41
			case  < 0xfd:
				 -= 0x9f
			default:
				,  = '\ufffd', 2
				goto 
			}
			,  = '\ufffd', 2
			if  := int()*94 + int();  < len(jis0208Decode) {
				 = rune(jis0208Decode[])
				if  == 0 {
					 = '\ufffd'
				}
			}

		case  == 0x80:
			,  = 0x80, 1

		default:
			,  = '\ufffd', 1
		}
	:
		if +utf8.RuneLen() > len() {
			 = transform.ErrShortDst
			break 
		}
		 += utf8.EncodeRune([:], )
	}
	return , , 
}

type shiftJISEncoder struct{ transform.NopResetter }

func (shiftJISEncoder) (,  []byte,  bool) (,  int,  error) {
	,  := rune(0), 0
:
	for ;  < len();  +=  {
		 = rune([])

		// Decode a 1-byte rune.
		if  < utf8.RuneSelf {
			 = 1

		} else {
			// Decode a multi-byte rune.
			,  = utf8.DecodeRune([:])
			if  == 1 {
				// All valid runes of size 1 (those below utf8.RuneSelf) were
				// handled above. We have invalid UTF-8 or we haven't seen the
				// full character yet.
				if ! && !utf8.FullRune([:]) {
					 = transform.ErrShortSrc
					break 
				}
			}

			// func init checks that the switch covers all tables.
			switch {
			case encode0Low <=  &&  < encode0High:
				if  = rune(encode0[-encode0Low]); >>tableShift == jis0208 {
					goto 
				}
			case encode1Low <=  &&  < encode1High:
				if  = rune(encode1[-encode1Low]); >>tableShift == jis0208 {
					goto 
				}
			case encode2Low <=  &&  < encode2High:
				if  = rune(encode2[-encode2Low]); >>tableShift == jis0208 {
					goto 
				}
			case encode3Low <=  &&  < encode3High:
				if  = rune(encode3[-encode3Low]); >>tableShift == jis0208 {
					goto 
				}
			case encode4Low <=  &&  < encode4High:
				if  = rune(encode4[-encode4Low]); >>tableShift == jis0208 {
					goto 
				}
			case encode5Low <=  &&  < encode5High:
				if 0xff61 <=  &&  < 0xffa0 {
					 -= 0xff61 - 0xa1
					goto 
				}
				if  = rune(encode5[-encode5Low]); >>tableShift == jis0208 {
					goto 
				}
			}
			 = internal.ErrASCIIReplacement
			break
		}

	:
		if  >= len() {
			 = transform.ErrShortDst
			break
		}
		[] = uint8()
		++
		continue

	:
		 := uint8(>>codeShift) & codeMask
		 := uint8() & codeMask
		if +2 > len() {
			 = transform.ErrShortDst
			break 
		}
		if  <= 61 {
			[+0] = 129 + /2
		} else {
			[+0] = 193 + /2
		}
		if &1 == 0 {
			[+1] =  + /63 + 64
		} else {
			[+1] =  + 159
		}
		 += 2
		continue
	}
	return , , 
}