Sha256: 5e6c428358d980ff6cab7b77b5569cfe9abebb68df0cdf75633bd56d7805a0a6

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 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}
 *
 * @group Internal Functions
 */
@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

4 entries across 4 versions & 1 rubygems

Version Path
flint-gs-2.0.6 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-2.0.5 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-2.0.4 stylesheets/flint/functions/lib/_replace-substring.scss
flint-gs-2.0.3 stylesheets/flint/functions/lib/_replace-substring.scss