|
|
@ -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' %% 如果存在翻译修饰符t,则编码设置为true |
|
|
|
, 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(). |
|
|
|