This commit is contained in:
Craig Everett 2025-12-20 04:23:34 +09:00
parent 23137a677e
commit 81fef99d9c

View File

@ -20,7 +20,7 @@ amount(Pucks) ->
-spec amount(Style, Pucks) -> Formatted -spec amount(Style, Pucks) -> Formatted
when Style :: us | jp | metric | heresy | {Separator, Span}, when Style :: us | jp | metric | legacy | {Separator, Span},
Separator :: $, | $_, Separator :: $, | $_,
Span :: 3 | 4, Span :: 3 | 4,
Pucks :: integer(), Pucks :: integer(),
@ -35,7 +35,7 @@ amount(Style, Pucks) ->
-spec amount(Unit, Style, Pucks) -> Formatted -spec amount(Unit, Style, Pucks) -> Formatted
when Unit :: gaju | puck, when Unit :: gaju | puck,
Style :: us | jp | metric | heresy | {Separator, Span}, Style :: us | jp | metric | legacy | {Separator, Span},
Separator :: $, | $_, Separator :: $, | $_,
Span :: 3 | 4, Span :: 3 | 4,
Pucks :: integer(), Pucks :: integer(),
@ -51,7 +51,7 @@ amount(Unit, jp, Pucks) ->
jp(Unit, all, Pucks); jp(Unit, all, Pucks);
amount(Unit, metric, Pucks) -> amount(Unit, metric, Pucks) ->
bestern(Unit, ranks(metric), all, Pucks); bestern(Unit, ranks(metric), all, Pucks);
amount(Unit, heresy, Pucks) -> amount(Unit, legacy, Pucks) ->
bestern(Unit, ranks(heresy), all, Pucks); bestern(Unit, ranks(heresy), all, Pucks);
amount(gaju, {Separator, Span}, Pucks) -> amount(gaju, {Separator, Span}, Pucks) ->
western(Separator, $., Span, all, Pucks); western(Separator, $., Span, all, Pucks);
@ -61,7 +61,7 @@ amount(puck, {Separator, Span}, Pucks) ->
-spec amount(Unit, Style, Precision, Pucks) -> Serialized -spec amount(Unit, Style, Precision, Pucks) -> Serialized
when Unit :: gaju | puck, when Unit :: gaju | puck,
Style :: us | jp | metric | heresy | {Separator, Span}, Style :: us | jp | metric | legacy | {Separator, Span},
Precision :: all | 0..18, Precision :: all | 0..18,
Separator :: $, | $_, Separator :: $, | $_,
Span :: 3 | 4, Span :: 3 | 4,
@ -134,7 +134,7 @@ western2(Separator, Span, Pucks) ->
western(Separator, Break, Span, Precision, Pucks) when Pucks >= 0 -> western(Separator, Break, Span, Precision, Pucks) when Pucks >= 0 ->
western2(Separator, Break, Span, Precision, Pucks); western2(Separator, Break, Span, Precision, Pucks);
western(Separator, Break, Span, Precision, Pucks) when Pucks < 0 -> western(Separator, Break, Span, Precision, Pucks) when Pucks < 0 ->
[$- | western2(Separator, Break, Span, Precision, Pucks)]. [$- | western2(Separator, Break, Span, Precision, Pucks * -1)].
western2(Separator, _, Span, 0, Pucks) -> western2(Separator, _, Span, 0, Pucks) ->
@ -432,6 +432,11 @@ read([C | Rest])
C =:= $\r orelse C =:= $\r orelse
C =:= $\n -> C =:= $\n ->
read(Rest); read(Rest);
read([C | Rest]) when $0 =< C andalso C =< $9 ->
read(Rest, [C], []);
read([C | Rest]) when $ =< C andalso C =< $ ->
NumC = C - $ + $0,
read(Rest, [NumC], []);
read(_) -> read(_) ->
io:format("Barfing~n"), io:format("Barfing~n"),
{error, format}. {error, format}.
@ -457,7 +462,15 @@ read_w_gajus([], A) ->
G = list_to_integer(lists:reverse(A)) * one_gaju(), G = list_to_integer(lists:reverse(A)) * one_gaju(),
{ok, G}; {ok, G};
read_w_gajus([C, 32 | Rest], A) -> read_w_gajus([C, 32 | Rest], A) ->
read_b_gajus(Rest, [{C, A}]); read(Rest, [], [{C, A}]);
read_w_gajus([32, $G | Rest], A) ->
case read(Rest, [], [{$G, A}]) of
{ok, P} ->
G = list_to_integer(lists:reverse(A)) * one_gaju(),
{ok, G + P};
Error ->
Error
end;
read_w_gajus(_, _) -> read_w_gajus(_, _) ->
io:format("Derping~n"), io:format("Derping~n"),
{error, format}. {error, format}.
@ -475,77 +488,89 @@ read_w_pucks([], A) ->
Padded = lists:flatten(string:pad(lists:reverse(A), 18, trailing, $0)), Padded = lists:flatten(string:pad(lists:reverse(A), 18, trailing, $0)),
{ok, list_to_integer(Padded)}. {ok, list_to_integer(Padded)}.
read_b_gajus(_, _) ->
{error, nyi}. read([C | Rest], A, S) when $0 =< C andalso C =< $9 ->
read(Rest, [C | A], S);
read([C | Rest], A, S) when $ =< C andalso C =< $ ->
NumC = C - $ + $0,
read(Rest, [NumC | A], S);
read([$木], A, S) ->
calc([{$木, A} | S]);
read([$木, 32 | Rest], A, S) ->
read(Rest, [], [{$木, A} | S]);
read([$本], A, S) ->
calc([{$本, A} | S]);
read([32, $G], A, S) ->
calc([{$G, A} | S]);
read([32, $G, 32 | Rest], A, S) ->
read(Rest, [], [{$G, A} | S]);
read([32, $P], A, S) ->
calc([{$P, A} | S]);
read([C, 32 | Rest], A, S) ->
read(Rest, [], [{C, A} | S]);
read([C | Rest], A, S) ->
read(Rest, [], [{C, A} | S]);
read(_, _, _) ->
{error, format}.
calc(S) ->
calc(S, 0).
calc([{_, []} | S], A) ->
calc(S, A);
calc([{M, Cs} | S], A) ->
case magnitude(M) of
{ok, J} ->
N = list_to_integer(lists:reverse(Cs)) * J,
calc(S, A + N);
Error ->
Error
end;
calc([], A) ->
{ok, A}.
%magnitude_j("") -> 1_0000;
%magnitude_j("") -> 1_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000_0000_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000_0000_0000_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;
%magnitude_j("") -> 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;
%magnitude_j("") -> one_gaju();
%magnitude_j("") -> 1.
%is_numchar(C) -> $0 =< C andalso C =< $9. magnitude("") ->
% {ok, one_gaju()};
%read_jp([$-, Format]) -> magnitude("") ->
% read_jp_neg(Format); {ok, 1};
%read_jp([$, Format]) -> magnitude("G") ->
% read_jp_neg(Format); {ok, one_gaju()};
%read_jp(Format) -> magnitude("P") ->
% read_jp2(Format). {ok, 1};
% magnitude(Mark) ->
%read_jp_neg(Format) -> case rank(Mark, ranks(jp), 1_0000, 1) of
% case read_jp2(Format) of {ok, J} ->
% {ok, Pucks} -> {ok, Pucks * -1}; {ok, J};
% Error -> Error error ->
% end. case rank(Mark, ranks(metric), 1_000, 1) of
% {ok, N} -> {ok, N};
%read_jp2(Format) -> error -> rank(Mark, ranks(heresy), 1_000, 1)
% case segment_jp(Format) of end
% {ok, Segments} -> assemble_jp(Segments); end.
% Error -> Error
% end.
% rank(Mark, [Mark | _], Magnitude, Sum) ->
%segment_jp(Format) -> {ok, Sum * Magnitude};
% case string:split(Format, [gaju_mark()], all) of rank(Mark, [_ | Rest], Magnitude, Sum) ->
% [Gajus, Pucks] -> rank(Mark, Rest, Magnitude, Sum * Magnitude);
% case read_segment(Gajus) of rank(_, [], _, _) ->
% {ok, GajuSegments} -> error.
% case read_segment(Pucks) of
% {ok, PuckSegments} -> {ok, GajuSegments, PuckSegments};
% Error -> Error
% end;
% Error ->
% Error
% end;
% [Gajus] ->
% case read_segment(Gajus) of
% {ok, GajuSegments} -> {ok, GajuSegments, ["0"]};
% Error -> Error
% end;
% [] ->
% {ok, ["0"], ["0"]};
% _ ->
% {error, format}
% end.
%
%read_segment([C | T], R, A) when $0 =< C andalso C =< $9 ->
% N = C - $0,
% read_segment(T, R, [NA);
%read_segment([C | T], R, A) when $ =< C andalso C =< $ ->
%
%
%
%assemble_jp({GajuSegments, PuckSegments}) ->
% GajuString = lists:flatten(lists:map(fun expand_jp_myriad/1, GajuSegments)),
% PuckString = lists:flatten(lists:map(fun expand_jp_myriad/1, PuckDegments)),
% {ok, integer_to_list(lists:append(GajuString, PuckString))}.
%assemble_jp(PuckSegments) ->
% PuckString = lists:flatten(lists:map(fun expand_jp_myriad/1, PuckDegments)),
% {ok, integer_to_list(PuckString)}.
%
%expand_jp_myriad(String) ->
% string:pad(String, 4, leading, $0).
%
%
%hw_jp_numchar(C) when $ =< C andalso C =< $ ->
% C - $;
%hw_jp_numchar(C) ->
% C.
-spec price_to_string(Pucks) -> Gajus -spec price_to_string(Pucks) -> Gajus