// Copyright 2015 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 width

import (
	

	
)

type foldTransform struct {
	transform.NopResetter
}

func (foldTransform) ( []byte,  bool) ( int,  error) {
	for  < len() {
		if [] < utf8.RuneSelf {
			// ASCII fast path.
			for ++;  < len() && [] < utf8.RuneSelf; ++ {
			}
			continue
		}
		,  := trie.lookup([:])
		if  == 0 { // incomplete UTF-8 encoding
			if ! {
				 = transform.ErrShortSrc
			} else {
				 = len()
			}
			break
		}
		if elem()&tagNeedsFold != 0 {
			 = transform.ErrEndOfSpan
			break
		}
		 += 
	}
	return , 
}

func (foldTransform) (,  []byte,  bool) (,  int,  error) {
	for  < len() {
		if [] < utf8.RuneSelf {
			// ASCII fast path.
			,  := , len()
			if  := len() - ;  < - {
				 =  + 
			}
			for ++;  <  && [] < utf8.RuneSelf; ++ {
			}
			 := copy([:], [:])
			if  += ;  == len() {
				 =  + 
				if  == len() {
					return , , nil
				}
				if [] < utf8.RuneSelf {
					return , , transform.ErrShortDst
				}
			}
			continue
		}
		,  := trie.lookup([:])
		if  == 0 { // incomplete UTF-8 encoding
			if ! {
				return , , transform.ErrShortSrc
			}
			 = 1 // gobble 1 byte
		}
		if elem()&tagNeedsFold == 0 {
			if  != copy([:], [:+]) {
				return , , transform.ErrShortDst
			}
			 += 
		} else {
			 := inverseData[byte()]
			if len()- < int([0]) {
				return , , transform.ErrShortDst
			}
			 := 1
			for  := int([0]);  < ; ++ {
				[] = []
				++
			}
			[] = [] ^ [+-1]
			++
		}
		 += 
	}
	return , , nil
}

type narrowTransform struct {
	transform.NopResetter
}

func (narrowTransform) ( []byte,  bool) ( int,  error) {
	for  < len() {
		if [] < utf8.RuneSelf {
			// ASCII fast path.
			for ++;  < len() && [] < utf8.RuneSelf; ++ {
			}
			continue
		}
		,  := trie.lookup([:])
		if  == 0 { // incomplete UTF-8 encoding
			if ! {
				 = transform.ErrShortSrc
			} else {
				 = len()
			}
			break
		}
		if  := elem().kind(); byte() == 0 ||  != EastAsianFullwidth &&  != EastAsianWide &&  != EastAsianAmbiguous {
		} else {
			 = transform.ErrEndOfSpan
			break
		}
		 += 
	}
	return , 
}

func (narrowTransform) (,  []byte,  bool) (,  int,  error) {
	for  < len() {
		if [] < utf8.RuneSelf {
			// ASCII fast path.
			,  := , len()
			if  := len() - ;  < - {
				 =  + 
			}
			for ++;  <  && [] < utf8.RuneSelf; ++ {
			}
			 := copy([:], [:])
			if  += ;  == len() {
				 =  + 
				if  == len() {
					return , , nil
				}
				if [] < utf8.RuneSelf {
					return , , transform.ErrShortDst
				}
			}
			continue
		}
		,  := trie.lookup([:])
		if  == 0 { // incomplete UTF-8 encoding
			if ! {
				return , , transform.ErrShortSrc
			}
			 = 1 // gobble 1 byte
		}
		if  := elem().kind(); byte() == 0 ||  != EastAsianFullwidth &&  != EastAsianWide &&  != EastAsianAmbiguous {
			if  != copy([:], [:+]) {
				return , , transform.ErrShortDst
			}
			 += 
		} else {
			 := inverseData[byte()]
			if len()- < int([0]) {
				return , , transform.ErrShortDst
			}
			 := 1
			for  := int([0]);  < ; ++ {
				[] = []
				++
			}
			[] = [] ^ [+-1]
			++
		}
		 += 
	}
	return , , nil
}

type wideTransform struct {
	transform.NopResetter
}

func (wideTransform) ( []byte,  bool) ( int,  error) {
	for  < len() {
		// TODO: Consider ASCII fast path. Special-casing ASCII handling can
		// reduce the ns/op of BenchmarkWideASCII by about 30%. This is probably
		// not enough to warrant the extra code and complexity.
		,  := trie.lookup([:])
		if  == 0 { // incomplete UTF-8 encoding
			if ! {
				 = transform.ErrShortSrc
			} else {
				 = len()
			}
			break
		}
		if  := elem().kind(); byte() == 0 ||  != EastAsianHalfwidth &&  != EastAsianNarrow {
		} else {
			 = transform.ErrEndOfSpan
			break
		}
		 += 
	}
	return , 
}

func (wideTransform) (,  []byte,  bool) (,  int,  error) {
	for  < len() {
		// TODO: Consider ASCII fast path. Special-casing ASCII handling can
		// reduce the ns/op of BenchmarkWideASCII by about 30%. This is probably
		// not enough to warrant the extra code and complexity.
		,  := trie.lookup([:])
		if  == 0 { // incomplete UTF-8 encoding
			if ! {
				return , , transform.ErrShortSrc
			}
			 = 1 // gobble 1 byte
		}
		if  := elem().kind(); byte() == 0 ||  != EastAsianHalfwidth &&  != EastAsianNarrow {
			if  != copy([:], [:+]) {
				return , , transform.ErrShortDst
			}
			 += 
		} else {
			 := inverseData[byte()]
			if len()- < int([0]) {
				return , , transform.ErrShortDst
			}
			 := 1
			for  := int([0]);  < ; ++ {
				[] = []
				++
			}
			[] = [] ^ [+-1]
			++
		}
		 += 
	}
	return , , nil
}