Explorar el Código

ft: split匹配替换成 pattern_amtch

master
SisMaker hace 4 años
padre
commit
9ed8704671
Se han modificado 2 ficheros con 15 adiciones y 1 borrados
  1. +2
    -0
      include/eFmt.hrl
  2. +13
    -1
      src/eFmt.erl

+ 2
- 0
include/eFmt.hrl Ver fichero

@ -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)).

+ 13
- 1
src/eFmt.erl Ver fichero

@ -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]);

Cargando…
Cancelar
Guardar