package lipgloss

import (
	

	
)

// StyleRanges applying styling to ranges in a string. Existing styles will be
// taken into account. Ranges should not overlap.
func ( string,  ...Range) string {
	if len() == 0 {
		return 
	}

	var  strings.Builder
	 := 0
	 := ansi.Strip()

	// Use Truncate and TruncateLeft to style match.MatchedIndexes without
	// losing the original option style:
	for ,  := range  {
		// Add the text before this match
		if .Start >  {
			.WriteString(ansi.Cut(, , .Start))
		}
		// Add the matched range with its highlight
		.WriteString(.Style.Render(ansi.Cut(, .Start, .End)))
		 = .End
	}

	// Add any remaining text after the last match
	.WriteString(ansi.TruncateLeft(, , ""))

	return .String()
}

// NewRange returns a range and style that can be used with [StyleRanges].
func (,  int,  Style) Range {
	return Range{, , }
}

// Range is a range of text and associated styling to be used with
// [StyleRanges].
type Range struct {
	Start, End int
	Style      Style
}