Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0a17ab2a
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0a17ab2a
编写于
1月 07, 2013
作者:
A
Andrew Paseltiner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fmt: replace parse_* structural records with struct Parsed<T>
上级
1a2a8975
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
40 deletion
+51
-40
src/libcore/extfmt.rs
src/libcore/extfmt.rs
+51
-40
未找到文件。
src/libcore/extfmt.rs
浏览文件 @
0a17ab2a
...
...
@@ -129,6 +129,17 @@ pub enum Count {
CountImplied
,
}
struct
Parsed
<
T
>
{
val
:
T
,
next
:
uint
}
impl
<
T
>
Parsed
<
T
>
{
static
pure
fn
new
(
val
:
T
,
next
:
uint
)
->
Parsed
<
T
>
{
Parsed
{
val
:
val
,
next
:
next
}
}
}
// A formatted conversion from an expression to a string
pub
struct
Conv
{
param
:
Option
<
uint
>
,
...
...
@@ -169,7 +180,7 @@ fn flush_buf(buf: ~str, pieces: &mut ~[Piece]) -> ~str {
}
else
{
buf
=
flush_buf
(
move
buf
,
&
mut
pieces
);
let
rs
=
parse_conversion
(
s
,
i
,
lim
,
err
);
pieces
.push
(
copy
rs
.
piece
);
pieces
.push
(
copy
rs
.
val
);
i
=
rs
.next
;
}
}
else
{
buf
+=
curr
;
i
+=
size
;
}
...
...
@@ -178,7 +189,7 @@ fn flush_buf(buf: ~str, pieces: &mut ~[Piece]) -> ~str {
move
pieces
}
pub
fn
peek_num
(
s
:
&
str
,
i
:
uint
,
lim
:
uint
)
->
Option
<
{
num
:
uint
,
next
:
uint
}
>
{
Option
<
Parsed
<
uint
>
>
{
let
mut
j
=
i
;
let
mut
accum
=
0u
;
let
mut
found
=
false
;
...
...
@@ -194,54 +205,54 @@ pub fn peek_num(s: &str, i: uint, lim: uint) ->
}
}
if
found
{
Some
(
{
num
:
accum
,
next
:
j
}
)
Some
(
Parsed
::
new
(
accum
,
j
)
)
}
else
{
None
}
}
pub
fn
parse_conversion
(
s
:
&
str
,
i
:
uint
,
lim
:
uint
,
err
:
ErrorFn
)
->
{
piece
:
Piece
,
next
:
uint
}
{
Parsed
<
Piece
>
{
let
parm
=
parse_parameter
(
s
,
i
,
lim
);
let
flags
=
parse_flags
(
s
,
parm
.next
,
lim
);
let
width
=
parse_count
(
s
,
flags
.next
,
lim
);
let
prec
=
parse_precision
(
s
,
width
.next
,
lim
);
let
ty
=
parse_type
(
s
,
prec
.next
,
lim
,
err
);
return
{
piece
:
PieceConv
(
Conv
{
param
:
parm
.
param
,
flags
:
copy
flags
.
flags
,
width
:
width
.
count
,
precision
:
prec
.
count
,
ty
:
ty
.
ty
}),
next
:
ty
.next
}
;
return
Parsed
::
new
(
PieceConv
(
Conv
{
param
:
parm
.
val
,
flags
:
copy
flags
.
val
,
width
:
width
.
val
,
precision
:
prec
.
val
,
ty
:
ty
.
val
}),
ty
.next
)
;
}
pub
fn
parse_parameter
(
s
:
&
str
,
i
:
uint
,
lim
:
uint
)
->
{
param
:
Option
<
uint
>
,
next
:
uint
}
{
if
i
>=
lim
{
return
{
param
:
None
,
next
:
i
}
;
}
Parsed
<
Option
<
uint
>>
{
if
i
>=
lim
{
return
Parsed
::
new
(
None
,
i
)
;
}
let
num
=
peek_num
(
s
,
i
,
lim
);
return
match
num
{
None
=>
{
param
:
None
,
next
:
i
}
,
None
=>
Parsed
::
new
(
None
,
i
)
,
Some
(
t
)
=>
{
let
n
=
t
.
num
;
let
n
=
t
.
val
;
let
j
=
t
.next
;
if
j
<
lim
&&
s
[
j
]
==
'$'
as
u8
{
{
param
:
Some
(
n
),
next
:
j
+
1
}
}
else
{
{
param
:
None
,
next
:
i
}
}
Parsed
::
new
(
Some
(
n
),
j
+
1
)
}
else
{
Parsed
::
new
(
None
,
i
)
}
}
};
}
pub
fn
parse_flags
(
s
:
&
str
,
i
:
uint
,
lim
:
uint
)
->
{
flags
:
~
[
Flag
],
next
:
uint
}
{
Parsed
<~
[
Flag
]
>
{
let
noflags
:
~
[
Flag
]
=
~
[];
if
i
>=
lim
{
return
{
flags
:
move
noflags
,
next
:
i
}
;
}
if
i
>=
lim
{
return
Parsed
::
new
(
move
noflags
,
i
)
;
}
fn
more
(
f
:
Flag
,
s
:
&
str
,
i
:
uint
,
lim
:
uint
)
->
{
flags
:
~
[
Flag
],
next
:
uint
}
{
Parsed
<~
[
Flag
]
>
{
let
next
=
parse_flags
(
s
,
i
+
1u
,
lim
);
let
rest
=
copy
next
.
flags
;
let
rest
=
copy
next
.
val
;
let
j
=
next
.next
;
let
curr
:
~
[
Flag
]
=
~
[
f
];
return
{
flags
:
vec
::
append
(
move
curr
,
rest
),
next
:
j
}
;
return
Parsed
::
new
(
vec
::
append
(
move
curr
,
rest
),
j
)
;
}
// Unfortunate, but because s is borrowed, can't use a closure
// fn more(f: Flag, s: &str) { more_(f, s, i, lim); }
...
...
@@ -256,48 +267,48 @@ fn more(f: Flag, s: &str, i: uint, lim: uint) ->
more
(
FlagSignAlways
,
s
,
i
,
lim
)
}
else
if
f
==
'#'
as
u8
{
more
(
FlagAlternate
,
s
,
i
,
lim
)
}
else
{
{
flags
:
move
noflags
,
next
:
i
}
};
}
else
{
Parsed
::
new
(
move
noflags
,
i
)
};
}
pub
fn
parse_count
(
s
:
&
str
,
i
:
uint
,
lim
:
uint
)
->
{
count
:
Count
,
next
:
uint
}
{
->
Parsed
<
Count
>
{
return
if
i
>=
lim
{
{
count
:
CountImplied
,
next
:
i
}
Parsed
::
new
(
CountImplied
,
i
)
}
else
if
s
[
i
]
==
'*'
as
u8
{
let
param
=
parse_parameter
(
s
,
i
+
1
,
lim
);
let
j
=
param
.next
;
match
param
.
param
{
None
=>
{
count
:
CountIsNextParam
,
next
:
j
}
,
Some
(
n
)
=>
{
count
:
CountIsParam
(
n
),
next
:
j
}
match
param
.
val
{
None
=>
Parsed
::
new
(
CountIsNextParam
,
j
)
,
Some
(
n
)
=>
Parsed
::
new
(
CountIsParam
(
n
),
j
)
}
}
else
{
let
num
=
peek_num
(
s
,
i
,
lim
);
match
num
{
None
=>
{
count
:
CountImplied
,
next
:
i
}
,
Some
(
num
)
=>
{
count
:
CountIs
(
num
.num
),
n
ext
:
n
um
.next
}
None
=>
Parsed
::
new
(
CountImplied
,
i
)
,
Some
(
num
)
=>
Parsed
::
new
(
CountIs
(
num
.val
),
num
.next
)
}
};
}
pub
fn
parse_precision
(
s
:
&
str
,
i
:
uint
,
lim
:
uint
)
->
{
count
:
Count
,
next
:
uint
}
{
Parsed
<
Count
>
{
return
if
i
>=
lim
{
{
count
:
CountImplied
,
next
:
i
}
Parsed
::
new
(
CountImplied
,
i
)
}
else
if
s
[
i
]
==
'.'
as
u8
{
let
count
=
parse_count
(
s
,
i
+
1u
,
lim
);
// If there were no digits specified, i.e. the precision
// was ".", then the precision is 0
match
count
.
count
{
CountImplied
=>
{
count
:
CountIs
(
0
),
next
:
count
.next
}
,
match
count
.
val
{
CountImplied
=>
Parsed
::
new
(
CountIs
(
0
),
count
.next
)
,
_
=>
count
}
}
else
{
{
count
:
CountImplied
,
next
:
i
}
};
}
else
{
Parsed
::
new
(
CountImplied
,
i
)
};
}
pub
fn
parse_type
(
s
:
&
str
,
i
:
uint
,
lim
:
uint
,
err
:
ErrorFn
)
->
{
ty
:
Ty
,
next
:
uint
}
{
Parsed
<
Ty
>
{
if
i
>=
lim
{
err
(
~
"missing type in conversion"
);
}
let
tstr
=
str
::
slice
(
s
,
i
,
i
+
1u
);
// FIXME (#2249): Do we really want two signed types here?
...
...
@@ -326,7 +337,7 @@ pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) ->
}
else
if
tstr
==
~
"?"
{
TyPoly
}
else
{
err
(
~
"unknown type in conversion: "
+
tstr
)
};
return
{
ty
:
t
,
next
:
i
+
1u
}
;
return
Parsed
::
new
(
t
,
i
+
1u
)
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录