summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/bourbon/app/assets/stylesheets/helpers/_str-to-num.scss
blob: 1e039f25d7299d09f482c64b18acd9a7f4c140f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//************************************************************************//
// Helper function for linear/radial-gradient-parsers.
// Source: http://sassmeister.com/gist/9647408
//************************************************************************//
@function _str-to-num($string) {
  @if $output-bourbon-deprecation-warnings == true {
    @warn "[Bourbon] [Deprecation] `_str-to-num` is " +
    "deprecated and will be removed in 5.0.0.";
  }

  // Matrices
  $strings: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9";
  $numbers:  0   1   2   3   4   5   6   7   8   9;

  // Result
  $result: 0;
  $divider: 0;
  $minus: false;

  // Looping through all characters
  @for $i from 1 through str-length($string) {
    $character: str-slice($string, $i, $i);
    $index: index($strings, $character);

    @if $character == "-" {
      $minus: true;
    }

    @else if $character == "." {
      $divider: 1;
    }

    @else {
      @if not $index {
        $result: if($minus, $result * -1, $result);
        @return _convert-units($result, str-slice($string, $i));
      }

      $number: nth($numbers, $index);

      @if $divider == 0 {
        $result: $result * 10;
      }

      @else {
        // Move the decimal dot to the left
        $divider: $divider * 10;
        $number: $number / $divider;
      }

      $result: $result + $number;
    }
  }
  @return if($minus, $result * -1, $result);
}