Explorar el Código

ft: 修改为二进制匹配

master
SisMaker hace 4 años
padre
commit
4696759e92
Se han modificado 3 ficheros con 53 adiciones y 51 borrados
  1. +10
    -0
      include/eFmt.hrl
  2. +26
    -44
      src/eFmt.erl
  3. +17
    -7
      src/eFmtFormat.erl

+ 10
- 0
include/eFmt.hrl Ver fichero

@ -0,0 +1,10 @@
-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
}).

+ 26
- 44
src/eFmt.erl Ver fichero

@ -1,5 +1,7 @@
-module(eFmt).
-include("eFmt.hrl").
-export([
format/2
, format/3
@ -17,7 +19,6 @@
, write/1
, write/2
, write/3
, nl/0
, format_prompt/1
, format_prompt/2
@ -67,17 +68,6 @@
, chars_length/1
]).
-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
}).
-export_type([
chars/0
, latin1_string/0
@ -98,38 +88,38 @@
-type chars_limit() :: integer().
-opaque continuation() ::
{Format :: string(), Stack :: chars(), Nchars :: non_neg_integer(), Results :: [term()]}.
{Format :: string(), Stack :: chars(), Nchars :: non_neg_integer(), Results :: [term()]}.
-type fread_error() ::
'atom'
| 'based'
| 'character'
| 'float'
| 'format'
| 'input'
| 'integer'
| 'string'
| 'unsigned'.
'atom'
| 'based'
| 'character'
| 'float'
| 'format'
| 'input'
| 'integer'
| 'string'
| 'unsigned'.
-type fread_item() ::
string() |
atom() |
integer() |
float().
string() |
atom() |
integer() |
float().
-type fmtSpec() :: #fmtSpec{}.
-type format_spec() ::
#{
control_char := char(),
args := [any()],
width := 'none' | integer(),
adjust := 'left' | 'right',
precision := 'none' | integer(),
pad_char := char(),
encoding := 'unicode' | 'latin1',
strings := boolean()
}.
#{
control_char := char(),
args := [any()],
width := 'none' | integer(),
adjust := 'left' | 'right',
precision := 'none' | integer(),
pad_char := char(),
encoding := 'unicode' | 'latin1',
strings := boolean()
}.
%%----------------------------------------------------------------------
-spec format(Format :: io:format(), Data :: [term()]) -> chars().
@ -715,14 +705,6 @@ printable_unicode_list([$\e | Cs]) -> printable_unicode_list(Cs);
printable_unicode_list([]) -> true;
printable_unicode_list(_) -> false. %Everything else is false
%% List = nl()
%% Return a list of characters to generate a newline.
-spec nl() -> string().
nl() ->
"\n".
%%
%% Utilities for collecting characters in input files
%%

+ 17
- 7
src/eFmtFormat.erl Ver fichero

@ -1,5 +1,7 @@
-module(eFmtFormat).
-include("eFmt.hrl").
%% Formatting functions of io library.
-export([
fwrite/2
@ -70,6 +72,18 @@ scan(Format, Args) ->
collect(Format, Args)
end.
doCollect(FmtBinStr, Args) ->
MatchList = binary:matches(FmtBinStr, <<"~">>),
doCollectList(MatchList, FmtBinStr, Args, 0, []).
doCollectList([], _FmtBinStr, _Args, Index, Acc) ->
Acc;
doCollectList([OneMatch | MatchList], FmtBinStr, Args, Index, Acc) ->
ok.
collect([$~ | Fmt0], Args0) ->
{C, Fmt1, Args1} = collect_cseq(Fmt0, Args0),
[C | collect(Fmt1, Args1)];
@ -175,10 +189,8 @@ count_small([], P, S, W, Other) ->
{P, S, W, Other}.
%% build_small([Control]) -> eFmt:chars().
%% Interpret the control structures, but only the small ones.
%% The big ones are saved for later.
%% build_limited([Control], NumberOfPps, NumberOfLimited,
%% CharsLimit, Indentation)
%% Interpret the control structures, but only the small ones. The big ones are saved for later.
%% build_limited([Control], NumberOfPps, NumberOfLimited, CharsLimit, Indentation)
%% Interpret the control structures. Count the number of print
%% remaining and only calculate indentation when necessary. Must also
%% be smart when calculating indentation for characters in format.
@ -191,9 +203,7 @@ build_small([#{control_char := C, args := As, width := F, adjust := Ad, precisio
build_small([C | Cs]) -> [C | build_small(Cs)];
build_small([]) -> [].
build_limited([#{control_char := C, args := As, width := F, adjust := Ad,
precision := P, pad_char := Pad, encoding := Enc,
strings := Str} | Cs], NumOfPs0, Count0, MaxLen0, I) ->
build_limited([#{control_char := C, args := As, width := F, adjust := Ad, precision := P, pad_char := Pad, encoding := Enc, strings := Str} | Cs], NumOfPs0, Count0, MaxLen0, I) ->
MaxChars = if
MaxLen0 < 0 -> MaxLen0;
true -> MaxLen0 div Count0

Cargando…
Cancelar
Guardar