Browse Source

Merge remote-tracking branch 'origin/master'

master
lijie 2 years ago
parent
commit
35f6ea6bce
2 changed files with 34 additions and 36 deletions
  1. +0
    -21
      include/eFmt.hrl
  2. +34
    -15
      src/eFmt.erl

+ 0
- 21
include/eFmt.hrl View File

@ -1,21 +0,0 @@
%% pretty
-define(LineCCnt, 120).
-define(eFmtPtMc, '$eFmtPtMc').
-define(base(Precision), case Precision of none -> 10; _ -> Precision end).
%%
-define(IIF(Cond, Ret1, Ret2), (case Cond of true -> Ret1; _ -> Ret2 end)).
-record(fmtSpec, {
ctlChar :: char() %% $p $w
, args :: [any()] %% 使
, width :: 'none' | integer() %%
, adjust :: 'left' | 'right' %%
, precision :: 'none' | integer() %%
, padChar :: char() %%
, encoding :: 'unicode' | 'latin1' %% ttrue
, strings :: boolean() %% l string设置为false
}).

+ 34
- 15
src/eFmt.erl View File

@ -7,7 +7,26 @@
-compile(inline).
-compile({inline_size, 128}).
-include("eFmt.hrl").
%% pretty
-define(LineCCnt, 120).
-define(eFmtPtMc, '$eFmtPtMc').
-define(base(Precision), case Precision of none -> 10; _ -> Precision end).
%%
-define(IIF(Cond, Ret1, Ret2), (case Cond of true -> Ret1; _ -> Ret2 end)).
-record(fmtSpec, {
ctlChar :: char() %% $p $w
, args :: [any()] %% 使
, width :: 'none' | integer() %%
, adjust :: 'left' | 'right' %%
, precision :: 'none' | integer() %%
, padChar :: char() %%
, encoding :: 'unicode' | 'latin1' %% ttrue
, strings :: boolean() %% l string设置为false
}).
-on_load(on_load/0).
@ -69,16 +88,16 @@ on_load() ->
format(Format, Args) ->
try fWrite(Format, Args)
catch
_C:_R ->
erlang:error(badarg, [Format, Args, _C, _R])
C:R:S ->
erlang:error(badarg, [Format, Args, {C, R, S}])
end.
-spec format(Format :: format(), Data :: [term()], Options :: [{charsLimit, CharsLimit :: charsLimit()}]) -> chars().
format(Format, Args, Options) ->
try fWrite(Format, Args, Options)
catch
_C:_R ->
erlang:error(badarg, [Format, Args, _C, _R])
C:R:S ->
erlang:error(badarg, [Format, Args, {C, R, S}])
end.
-spec formatBin(Format :: format(), Data :: [term()]) -> chars().
@ -87,8 +106,8 @@ formatBin(Format, Args) ->
Ret ->
iolist_to_binary(Ret)
catch
_C:_R ->
erlang:error(badarg, [Format, Args, _C, _R])
C:R:S ->
erlang:error(badarg, [Format, Args, {C, R, S}])
end.
-spec formatBin(Format :: format(), Data :: [term()], Options :: [{charsLimit, CharsLimit :: charsLimit()}]) -> chars().
@ -97,32 +116,32 @@ formatBin(Format, Args, Options) ->
Ret ->
iolist_to_binary(Ret)
catch
_C:_R ->
erlang:error(badarg, [Format, Args])
C:R:S ->
erlang:error(badarg, [Format, Args, {C, R, S}])
end.
-spec scan(Format :: format(), Data :: [term()]) -> FormatList :: [char() | fmtSpec()].
scan(Format, Args) ->
try fScan(Format, Args)
catch
_C:_R ->
erlang:error(badarg, [Format, Args])
C:R:S ->
erlang:error(badarg, [Format, Args, {C, R, S}])
end.
-spec build(FormatList :: [char() | fmtSpec()]) -> chars().
build(FormatList) ->
try fBuild(FormatList)
catch
_C:_R ->
erlang:error(badarg, [FormatList])
C:R:S ->
erlang:error(badarg, [FormatList, {C, R, S}])
end.
-spec build(FormatList :: [char() | fmtSpec()], Options :: [{charsLimit, CharsLimit :: charsLimit()}]) -> chars().
build(FormatList, Options) ->
try fBuild(FormatList, Options)
catch
_C:_R ->
erlang:error(badarg, [FormatList, Options])
C:R:S ->
erlang:error(badarg, [FormatList, Options, {C, R, S}])
end.
-spec write(Term :: term()) -> chars().

Loading…
Cancel
Save