Sha256: 24a01affcb2f136261b8c5a4f806bf124b2009cf31f2c25c58b07600beedd885

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

/**
 * 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}
 */
@function flint-replace-substring($string, $substring, $new-substring: " ") {

	// Use Ruby function if available
	@if $flint__use-ruby-functions {
		@return flint_ruby_replace_substring($string, $substring, $new-substring);
	} @else {
		// 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;
	}
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flint-gs-2.0.2 stylesheets/flint/functions/lib/_replace-substring.scss