package ansi

import (
	
	

	
)

// Strip removes ANSI escape codes from a string.
func ( string) string {
	var (
		    bytes.Buffer         // buffer for collecting printable characters
		     int                  // rune index
		     int                  // rune width
		 = parser.GroundState // initial state
	)

	// This implements a subset of the Parser to only collect runes and
	// printable characters.
	for  := range len() {
		if  == parser.Utf8State {
			// During this state, collect rw bytes to form a valid rune in the
			// buffer. After getting all the rune bytes into the buffer,
			// transition to GroundState and reset the counters.
			.WriteByte([])
			++
			if  <  {
				continue
			}
			 = parser.GroundState
			 = 0
			 = 0
			continue
		}

		,  := parser.Table.Transition(, [])
		switch  {
		case parser.CollectAction:
			if  == parser.Utf8State {
				// This action happens when we transition to the Utf8State.
				 = utf8ByteLen([])
				.WriteByte([])
				++
			}
		case parser.PrintAction, parser.ExecuteAction:
			// collects printable ASCII and non-printable characters
			.WriteByte([])
		}

		// Transition to the next state.
		// The Utf8State is managed separately above.
		if  != parser.Utf8State {
			 = 
		}
	}

	return .String()
}

// StringWidth returns the width of a string in cells. This is the number of
// cells that the string will occupy when printed in a terminal. ANSI escape
// codes are ignored and wide characters (such as East Asians and emojis) are
// accounted for.
// This treats the text as a sequence of grapheme clusters.
func ( string) int {
	return stringWidth(GraphemeWidth, )
}

// StringWidthWc returns the width of a string in cells. This is the number of
// cells that the string will occupy when printed in a terminal. ANSI escape
// codes are ignored and wide characters (such as East Asians and emojis) are
// accounted for.
// This treats the text as a sequence of wide characters and runes.
func ( string) int {
	return stringWidth(WcWidth, )
}

func ( Method,  string) int {
	if  == "" {
		return 0
	}

	var (
		 = parser.GroundState // initial state
		  int
	)

	for  := 0;  < len(); ++ {
		,  := parser.Table.Transition(, [])
		if  == parser.PrintAction ||  == parser.Utf8State {
			if  == WcWidth {
				// Wcwidth sums codepoints, so where the cluster boundaries
				// fall makes no difference to the total. Skipping the
				// segmentation is a good deal cheaper.
				,  := utf8.DecodeRuneInString([:])
				 += wcRuneWidth()
				 +=  - 1
				 = parser.GroundState
				continue
			}

			,  := FirstGraphemeCluster([:], )
			 += 

			 += len() - 1
			 = parser.GroundState
			continue
		}

		if  == parser.PrintAction {
			++
		}

		 = 
	}

	return 
}