|
44 | 44 | @return $string; |
45 | 45 | } |
46 | 46 |
|
| 47 | +// Remove empty spaces from ends of string |
| 48 | +// |
| 49 | +// @author Hugo Giraudel (Original), Aaron M Jones (modified to work with quoted strings) |
| 50 | +// |
| 51 | +// @param {String} $string - The string to trim previously quoted strings. |
| 52 | +@function str-trim($string) { |
| 53 | + $unquote: unquote(quote($string)); |
| 54 | + $start: 1; |
| 55 | + $end: str-length($unquote); |
| 56 | + |
| 57 | + @for $i from 1 through str-length($unquote) { |
| 58 | + $first: str-slice($unquote, $i, $i); |
| 59 | + $last: str-slice($unquote, -$i, -$i); |
| 60 | + |
| 61 | + @if $first == " " and $i + 1 == $start + 1 { |
| 62 | + $start: $i + 1; |
| 63 | + } |
| 64 | + |
| 65 | + @if $last == " " and str-length($unquote) - $i == $end - 1 { |
| 66 | + $end: str-length($unquote) - $i; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + $trimmed: str-slice($unquote, $start, $end); |
| 71 | + |
| 72 | + @return if(($unquote != $string), quote($trimmed), $trimmed); |
| 73 | +} |
| 74 | + |
| 75 | +// Surround String with Parenthesis. If doNotQuote property is true, quoted strings are unquoted. |
| 76 | +// |
| 77 | +// @param {String} $string - The string to enclose in parenthesis. |
| 78 | +// @param {Boolean} $doNotQuote - TRUE: Leave the string unquoted, FALSE: Return quotes to previously quoted strings. |
| 79 | +@function parenthesis($string,$doNotQuote: false) { |
| 80 | + $unquote: str-trim(unquote(quote($string))); |
| 81 | + $left: unquote("("); |
| 82 | + $right: unquote(")"); |
| 83 | + $tItem: if(str-slice($unquote,1,1) == $left,$unquote,#{$left}#{$unquote}); |
| 84 | + $tItem: if(str-slice($tItem,-1,-1) == $right,$tItem,#{$tItem}#{$right}); |
| 85 | + |
| 86 | + @return if(($unquote != $string and $doNotQuote != true), quote($tItem), $tItem); |
| 87 | +} |
| 88 | + |
47 | 89 | // Explodes a string into a SASS list by the given delimiter |
48 | 90 | // @author Hugo Giraudel (modified from original) |
49 | 91 | @function _str-explode($string, $delimiter: "") { |
|
0 commit comments