<commit_before>include base.comparator.BaseComparator

include math.util.MathUtil

include string.validator.StringValidator

@class
StringUtil(){
	append(){
		echo ${1}${2}
	}

	capitalize(){
		local str=${@}

		echo ${str^}
	}

	escape(){
		local level=$(MathUtil decrement ${2})
		local str=${1}

		if [[ ! $(BaseComparator isLessThan ${level} 0) ]]; then
			for (( i=0; i<$(MathUtil exp 2 ${level}); i++ )); do
				local str=$(append \\ ${str})
			done
		fi

		echo ${str}
	}

	join(){
		local __array=${1}
		local _array=${__array}[@]
		local array=(${!_array})

		local separator=${2}

		for _string in ${array[@]}; do
			if [[ ${str} ]]; then
				local str=$(append $(append ${str} ${separator}) ${_string})
			else
				local str=${_string}
			fi
		done

		echo ${str}
	}

	length(){
		local str=${@}

		echo ${#str}
	}

	parseMessage(){
		replace ${1} _ space
	}

	replace(){
		local input=$(readvar ${1})
		local new=${3}
		local old=${2}

		if [[ $(BaseComparator isEqual ${new} space) ]]; then
			local new="\ "
		elif [[ $(BaseComparator isEqual ${new} null) ]]; then
			local new=""
		fi

		if [[ $(BaseComparator isEqual ${old} space) ]]; then
			local old=" "
		fi

		echo ${input} | sed "s;${old};${new};g"
	}

	returnOption(){
		if [[ $(StringValidator isOption ${1}) ]]; then
			local option=${1}

			strip option -
		fi
	}

	split(){
		replace ${@} space
	}

	strip(){
		replace ${@} null
	}

	toArray(){
		local array=()<commit_msg>Add method to extract substring by length parameter<commit_after>include base.comparator.BaseComparator

include math.util.MathUtil

include string.validator.StringValidator

@class
StringUtil(){
	append(){
		echo ${1}${2}
	}

	capitalize(){
		local str=${@}

		echo ${str^}
	}

	escape(){
		local level=$(MathUtil decrement ${2})
		local str=${1}

		if [[ ! $(BaseComparator isLessThan ${level} 0) ]]; then
			for (( i=0; i<$(MathUtil exp 2 ${level}); i++ )); do
				local str=$(append \\ ${str})
			done
		fi

		echo ${str}
	}

	join(){
		local __array=${1}
		local _array=${__array}[@]
		local array=(${!_array})

		local separator=${2}

		for _string in ${array[@]}; do
			if [[ ${str} ]]; then
				local str=$(append $(append ${str} ${separator}) ${_string})
			else
				local str=${_string}
			fi
		done

		echo ${str}
	}

	length(){
		local str=${@}

		echo ${#str}
	}

	parseMessage(){
		replace ${1} _ space
	}

	replace(){
		local input=$(readvar ${1})
		local new=${3}
		local old=${2}

		if [[ $(BaseComparator isEqual ${new} space) ]]; then
			local new="\ "
		elif [[ $(BaseComparator isEqual ${new} null) ]]; then
			local new=""
		fi

		if [[ $(BaseComparator isEqual ${old} space) ]]; then
			local old=" "
		fi

		echo ${input} | sed "s;${old};${new};g"
	}

	returnOption(){
		if [[ $(StringValidator isOption ${1}) ]]; then
			local option=${1}

			strip option -
		fi
	}

	split(){
		replace ${@} space
	}

	strip(){
		replace ${@} null
	}

	substring(){
		if [[ $(BaseComparator isEqual $# 3) ]]; then
			local init=${2}
			local length=${3}
			local string=$(readvar ${1})
		elif [[ $(BaseComparator isEqual $# 2) ]]; then
			local init=0
			local length=${2}
			local string=$(readvar ${1})
		fi

		echo ${string:${init}:${length}}
	}

	toArray(){
		local array=()
{'fraction_non_alphanumeric': 0.20135886349598517, 'fraction_numerical': 0.01173563928350834, 'mean_word_length': 3.3711201079622133, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1043507', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1153, 'n_words': 316}