Debian Codegraph @

debian/missing-sources/bourbon/app/assets/stylesheets/helpers/_str-to-num.scss

raw
1 //************************************************************************//
2 // Helper function for linear/radial-gradient-parsers.
3 // Source: http://sassmeister.com/gist/9647408
4 //************************************************************************//
5 @function _str-to-num($string) {
6 @if $output-bourbon-deprecation-warnings == true {
7 @warn "[Bourbon] [Deprecation] `_str-to-num` is " +
8 "deprecated and will be removed in 5.0.0.";
9 }
10
11 // Matrices
12 $strings: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9";
13 $numbers: 0 1 2 3 4 5 6 7 8 9;
14
15 // Result
16 $result: 0;
17 $divider: 0;
18 $minus: false;
19
20 // Looping through all characters
21 @for $i from 1 through str-length($string) {
22 $character: str-slice($string, $i, $i);
23 $index: index($strings, $character);
24
25 @if $character == "-" {
26 $minus: true;
27 }
28
29 @else if $character == "." {
30 $divider: 1;
31 }
32
33 @else {
34 @if not $index {
35 $result: if($minus, $result * -1, $result);
36 @return _convert-units($result, str-slice($string, $i));
37 }
38
39 $number: nth($numbers, $index);
40
41 @if $divider == 0 {
42 $result: $result * 10;
43 }
44
45 @else {
46 // Move the decimal dot to the left
47 $divider: $divider * 10;
48 $number: $number / $divider;
49 }
50
51 $result: $result + $number;
52 }
53 }
54 @return if($minus, $result * -1, $result);
55 }