WIP
This commit is contained in:
parent
975325db14
commit
11730de24a
@ -42,8 +42,6 @@ price(Style, Pucks) ->
|
|||||||
Formatted :: string().
|
Formatted :: string().
|
||||||
%% @doc
|
%% @doc
|
||||||
%% A simplified format function covering the most common formats desired.
|
%% A simplified format function covering the most common formats desired.
|
||||||
%%
|
|
||||||
%% ```
|
|
||||||
|
|
||||||
price(gaju, us, Pucks) ->
|
price(gaju, us, Pucks) ->
|
||||||
western($,, $., 3, all, Pucks);
|
western($,, $., 3, all, Pucks);
|
||||||
@ -245,7 +243,8 @@ jp2(puck, Precision, Pucks) ->
|
|||||||
true ->
|
true ->
|
||||||
[$0, puck_mark()];
|
[$0, puck_mark()];
|
||||||
false ->
|
false ->
|
||||||
PuckingString = lists:flatten(string:pad(lists:reverse(lists:sublist(P, Digits)), 18, leading, $0)),
|
PucksToGive = lists:sublist(P, Digits),
|
||||||
|
PuckingString = lists:flatten(string:pad(lists:reverse(PucksToGive), 18, leading, $0)),
|
||||||
case lists:all(fun(C) -> C =:= $0 end, PuckingString) of
|
case lists:all(fun(C) -> C =:= $0 end, PuckingString) of
|
||||||
false -> myriad4(puck_mark(), h, PuckingString);
|
false -> myriad4(puck_mark(), h, PuckingString);
|
||||||
true -> [$0, puck_mark()]
|
true -> [$0, puck_mark()]
|
||||||
@ -339,34 +338,30 @@ one_gaju() -> 1_000_000_000_000_000_000.
|
|||||||
%% style. When in doubt, always call `read/2' with a style specified.
|
%% style. When in doubt, always call `read/2' with a style specified.
|
||||||
|
|
||||||
read(Format) ->
|
read(Format) ->
|
||||||
case assess_style(Format) of
|
case assess_style(string:trim(Format)) of
|
||||||
us -> read(us, Format);
|
us -> read(us, Format);
|
||||||
ch -> read(ch, Format);
|
ch -> read(ch, Format);
|
||||||
jp -> read(jp, Format);
|
jp -> read(jp, Format);
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
assess_style([H1, H2 | Numbers])
|
||||||
|
when H1 =:= $木 orelse H1 =:= $本 orelse H2 =:= $木 orelse H2 =:= $本 ->
|
||||||
|
case count($., Numbers) > 1 of
|
||||||
|
false -> us;
|
||||||
|
true -> ch
|
||||||
|
end;
|
||||||
assess_style(Format) ->
|
assess_style(Format) ->
|
||||||
CharIndex = count_chars(Format),
|
case lists:member($木, Format) orelse lists:member($本, Format) of
|
||||||
case maps:find($., CharIndex) of
|
true -> jp;
|
||||||
{ok, 1} ->
|
false -> {error, format}
|
||||||
us;
|
|
||||||
{ok, N} when N > 1 ->
|
|
||||||
ch;
|
|
||||||
error ->
|
|
||||||
case maps:is_key($木, CharIndex) orelse maps:is_key($本, CharIndex) of
|
|
||||||
true -> read(jp, Format);
|
|
||||||
false -> {error, format}
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
count_chars(Format) ->
|
count(Char, String) -> count(Char, String, 0).
|
||||||
count_chars(Format, #{}).
|
|
||||||
|
|
||||||
count_chars([H | T], A) -> count_chars(T, maps:update_with(H, fun inc/1, 1, A));
|
count(C, [C | T], A) -> count(C, T, A + 1);
|
||||||
count_chars([], A) -> A.
|
count(C, [_ | T], A) -> count(C, T, A);
|
||||||
|
count(_, [], A) -> A.
|
||||||
inc(N) -> N + 1.
|
|
||||||
|
|
||||||
|
|
||||||
-spec read(Style, Format) -> Result
|
-spec read(Style, Format) -> Result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user