Browse Source

ft: split匹配替换成 pattern_amtch

master
SisMaker 4 years ago
parent
commit
9ed8704671
2 changed files with 15 additions and 1 deletions
  1. +2
    -0
      include/eFmt.hrl
  2. +13
    -1
      src/eFmt.erl

+ 2
- 0
include/eFmt.hrl View File

@ -1,6 +1,8 @@
%% pretty %% pretty
-define(LineCCnt, 120). -define(LineCCnt, 120).
-define(eFmtPtMc, '$eFmtPtMc').
-define(base(Precision), case Precision of none -> 10; _ -> Precision end). -define(base(Precision), case Precision of none -> 10; _ -> Precision end).
%% %%
-define(IIF(Cond, Ret1, Ret2), (case Cond of true -> Ret1; _ -> Ret2 end)). -define(IIF(Cond, Ret1, Ret2), (case Cond of true -> Ret1; _ -> Ret2 end)).

+ 13
- 1
src/eFmt.erl View File

@ -9,6 +9,8 @@
-include("eFmt.hrl"). -include("eFmt.hrl").
-on_load(on_load/0).
-export([ -export([
%% eFmt %% eFmt
format/2 format/2
@ -54,6 +56,16 @@
-type fmtSpec() :: #fmtSpec{}. -type fmtSpec() :: #fmtSpec{}.
-type format() :: atom() | string() | binary(). -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(). -spec format(Format :: format(), Data :: [term()]) -> chars().
format(Format, Args) -> format(Format, Args) ->
try fWrite(Format, Args) try fWrite(Format, Args)
@ -503,7 +515,7 @@ fScan(Format, Args) ->
end. end.
doCollect(FmtBinStr, Args, Acc) -> doCollect(FmtBinStr, Args, Acc) ->
case split(FmtBinStr, <<"~">>) of
case split(FmtBinStr, persistent_term:get(?eFmtPtMc)) of
[NotMatch] -> [NotMatch] ->
true = [] == Args, true = [] == Args,
?IIF(NotMatch == <<>>, Acc, [NotMatch | Acc]); ?IIF(NotMatch == <<>>, Acc, [NotMatch | Acc]);

Loading…
Cancel
Save