stylesheets/flint/functions/lib/_replace-substring.scss in flint-gs-1.6.5 vs stylesheets/flint/functions/lib/_replace-substring.scss in flint-gs-1.7.0

- old
+ new

@@ -4,25 +4,31 @@ // @param $substring [string] : substring to replace // @param $new-substring [string] : new string to replace sub with // ------------------------------------------------------------------------------- // @return [string] -@function replace-substring($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); +@function flint-replace-substring($string, $substring, $new-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; + // 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; } - - @return $string; }