///
/// Replace substring
///
/// @access private
///
/// @param {String} $string              - string that contains substring
/// @param {String} $substring           - substring to replace
/// @param {String} $new-substring [" "] - new string to replace sub with
///
/// @return {String}
///
/// @group Internal Functions
///
@function flint-str-replace($string, $substring, $new-substring: " ") {

	// Use Ruby function if available
	@if $flint-use-ruby-functions {
		@return flint_ruby_str_replace($string, $substring, $new-substring);
	}
	
	// Loop through length of string
	@for $i from 1 through str-length($string) {
		// Get index and length of substring
		$sub-index: str-index($string, $substring);
		$sub-length: str-length($substring);

		// If count is index of substring
		@if $i == $sub-index {
			// Slice string to exclude substring
			$string-before: str-slice($string, 1, $i - 1);
			$string-after: str-slice($string, $i + $sub-length, str-length($string));
			// Create new string
			$string: $string-before + $new-substring + $string-after;
		}

	}

	@return $string;
}
