// 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 traditionalchinese

import (
	

	
	
	
	
)

// All is a list of all defined encodings in this package.
var All = []encoding.Encoding{Big5}

// Big5 is the Big5 encoding, also known as Code Page 950.
var Big5 encoding.Encoding = &big5

var big5 = internal.Encoding{
	&internal.SimpleEncoding{big5Decoder{}, big5Encoder{}},
	"Big5",
	identifier.Big5,
}

type big5Decoder struct{ transform.NopResetter }

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

		case 0x81 <=  &&  < 0xff:
			if +1 >= len() {
				if ! {
					 = transform.ErrShortSrc
					break 
				}
				,  = utf8.RuneError, 1
				goto 
			}
			 := [+1]
			switch {
			case 0x40 <=  &&  < 0x7f:
				 -= 0x40
			case 0xa1 <=  &&  < 0xff:
				 -= 0x62
			case  < 0x40:
				,  = utf8.RuneError, 1
				goto 
			default:
				,  = utf8.RuneError, 2
				goto 
			}
			,  = '\ufffd', 2
			if  := int(-0x81)*157 + int();  < len(decode) {
				if 1133 <=  &&  < 1167 {
					// The two-rune special cases for LATIN CAPITAL / SMALL E WITH CIRCUMFLEX
					// AND MACRON / CARON are from http://encoding.spec.whatwg.org/#big5
					switch  {
					case 1133:
						 = "\u00CA\u0304"
						goto 
					case 1135:
						 = "\u00CA\u030C"
						goto 
					case 1164:
						 = "\u00EA\u0304"
						goto 
					case 1166:
						 = "\u00EA\u030C"
						goto 
					}
				}
				 = rune(decode[])
				if  == 0 {
					 = '\ufffd'
				}
			}

		default:
			,  = utf8.RuneError, 1
		}

	:
		if +utf8.RuneLen() > len() {
			 = transform.ErrShortDst
			break 
		}
		 += utf8.EncodeRune([:], )
		continue 

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

type big5Encoder struct{ transform.NopResetter }

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

		// Decode a 1-byte rune.
		if  < utf8.RuneSelf {
			 = 1
			if  >= len() {
				 = transform.ErrShortDst
				break
			}
			[] = uint8()
			++
			continue

		} 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
				}
			}
		}

		if  >= utf8.RuneSelf {
			// func init checks that the switch covers all tables.
			switch {
			case encode0Low <=  &&  < encode0High:
				if  = rune(encode0[-encode0Low]);  != 0 {
					goto 
				}
			case encode1Low <=  &&  < encode1High:
				if  = rune(encode1[-encode1Low]);  != 0 {
					goto 
				}
			case encode2Low <=  &&  < encode2High:
				if  = rune(encode2[-encode2Low]);  != 0 {
					goto 
				}
			case encode3Low <=  &&  < encode3High:
				if  = rune(encode3[-encode3Low]);  != 0 {
					goto 
				}
			case encode4Low <=  &&  < encode4High:
				if  = rune(encode4[-encode4Low]);  != 0 {
					goto 
				}
			case encode5Low <=  &&  < encode5High:
				if  = rune(encode5[-encode5Low]);  != 0 {
					goto 
				}
			case encode6Low <=  &&  < encode6High:
				if  = rune(encode6[-encode6Low]);  != 0 {
					goto 
				}
			case encode7Low <=  &&  < encode7High:
				if  = rune(encode7[-encode7Low]);  != 0 {
					goto 
				}
			}
			 = internal.ErrASCIIReplacement
			break
		}

	:
		if +2 > len() {
			 = transform.ErrShortDst
			break
		}
		[+0] = uint8( >> 8)
		[+1] = uint8()
		 += 2
		continue
	}
	return , , 
}

func init() {
	// Check that the hard-coded encode switch covers all tables.
	if numEncodeTables != 8 {
		panic("bad numEncodeTables")
	}
}