WIP
This commit is contained in:
parent
beed46a38b
commit
975325db14
@ -5,7 +5,7 @@
|
||||
-module(hz_format).
|
||||
|
||||
-export([price/1, price/2, price/3, price/4,
|
||||
read/1,
|
||||
read/1, read/2,
|
||||
price_to_string/1, string_to_price/1]).
|
||||
|
||||
-spec price(Pucks) -> Formatted
|
||||
@ -211,12 +211,12 @@ jp2(gaju, 0, Pucks) ->
|
||||
myriad4(gaju_mark(), h, G);
|
||||
jp2(gaju, all, Pucks) ->
|
||||
H = jp(gaju, 0, Pucks),
|
||||
P = lists:flatten(string:pad(integer_to_list(Pucks rem one_gaju()), 18, leading, $0),
|
||||
P = lists:flatten(string:pad(integer_to_list(Pucks rem one_gaju()), 18, leading, $0)),
|
||||
T = myriad4("", l, lists:reverse(P)),
|
||||
lists:flatten([H, " ", T]);
|
||||
jp2(gaju, Precision, Pucks) ->
|
||||
H = jp(gaju, 0, Pucks),
|
||||
P = lists:flatten(string:pad(integer_to_list(Pucks rem one_gaju()), 18, leading, $0),
|
||||
P = lists:flatten(string:pad(integer_to_list(Pucks rem one_gaju()), 18, leading, $0)),
|
||||
Digits = min(Precision, 18),
|
||||
T =
|
||||
case length(P) > Digits of
|
||||
@ -346,7 +346,30 @@ read(Format) ->
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
-spec read(Style, Formatted) -> Result
|
||||
assess_style(Format) ->
|
||||
CharIndex = count_chars(Format),
|
||||
case maps:find($., CharIndex) of
|
||||
{ok, 1} ->
|
||||
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.
|
||||
|
||||
count_chars(Format) ->
|
||||
count_chars(Format, #{}).
|
||||
|
||||
count_chars([H | T], A) -> count_chars(T, maps:update_with(H, fun inc/1, 1, A));
|
||||
count_chars([], A) -> A.
|
||||
|
||||
inc(N) -> N + 1.
|
||||
|
||||
|
||||
-spec read(Style, Format) -> Result
|
||||
when Style :: us | ch | jp | undefined,
|
||||
Format :: string(),
|
||||
Result :: {ok, Pucks} | {error, Reason},
|
||||
@ -382,7 +405,7 @@ read2(jp, Format) ->
|
||||
read2(undefined, Format) ->
|
||||
read(Format).
|
||||
|
||||
read_western(Break, [$-, Rest]) ->
|
||||
read_western(Break, [$-, Format]) ->
|
||||
case read_western2(Break, Format) of
|
||||
{ok, Pucks} -> {ok, Pucks * -1};
|
||||
Error -> Error
|
||||
@ -448,7 +471,14 @@ segment_jp(Format) ->
|
||||
case string:split(Format, [gaju_mark()], all) of
|
||||
[Gajus, Pucks] ->
|
||||
case read_segment(Gajus) of
|
||||
{ok,
|
||||
{ok, GajuSegments} ->
|
||||
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"]};
|
||||
@ -460,6 +490,8 @@ segment_jp(Format) ->
|
||||
{error, format}
|
||||
end.
|
||||
|
||||
read_segment(
|
||||
|
||||
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)),
|
||||
@ -472,9 +504,9 @@ expand_jp_myriad(String) ->
|
||||
string:pad(String, 4, leading, $0).
|
||||
|
||||
|
||||
lower_jp_numchar(C) when $0 =< C andalso C =< $9 ->
|
||||
hw_jp_numchar(C) when $0 =< C andalso C =< $9 ->
|
||||
C - $0;
|
||||
lower_jp_numchar(C) ->
|
||||
hw_jp_numchar(C) ->
|
||||
C.
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user