diff --git a/include/eFmt.hrl b/include/eFmt.hrl index 30a6829..85f1a28 100644 --- a/include/eFmt.hrl +++ b/include/eFmt.hrl @@ -1,6 +1,8 @@ %% 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)). diff --git a/src/eFmt.erl b/src/eFmt.erl index d7fa55a..2131004 100644 --- a/src/eFmt.erl +++ b/src/eFmt.erl @@ -9,6 +9,8 @@ -include("eFmt.hrl"). +-on_load(on_load/0). + -export([ %% eFmt format/2 @@ -54,6 +56,16 @@ -type fmtSpec() :: #fmtSpec{}. -type format() :: atom() | string() | binary(). +on_load() -> + ?log(on_load), + case persistent_term:get(?eFmtPtMc, undefined) of + undefined -> + persistent_term:put(?eFmtPtMc, binary:compile_pattern(<<"~">>)); + _ -> + ignore + end, + ok. + -spec format(Format :: format(), Data :: [term()]) -> chars(). format(Format, Args) -> try fWrite(Format, Args) @@ -503,7 +515,7 @@ fScan(Format, Args) -> end. doCollect(FmtBinStr, Args, Acc) -> - case split(FmtBinStr, <<"~">>) of + case split(FmtBinStr, persistent_term:get(?eFmtPtMc)) of [NotMatch] -> true = [] == Args, ?IIF(NotMatch == <<>>, Acc, [NotMatch | Acc]);