aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/small_SUITE_data/src/left_assoc.erl
blob: 0250e4ab4937b932e8fcb7391c4f402e9b9977f0 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
-module(left_assoc).

%% As pointed out in ERL-680, analyzing guards with short circuit
%% operators becomes very slow as the number of left associations
%% grows.

-spec from_iso8601('Elixir.String':t(), 'Elixir.Calendar':calendar()) ->
                          {ok, t()} | {error, atom()}.

-export_type([t/0]).

-type t() ::
        #{'__struct__' := 'Elixir.Date',
          calendar := 'Elixir.Calendar':calendar(),
          day := 'Elixir.Calendar':day(),
          month := 'Elixir.Calendar':month(),
          year := 'Elixir.Calendar':year()}.

-export([from_iso8601/1,
         from_iso8601/2]).

from_iso8601(__@1) ->
    from_iso8601(__@1, 'Elixir.Calendar.ISO').

from_iso8601(<<45/integer,_rest@1/binary>>, _calendar@1) ->
    case raw_from_iso8601(_rest@1, _calendar@1) of
        {ok,#{year := _year@1} = _date@1} ->
            {ok,_date@1#{year := - _year@1}};
        __@1 ->
            __@1
    end;
from_iso8601(<<_rest@1/binary>>, _calendar@1) ->
    raw_from_iso8601(_rest@1, _calendar@1).

raw_from_iso8601(_string@1, _calendar@1) ->
    case _string@1 of
        <<_y1@1/integer,
          _y2@1/integer,
          _y3@1/integer,
          _y4@1/integer,
          45/integer,
          _m1@1/integer,
          _m2@1/integer,
          45/integer,
          _d1@1/integer,
          _d2@1/integer>>
          when
              ((((((((((((((_y1@1 >= 48
                            andalso
                            _y1@1 =< 57)
                           andalso
                           _y2@1 >= 48)
                          andalso
                          _y2@1 =< 57)
                         andalso
                         _y3@1 >= 48)
                        andalso
                        _y3@1 =< 57)
                       andalso
                       _y4@1 >= 48)
                      andalso
                      _y4@1 =< 57)
                     andalso
                     _m1@1 >= 48)
                    andalso
                    _m1@1 =< 57)
                   andalso
                   _m2@1 >= 48)
                  andalso
                  _m2@1 =< 57)
                 andalso
                 _d1@1 >= 48)
                andalso
                _d1@1 =< 57)
               andalso
               _d2@1 >= 48)
              andalso
              _d2@1 =< 57 ->
            {ok,
             #{year => (_y1@1 - 48) * 1000 + (_y2@1 - 48) * 100
               +
                   (_y3@1 - 48) * 10
               +
                   (_y4@1 - 48),
               month => (_m1@1 - 48) * 10 + (_m2@1 - 48),
               day => (_d1@1 - 48) * 10 + (_d2@1 - 48),
               calendar => _calendar@1,
               '__struct__' => 'Elixir.Date'}};
        __@1 ->
            case __@1 of
                _ ->
                    {error,invalid_format};
                __@2 ->
                    error({with_clause,__@2})
            end
    end.