Sha256: 7cf950c722f3580ca515145acd482a48771f4459aa451d36aa9210b7f12738f7

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

// Replace substring
// -------------------------------------------------------------------------------
// @param $string [string] : string that contains substring
// @param $substring [string] : substring to replace
// @param $new-substring [string] : 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 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

7 entries across 7 versions & 1 rubygems

Version Path
flint-gs-1.12.0 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-1.11.2 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-1.10.0 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-1.9.1 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-1.8.0 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-1.7.2 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-1.7.0 stylesheets/flint/functions/lib/_replace-substring.scss