package helpers

import (
	
	
	
	
	

	
)

func ( []rune,  []rune) int {
	// special case
	if len() == 0 {
		return -1
	}
	// naive version
	for ,  := range  {
		if slices.Contains(, ) {
			return 
		}
	}
	return -1
}

func ( []rune,  rune) int {
	//TODO: bytes optimization?
	return slices.Index(, )
}

func ( []rune, ,  rune) int {
	for ,  := range  {
		if  ==  ||  ==  {
			return 
		}
	}

	return -1
}

func ( []rune, , ,  rune) int {
	for ,  := range  {
		if  ==  ||  ==  ||  ==  {
			return 
		}
	}

	return -1
}

func ( []rune, ,  rune) int {
	for ,  := range  {
		if  >=  &&  <=  {
			return 
		}
	}
	return -1
}

func ( []rune,  []rune) int {
	for ,  := range  {
		 := false
		for ,  := range  {
			if  ==  {
				 = true
				break
			}
		}
		if ! {
			return 
		}
	}
	return -1
}

func ( []rune,  rune) int {
	for ,  := range  {
		if  !=  {
			return 
		}
	}
	return -1
}

func ( []rune, ,  rune) int {
	for ,  := range  {
		if  !=  &&  !=  {
			return 
		}
	}

	return -1
}

func ( []rune, , ,  rune) int {
	for ,  := range  {
		if  !=  &&  !=  &&  !=  {
			return 
		}
	}

	return -1
}

func ( []rune, ,  rune) int {
	for ,  := range  {
		if  >  {
			return 
		}
		if  <  {
			return 
		}
	}
	return -1
}

func ( []rune,  func( rune) bool) int {
	for  := range  {
		if ([]) {
			return 
		}
	}
	return -1
}

func ( []rune,  syntax.CharSet) int {
	//TODO: this
	panic("not implemented")
}

func ( []rune,  []rune) int {
	 := len() - len()
	 := [0]
	 := len() - 1
	 := []
	for  := ;  >= 0; -- {
		//TODO: check 2 chars needed?
		// match start and end...check the middle
		if [] ==  && [+] ==  {
			// found our first char
			// check if the rest are equal
			if bytesEqual([:+len()], ) {
				return 
			}
		}
	}

	//not found
	return -1
}

func ( []rune,  rune) int {
	for  := len() - 1;  >= 0; -- {
		if [] !=  {
			return 
		}
	}
	return -1
}

func ( []rune,  rune) int {
	for  := len() - 1;  >= 0; -- {
		if [] ==  {
			// found our char
			return 
		}
	}

	//not found
	return -1
}

func ( []rune, ,  rune) int {
	for  := len() - 1;  >= 0; -- {
		if [] >=  && [] <=  {
			return 
		}
	}
	return -1
}

//TODO: LastIndexOf methods
//IndexOfAnyInRange
//LastIndexOfAnyInRange
//LastIndexOfAnyExceptInRange

// find should always be sent in lower-case
func ( []rune,  []rune) int {
	// search the in slice for the "find" slice, ignoring case in the comparisons
	 := len() - len()
	 := [0]
	for  := 0;  <= ; ++ {
		if [] !=  && unicode.ToLower([]) !=  {
			continue
		}
		 := true
		for  := 1;  < len(); ++ {
			 := [+]
			if  != [] && unicode.ToLower() != [] {
				 = false
				break
			}
		}
		if  {
			return 
		}
	}
	return -1
}

func ( []rune,  []rune) int {
	// search the in slice for the "find" slice, ignoring case in the comparisons
	// we can assume the find chars are ascii and do simple masks on them
	if len() == 0 {
		return 0
	}
	 := len() - len()
	 := foldASCII(rune([0]))
	for  := 0;  <= ; ++ {
		if foldASCII([]) !=  {
			continue
		}
		 := true
		for  := 1;  < len(); ++ {
			if foldASCII([+]) != foldASCII([]) {
				 = false
				break
			}
		}
		if  {
			return 
		}
	}
	return -1
}

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

	for ,  := 0, len()-len();  <= ; {
		 := indexASCIIByteIgnoreCase([:], [0])
		if  < 0 || + >  {
			return -1
		}

		 :=  + 
		if EqualStringIgnoreCaseASCII([:+len()], ) {
			return 
		}
		 =  + 1
	}
	return -1
}

func (,  string) bool {
	if len() < len() {
		return false
	}
	for  := 0;  < len(); ++ {
		if foldASCII(rune([])) != foldASCII(rune([])) {
			return false
		}
	}
	return true
}

func indexASCIIByteIgnoreCase( string,  byte) int {
	 = byte(foldASCII(rune()))
	 := strings.IndexByte(, )
	if  < 'a' ||  > 'z' {
		return 
	}
	 := strings.IndexByte(, -('a'-'A'))
	if  < 0 {
		return 
	}
	if  >= 0 &&  <  {
		return 
	}
	return 
}

func foldASCII( rune) rune {
	if 'A' <=  &&  <= 'Z' {
		return  + ('a' - 'A')
	}
	return 
}

func ( []rune,  []rune) int {
	/*
		Since we auto-gen the find code this shouldn't happen
		if len(find) == 0 {
			//special case
			return -1
		}*/
	 := len() - len()
	 := [0]
	//TODO: benchmark checking last char too or first two chars
	for  := 0;  <= ; ++ {
		// match start...check the rest
		if [] ==  {
			// found our first char
			// check if the rest are equal
			if bytesEqual([:+len()], ) {
				return 
			}
			/*if slices.Equal(in[i:i+len(find)], find) {
				return i
			}*/
		}
	}

	//not found
	return -1
}

func ( []rune,  []rune) bool {
	// if text is less than our "begin" then can't find it
	if len() < len() {
		return false
	}

	return bytesEqual([:len()], )

	/*for i := 0; i < len(find); i++ {
		if in[i] != find[i] {
			return false
		}
	}

	return true*/
}

//StartsWithIgnoreCaseAscii would be faster

// find should always be sent in lower-case
func ( []rune,  []rune) bool {
	// if text is less than our "begin" then can't find it
	if len() < len() {
		return false
	}

	for  := 0;  < len(); ++ {
		if [] == [] {
			// if we match the char exactly then we're good
			continue
		}
		// if the to-lower still doesn't match then it's not a match
		if unicode.ToLower([]) != [] {
			return false
		}
	}

	return true
}

// internal function, assumes the bounds are already set right on the slices for equality
// casts the rune slices to bytes to use framework fast []byte comparison
func bytesEqual(,  []rune) bool {
	 := unsafe.Slice((*byte)(unsafe.Pointer(&[0])), len()*4)
	 := unsafe.Slice((*byte)(unsafe.Pointer(&[0])), len()*4)
	return bytes.Equal(, )
}

func ( []rune,  int,  int,  []rune) bool {
	if len() == 0 {
		return true
	}
	return bytesEqual([:+], )
}

func ( []rune,  int,  int,  []rune) bool {
	//fast path if case matches
	if Equals(, , , ) {
		return true
	}

	// search the in slice for the "find" slice, ignoring case in the comparisons
	// we can't assume casing or ascii-ness for either letter, have to toLower them both
	for  := 0;  < len(); ++ {
		 := [+]
		 := []
		if  !=  && unicode.ToLower() != unicode.ToLower() {
			return false
		}
	}

	// we've checked all chars and found matches every time
	return true
}