Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
535bd13f
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,发现更多精彩内容 >>
提交
535bd13f
编写于
8月 10, 2018
作者:
L
ljedrz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A few cleanups for fmt_macros, graphviz, apfloat, target, serialize and term
上级
f6d43ed8
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
141 addition
and
153 deletion
+141
-153
src/libfmt_macros/lib.rs
src/libfmt_macros/lib.rs
+5
-7
src/libgraphviz/lib.rs
src/libgraphviz/lib.rs
+6
-5
src/librustc_apfloat/ieee.rs
src/librustc_apfloat/ieee.rs
+44
-47
src/librustc_target/spec/mod.rs
src/librustc_target/spec/mod.rs
+4
-8
src/libserialize/hex.rs
src/libserialize/hex.rs
+1
-1
src/libserialize/json.rs
src/libserialize/json.rs
+28
-30
src/libserialize/leb128.rs
src/libserialize/leb128.rs
+2
-2
src/libterm/terminfo/mod.rs
src/libterm/terminfo/mod.rs
+8
-8
src/libterm/terminfo/parm.rs
src/libterm/terminfo/parm.rs
+41
-43
src/libterm/win.rs
src/libterm/win.rs
+2
-2
未找到文件。
src/libfmt_macros/lib.rs
浏览文件 @
535bd13f
...
...
@@ -411,7 +411,7 @@ fn format(&mut self) -> FormatSpec<'a> {
// fill character
if
let
Some
(
&
(
_
,
c
))
=
self
.cur
.peek
()
{
match
self
.cur
.clone
()
.
skip
(
1
)
.next
(
)
{
match
self
.cur
.clone
()
.
nth
(
1
)
{
Some
((
_
,
'>'
))
|
Some
((
_
,
'<'
))
|
Some
((
_
,
'^'
))
=>
{
spec
.fill
=
Some
(
c
);
self
.cur
.next
();
...
...
@@ -504,13 +504,11 @@ fn count(&mut self) -> Count<'a> {
if
word
.is_empty
()
{
self
.cur
=
tmp
;
CountImplied
}
else
if
self
.consume
(
'$'
)
{
CountIsName
(
word
)
}
else
{
if
self
.consume
(
'$'
)
{
CountIsName
(
word
)
}
else
{
self
.cur
=
tmp
;
CountImplied
}
self
.cur
=
tmp
;
CountImplied
}
}
}
...
...
src/libgraphviz/lib.rs
浏览文件 @
535bd13f
...
...
@@ -420,7 +420,8 @@ pub fn new<Name: IntoCow<'a, str>>(name: Name) -> Result<Id<'a>, ()> {
if
!
name
.chars
()
.all
(|
c
|
c
.is_ascii_alphanumeric
()
||
c
==
'_'
)
{
return
Err
(());
}
return
Ok
(
Id
{
name
:
name
});
Ok
(
Id
{
name
})
}
pub
fn
as_slice
(
&
'a
self
)
->
&
'a
str
{
...
...
@@ -533,10 +534,10 @@ fn escape_str(s: &str) -> String {
/// Renders text as string suitable for a label in a .dot file.
/// This includes quotes or suitable delimiters.
pub
fn
to_dot_string
(
&
self
)
->
String
{
match
self
{
&
LabelStr
(
ref
s
)
=>
format!
(
"
\"
{}
\"
"
,
s
.escape_default
()),
&
EscStr
(
ref
s
)
=>
format!
(
"
\"
{}
\"
"
,
LabelText
::
escape_str
(
&
s
)),
&
HtmlStr
(
ref
s
)
=>
format!
(
"<{}>"
,
s
),
match
*
self
{
LabelStr
(
ref
s
)
=>
format!
(
"
\"
{}
\"
"
,
s
.escape_default
()),
EscStr
(
ref
s
)
=>
format!
(
"
\"
{}
\"
"
,
LabelText
::
escape_str
(
&
s
)),
HtmlStr
(
ref
s
)
=>
format!
(
"<{}>"
,
s
),
}
}
...
...
src/librustc_apfloat/ieee.rs
浏览文件 @
535bd13f
...
...
@@ -536,23 +536,21 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Check whether we should use scientific notation.
let
scientific
=
if
width
==
0
{
true
}
else
if
exp
>=
0
{
// 765e3 --> 765000
// ^^^
// But we shouldn't make the number look more precise than it is.
exp
as
usize
>
width
||
digits
+
exp
as
usize
>
precision
}
else
{
if
exp
>=
0
{
// 765e3 --> 765000
// ^^^
//
But we shouldn't make the number look more precise than it is.
exp
as
usize
>
width
||
digits
+
exp
as
usize
>
precision
// Power of the most significant digit.
let
msd
=
exp
+
(
digits
-
1
)
as
ExpInt
;
if
msd
>=
0
{
//
765e-2 == 7.65
false
}
else
{
// Power of the most significant digit.
let
msd
=
exp
+
(
digits
-
1
)
as
ExpInt
;
if
msd
>=
0
{
// 765e-2 == 7.65
false
}
else
{
// 765e-5 == 0.00765
// ^ ^^
-
msd
as
usize
>
width
}
// 765e-5 == 0.00765
// ^ ^^
-
msd
as
usize
>
width
}
};
...
...
@@ -702,7 +700,7 @@ fn largest() -> Self {
// exponent = 1..10
// significand = 1..1
IeeeFloat
{
sig
:
[
!
0
&
((
1
<<
S
::
PRECISION
)
-
1
)
],
sig
:
[
(
1
<<
S
::
PRECISION
)
-
1
],
exp
:
S
::
MAX_EXP
,
category
:
Category
::
Normal
,
sign
:
false
,
...
...
@@ -1507,10 +1505,11 @@ fn is_x87_double_extended<S: Semantics>() -> bool {
}
// If this is a truncation, perform the shift.
let
mut
loss
=
Loss
::
ExactlyZero
;
if
shift
<
0
&&
(
r
.is_finite_non_zero
()
||
r
.category
==
Category
::
NaN
)
{
loss
=
sig
::
shift_right
(
&
mut
r
.sig
,
&
mut
0
,
-
shift
as
usize
);
}
let
loss
=
if
shift
<
0
&&
(
r
.is_finite_non_zero
()
||
r
.category
==
Category
::
NaN
)
{
sig
::
shift_right
(
&
mut
r
.sig
,
&
mut
0
,
-
shift
as
usize
)
}
else
{
Loss
::
ExactlyZero
};
// If this is an extension, perform the shift.
if
shift
>
0
&&
(
r
.is_finite_non_zero
()
||
r
.category
==
Category
::
NaN
)
{
...
...
@@ -1738,27 +1737,25 @@ fn from_hexadecimal_string(s: &str, round: Round) -> Result<StatusAnd<Self>, Par
bit_pos
-=
4
;
if
bit_pos
>=
0
{
r
.sig
[
0
]
|
=
(
hex_value
as
Limb
)
<<
bit_pos
;
}
else
{
// If zero or one-half (the hexadecimal digit 8) are followed
// by non-zero, they're a little more than zero or one-half.
if
let
Some
(
ref
mut
loss
)
=
loss
{
if
hex_value
!=
0
{
if
*
loss
==
Loss
::
ExactlyZero
{
*
loss
=
Loss
::
LessThanHalf
;
}
if
*
loss
==
Loss
::
ExactlyHalf
{
*
loss
=
Loss
::
MoreThanHalf
;
}
// If zero or one-half (the hexadecimal digit 8) are followed
// by non-zero, they're a little more than zero or one-half.
}
else
if
let
Some
(
ref
mut
loss
)
=
loss
{
if
hex_value
!=
0
{
if
*
loss
==
Loss
::
ExactlyZero
{
*
loss
=
Loss
::
LessThanHalf
;
}
if
*
loss
==
Loss
::
ExactlyHalf
{
*
loss
=
Loss
::
MoreThanHalf
;
}
}
else
{
loss
=
Some
(
match
hex_value
{
0
=>
Loss
::
ExactlyZero
,
1
..=
7
=>
Loss
::
LessThanHalf
,
8
=>
Loss
::
ExactlyHalf
,
9
..=
15
=>
Loss
::
MoreThanHalf
,
_
=>
unreachable!
(),
});
}
}
else
{
loss
=
Some
(
match
hex_value
{
0
=>
Loss
::
ExactlyZero
,
1
..=
7
=>
Loss
::
LessThanHalf
,
8
=>
Loss
::
ExactlyHalf
,
9
..=
15
=>
Loss
::
MoreThanHalf
,
_
=>
unreachable!
(),
});
}
}
else
if
c
==
'p'
||
c
==
'P'
{
if
!
any_digits
{
...
...
@@ -2309,9 +2306,9 @@ pub(super) fn is_all_zeros(limbs: &[Limb]) -> bool {
/// One, not zero, based LSB. That is, returns 0 for a zeroed significand.
pub
(
super
)
fn
olsb
(
limbs
:
&
[
Limb
])
->
usize
{
for
i
in
0
..
limbs
.len
()
{
if
limb
s
[
i
]
!=
0
{
return
i
*
LIMB_BITS
+
limb
s
[
i
]
.trailing_zeros
()
as
usize
+
1
;
for
(
i
,
&
limb
)
in
limbs
.iter
()
.enumerate
()
{
if
limb
!=
0
{
return
i
*
LIMB_BITS
+
limb
.trailing_zeros
()
as
usize
+
1
;
}
}
...
...
@@ -2320,9 +2317,9 @@ pub(super) fn olsb(limbs: &[Limb]) -> usize {
/// One, not zero, based MSB. That is, returns 0 for a zeroed significand.
pub
(
super
)
fn
omsb
(
limbs
:
&
[
Limb
])
->
usize
{
for
i
in
(
0
..
limbs
.len
()
)
.rev
()
{
if
limb
s
[
i
]
!=
0
{
return
(
i
+
1
)
*
LIMB_BITS
-
limb
s
[
i
]
.leading_zeros
()
as
usize
;
for
(
i
,
&
limb
)
in
limbs
.iter
()
.enumerate
(
)
.rev
()
{
if
limb
!=
0
{
return
(
i
+
1
)
*
LIMB_BITS
-
limb
.leading_zeros
()
as
usize
;
}
}
...
...
@@ -2378,7 +2375,7 @@ pub(super) fn shift_left(dst: &mut [Limb], exp: &mut ExpInt, bits: usize) {
limb
=
dst
[
i
-
jump
];
if
shift
>
0
{
limb
<<=
shift
;
if
i
>
=
jump
+
1
{
if
i
>
jump
{
limb
|
=
dst
[
i
-
jump
-
1
]
>>
(
LIMB_BITS
-
shift
);
}
}
...
...
@@ -2448,7 +2445,7 @@ pub(super) fn extract(dst: &mut [Limb], src: &[Limb], src_bits: usize, src_lsb:
let
n
=
dst_limbs
*
LIMB_BITS
-
shift
;
if
n
<
src_bits
{
let
mask
=
(
1
<<
(
src_bits
-
n
))
-
1
;
dst
[
dst_limbs
-
1
]
|
=
(
src
[
dst_limbs
]
&
mask
)
<<
n
%
LIMB_BITS
;
dst
[
dst_limbs
-
1
]
|
=
(
src
[
dst_limbs
]
&
mask
)
<<
(
n
%
LIMB_BITS
)
;
}
else
if
n
>
src_bits
&&
src_bits
%
LIMB_BITS
>
0
{
dst
[
dst_limbs
-
1
]
&=
(
1
<<
(
src_bits
%
LIMB_BITS
))
-
1
;
}
...
...
src/librustc_target/spec/mod.rs
浏览文件 @
535bd13f
...
...
@@ -764,14 +764,10 @@ pub fn from_json(obj: Json) -> TargetResult {
// the JSON parser is not updated to match the structs.
let
get_req_field
=
|
name
:
&
str
|
{
match
obj
.find
(
name
)
.map
(|
s
|
s
.as_string
())
.and_then
(|
os
|
os
.map
(|
s
|
s
.to_string
()))
{
Some
(
val
)
=>
Ok
(
val
),
None
=>
{
return
Err
(
format!
(
"Field {} in target specification is required"
,
name
))
}
}
obj
.find
(
name
)
.map
(|
s
|
s
.as_string
())
.and_then
(|
os
|
os
.map
(|
s
|
s
.to_string
()))
.ok_or_else
(||
format!
(
"Field {} in target specification is required"
,
name
))
};
let
get_opt_field
=
|
name
:
&
str
,
default
:
&
str
|
{
...
...
src/libserialize/hex.rs
浏览文件 @
535bd13f
...
...
@@ -22,7 +22,7 @@ pub trait ToHex {
fn
to_hex
(
&
self
)
->
String
;
}
const
CHARS
:
&
'static
[
u8
]
=
b
"0123456789abcdef"
;
const
CHARS
:
&
[
u8
]
=
b
"0123456789abcdef"
;
impl
ToHex
for
[
u8
]
{
/// Turn a vector of `u8` bytes into a hexadecimal string.
...
...
src/libserialize/json.rs
浏览文件 @
535bd13f
...
...
@@ -438,7 +438,7 @@ fn escape_char(writer: &mut dyn fmt::Write, v: char) -> EncodeResult {
}
fn
spaces
(
wr
:
&
mut
dyn
fmt
::
Write
,
mut
n
:
usize
)
->
EncodeResult
{
const
BUF
:
&
'static
str
=
" "
;
const
BUF
:
&
str
=
" "
;
while
n
>=
BUF
.len
()
{
wr
.write_str
(
BUF
)
?
;
...
...
@@ -799,21 +799,21 @@ fn emit_enum_variant<F>(&mut self,
escape_str
(
self
.writer
,
name
)
}
else
{
if
self
.is_emitting_map_key
{
return
Err
(
EncoderError
::
BadHashmapKey
);
}
write
!
(
self
.writer
,
"{{
\n
"
)
?
;
write
ln!
(
self
.writer
,
"{{
"
)
?
;
self
.curr_indent
+=
self
.indent
;
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
write!
(
self
.writer
,
"
\"
variant
\"
: "
)
?
;
escape_str
(
self
.writer
,
name
)
?
;
write
!
(
self
.writer
,
",
\n
"
)
?
;
write
ln!
(
self
.writer
,
",
"
)
?
;
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
write
!
(
self
.writer
,
"
\"
fields
\"
: [
\n
"
)
?
;
write
ln!
(
self
.writer
,
"
\"
fields
\"
: [
"
)
?
;
self
.curr_indent
+=
self
.indent
;
f
(
self
)
?
;
self
.curr_indent
-=
self
.indent
;
write
!
(
self
.writer
,
"
\n
"
)
?
;
write
ln!
(
self
.writer
)
?
;
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
self
.curr_indent
-=
self
.indent
;
write
!
(
self
.writer
,
"]
\n
"
)
?
;
write
ln!
(
self
.writer
,
"]
"
)
?
;
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
write!
(
self
.writer
,
"}}"
)
?
;
Ok
(())
...
...
@@ -825,7 +825,7 @@ fn emit_enum_variant_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult where
{
if
self
.is_emitting_map_key
{
return
Err
(
EncoderError
::
BadHashmapKey
);
}
if
idx
!=
0
{
write
!
(
self
.writer
,
",
\n
"
)
?
;
write
ln!
(
self
.writer
,
",
"
)
?
;
}
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
f
(
self
)
...
...
@@ -864,7 +864,7 @@ fn emit_struct<F>(&mut self, _: &str, len: usize, f: F) -> EncodeResult where
self
.curr_indent
+=
self
.indent
;
f
(
self
)
?
;
self
.curr_indent
-=
self
.indent
;
write
!
(
self
.writer
,
"
\n
"
)
?
;
write
ln!
(
self
.writer
)
?
;
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
write!
(
self
.writer
,
"}}"
)
?
;
}
...
...
@@ -876,9 +876,9 @@ fn emit_struct_field<F>(&mut self, name: &str, idx: usize, f: F) -> EncodeResult
{
if
self
.is_emitting_map_key
{
return
Err
(
EncoderError
::
BadHashmapKey
);
}
if
idx
==
0
{
write
!
(
self
.writer
,
"
\n
"
)
?
;
write
ln!
(
self
.writer
)
?
;
}
else
{
write
!
(
self
.writer
,
",
\n
"
)
?
;
write
ln!
(
self
.writer
,
",
"
)
?
;
}
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
escape_str
(
self
.writer
,
name
)
?
;
...
...
@@ -940,7 +940,7 @@ fn emit_seq<F>(&mut self, len: usize, f: F) -> EncodeResult where
self
.curr_indent
+=
self
.indent
;
f
(
self
)
?
;
self
.curr_indent
-=
self
.indent
;
write
!
(
self
.writer
,
"
\n
"
)
?
;
write
ln!
(
self
.writer
)
?
;
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
write!
(
self
.writer
,
"]"
)
?
;
}
...
...
@@ -952,9 +952,9 @@ fn emit_seq_elt<F>(&mut self, idx: usize, f: F) -> EncodeResult where
{
if
self
.is_emitting_map_key
{
return
Err
(
EncoderError
::
BadHashmapKey
);
}
if
idx
==
0
{
write
!
(
self
.writer
,
"
\n
"
)
?
;
write
ln!
(
self
.writer
)
?
;
}
else
{
write
!
(
self
.writer
,
",
\n
"
)
?
;
write
ln!
(
self
.writer
,
",
"
)
?
;
}
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
f
(
self
)
...
...
@@ -971,7 +971,7 @@ fn emit_map<F>(&mut self, len: usize, f: F) -> EncodeResult where
self
.curr_indent
+=
self
.indent
;
f
(
self
)
?
;
self
.curr_indent
-=
self
.indent
;
write
!
(
self
.writer
,
"
\n
"
)
?
;
write
ln!
(
self
.writer
)
?
;
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
write!
(
self
.writer
,
"}}"
)
?
;
}
...
...
@@ -983,9 +983,9 @@ fn emit_map_elt_key<F>(&mut self, idx: usize, f: F) -> EncodeResult where
{
if
self
.is_emitting_map_key
{
return
Err
(
EncoderError
::
BadHashmapKey
);
}
if
idx
==
0
{
write
!
(
self
.writer
,
"
\n
"
)
?
;
write
ln!
(
self
.writer
)
?
;
}
else
{
write
!
(
self
.writer
,
",
\n
"
)
?
;
write
ln!
(
self
.writer
,
",
"
)
?
;
}
spaces
(
self
.writer
,
self
.curr_indent
)
?
;
self
.is_emitting_map_key
=
true
;
...
...
@@ -1387,10 +1387,10 @@ fn pop(&mut self) {
// Used by Parser to test whether the top-most element is an index.
fn
last_is_index
(
&
self
)
->
bool
{
if
self
.is_empty
()
{
return
false
;
}
return
match
*
self
.stack
.last
()
.unwrap
()
{
InternalIndex
(
_
)
=>
true
,
_
=>
false
,
if
let
Some
(
InternalIndex
(
_
))
=
self
.stack
.last
()
{
true
}
else
{
false
}
}
...
...
@@ -1530,19 +1530,17 @@ fn parse_number(&mut self) -> JsonEvent {
}
F64Value
(
res
)
}
else
{
if
neg
{
let
res
=
(
res
as
i64
)
.wrapping_neg
();
}
else
if
neg
{
let
res
=
(
res
as
i64
)
.wrapping_neg
();
// Make sure we didn't underflow.
if
res
>
0
{
Error
(
SyntaxError
(
InvalidNumber
,
self
.line
,
self
.col
))
}
else
{
I64Value
(
res
)
}
// Make sure we didn't underflow.
if
res
>
0
{
Error
(
SyntaxError
(
InvalidNumber
,
self
.line
,
self
.col
))
}
else
{
U
64Value
(
res
)
I
64Value
(
res
)
}
}
else
{
U64Value
(
res
)
}
}
...
...
src/libserialize/leb128.rs
浏览文件 @
535bd13f
...
...
@@ -103,8 +103,8 @@ pub fn write_signed_leb128_to<W>(mut value: i128, mut write: W)
loop
{
let
mut
byte
=
(
value
as
u8
)
&
0x7f
;
value
>>=
7
;
let
more
=
!
(((
(
value
==
0
)
&&
((
byte
&
0x40
)
==
0
))
||
((
value
==
-
1
)
&&
((
byte
&
0x40
)
!=
0
)
)));
let
more
=
!
(((
value
==
0
)
&&
((
byte
&
0x40
)
==
0
))
||
((
value
==
-
1
)
&&
((
byte
&
0x40
)
!=
0
)));
if
more
{
byte
|
=
0x80
;
// Mark this byte to show that more bytes will follow.
...
...
src/libterm/terminfo/mod.rs
浏览文件 @
535bd13f
...
...
@@ -60,8 +60,8 @@ fn description(&self) -> &str {
fn
cause
(
&
self
)
->
Option
<&
dyn
error
::
Error
>
{
use
self
::
Error
::
*
;
match
self
{
&
IoError
(
ref
e
)
=>
Some
(
e
),
match
*
self
{
IoError
(
ref
e
)
=>
Some
(
e
),
_
=>
None
,
}
}
...
...
@@ -70,10 +70,10 @@ fn cause(&self) -> Option<&dyn error::Error> {
impl
fmt
::
Display
for
Error
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
use
self
::
Error
::
*
;
match
self
{
&
TermUnset
=>
Ok
(()),
&
MalformedTerminfo
(
ref
e
)
=>
e
.fmt
(
f
),
&
IoError
(
ref
e
)
=>
e
.fmt
(
f
),
match
*
self
{
TermUnset
=>
Ok
(()),
MalformedTerminfo
(
ref
e
)
=>
e
.fmt
(
f
),
IoError
(
ref
e
)
=>
e
.fmt
(
f
),
}
}
}
...
...
@@ -109,9 +109,9 @@ pub fn from_path<P: AsRef<Path>>(path: P) -> Result<TermInfo, Error> {
}
// Keep the metadata small
fn
_
from_path
(
path
:
&
Path
)
->
Result
<
TermInfo
,
Error
>
{
let
file
=
File
::
open
(
path
)
.map_err
(
|
e
|
Error
::
IoError
(
e
)
)
?
;
let
file
=
File
::
open
(
path
)
.map_err
(
Error
::
IoError
)
?
;
let
mut
reader
=
BufReader
::
new
(
file
);
parse
(
&
mut
reader
,
false
)
.map_err
(
|
e
|
Error
::
MalformedTerminfo
(
e
)
)
parse
(
&
mut
reader
,
false
)
.map_err
(
Error
::
MalformedTerminfo
)
}
}
...
...
src/libterm/terminfo/parm.rs
浏览文件 @
535bd13f
...
...
@@ -12,8 +12,6 @@
use
self
::
Param
::
*
;
use
self
::
States
::
*
;
use
self
::
FormatState
::
*
;
use
self
::
FormatOp
::
*
;
use
std
::
iter
::
repeat
;
...
...
@@ -36,9 +34,9 @@ enum States {
#[derive(Copy,
PartialEq,
Clone)]
enum
FormatState
{
F
ormatStateF
lags
,
FormatState
Width
,
FormatState
Precision
,
Flags
,
Width
,
Precision
,
}
/// Types of parameters a capability can use
...
...
@@ -210,22 +208,22 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
if
let
Some
(
arg
)
=
stack
.pop
()
{
let
flags
=
Flags
::
new
();
let
res
=
format
(
arg
,
FormatOp
::
from_char
(
cur
),
flags
)
?
;
output
.extend
(
res
.iter
()
.
map
(|
x
|
*
x
));
output
.extend
(
res
.iter
()
.
cloned
(
));
}
else
{
return
Err
(
"stack is empty"
.to_string
());
}
}
':'
|
'#'
|
' '
|
'.'
|
'0'
..=
'9'
=>
{
let
mut
flags
=
Flags
::
new
();
let
mut
fstate
=
FormatStateFlags
;
let
mut
fstate
=
FormatState
::
Flags
;
match
cur
{
':'
=>
(),
'#'
=>
flags
.alternate
=
true
,
' '
=>
flags
.space
=
true
,
'.'
=>
fstate
=
FormatStatePrecision
,
'.'
=>
fstate
=
FormatState
::
Precision
,
'0'
..=
'9'
=>
{
flags
.width
=
cur
as
usize
-
'0'
as
usize
;
fstate
=
FormatStateWidth
;
fstate
=
FormatState
::
Width
;
}
_
=>
unreachable!
(),
}
...
...
@@ -318,43 +316,43 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
(
_
,
'd'
)
|
(
_
,
'o'
)
|
(
_
,
'x'
)
|
(
_
,
'X'
)
|
(
_
,
's'
)
=>
{
if
let
Some
(
arg
)
=
stack
.pop
()
{
let
res
=
format
(
arg
,
FormatOp
::
from_char
(
cur
),
*
flags
)
?
;
output
.extend
(
res
.iter
()
.
map
(|
x
|
*
x
));
output
.extend
(
res
.iter
()
.
cloned
(
));
// will cause state to go to Nothing
old_state
=
FormatPattern
(
*
flags
,
*
fstate
);
}
else
{
return
Err
(
"stack is empty"
.to_string
());
}
}
(
FormatStateFlags
,
'#'
)
=>
{
(
FormatState
::
Flags
,
'#'
)
=>
{
flags
.alternate
=
true
;
}
(
FormatStateFlags
,
'-'
)
=>
{
(
FormatState
::
Flags
,
'-'
)
=>
{
flags
.left
=
true
;
}
(
FormatStateFlags
,
'+'
)
=>
{
(
FormatState
::
Flags
,
'+'
)
=>
{
flags
.sign
=
true
;
}
(
FormatStateFlags
,
' '
)
=>
{
(
FormatState
::
Flags
,
' '
)
=>
{
flags
.space
=
true
;
}
(
FormatStateFlags
,
'0'
..=
'9'
)
=>
{
(
FormatState
::
Flags
,
'0'
..=
'9'
)
=>
{
flags
.width
=
cur
as
usize
-
'0'
as
usize
;
*
fstate
=
FormatStateWidth
;
*
fstate
=
FormatState
::
Width
;
}
(
FormatStateFlags
,
'.'
)
=>
{
*
fstate
=
FormatStatePrecision
;
(
FormatState
::
Flags
,
'.'
)
=>
{
*
fstate
=
FormatState
::
Precision
;
}
(
FormatStateWidth
,
'0'
..=
'9'
)
=>
{
(
FormatState
::
Width
,
'0'
..=
'9'
)
=>
{
let
old
=
flags
.width
;
flags
.width
=
flags
.width
*
10
+
(
cur
as
usize
-
'0'
as
usize
);
if
flags
.width
<
old
{
return
Err
(
"format width overflow"
.to_string
());
}
}
(
FormatStateWidth
,
'.'
)
=>
{
*
fstate
=
FormatStatePrecision
;
(
FormatState
::
Width
,
'.'
)
=>
{
*
fstate
=
FormatState
::
Precision
;
}
(
FormatStatePrecision
,
'0'
..=
'9'
)
=>
{
(
FormatState
::
Precision
,
'0'
..=
'9'
)
=>
{
let
old
=
flags
.precision
;
flags
.precision
=
flags
.precision
*
10
+
(
cur
as
usize
-
'0'
as
usize
);
if
flags
.precision
<
old
{
...
...
@@ -437,31 +435,31 @@ fn new() -> Flags {
#[derive(Copy,
Clone)]
enum
FormatOp
{
Format
Digit
,
Format
Octal
,
Format
Hex
,
FormatHEX
,
Format
String
,
Digit
,
Octal
,
Lower
Hex
,
UpperHex
,
String
,
}
impl
FormatOp
{
fn
from_char
(
c
:
char
)
->
FormatOp
{
match
c
{
'd'
=>
FormatDigit
,
'o'
=>
FormatOctal
,
'x'
=>
FormatHex
,
'X'
=>
Format
HEX
,
's'
=>
FormatString
,
'd'
=>
Format
Op
::
Digit
,
'o'
=>
FormatO
p
::
O
ctal
,
'x'
=>
Format
Op
::
Lower
Hex
,
'X'
=>
Format
Op
::
UpperHex
,
's'
=>
Format
Op
::
String
,
_
=>
panic!
(
"bad FormatOp char"
),
}
}
fn
to_char
(
self
)
->
char
{
match
self
{
FormatDigit
=>
'd'
,
FormatOctal
=>
'o'
,
FormatHex
=>
'x'
,
Format
HEX
=>
'X'
,
FormatString
=>
's'
,
Format
Op
::
Digit
=>
'd'
,
FormatO
p
::
O
ctal
=>
'o'
,
Format
Op
::
Lower
Hex
=>
'x'
,
Format
Op
::
UpperHex
=>
'X'
,
Format
Op
::
String
=>
's'
,
}
}
}
...
...
@@ -470,7 +468,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8>, String> {
let
mut
s
=
match
val
{
Number
(
d
)
=>
{
match
op
{
FormatDigit
=>
{
Format
Op
::
Digit
=>
{
if
flags
.sign
{
format!
(
"{:+01$}"
,
d
,
flags
.precision
)
}
else
if
d
<
0
{
...
...
@@ -482,7 +480,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8>, String> {
format!
(
"{:01$}"
,
d
,
flags
.precision
)
}
}
FormatOctal
=>
{
FormatO
p
::
O
ctal
=>
{
if
flags
.alternate
{
// Leading octal zero counts against precision.
format!
(
"0{:01$o}"
,
d
,
flags
.precision
.saturating_sub
(
1
))
...
...
@@ -490,27 +488,27 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8>, String> {
format!
(
"{:01$o}"
,
d
,
flags
.precision
)
}
}
FormatHex
=>
{
Format
Op
::
Lower
Hex
=>
{
if
flags
.alternate
&&
d
!=
0
{
format!
(
"0x{:01$x}"
,
d
,
flags
.precision
)
}
else
{
format!
(
"{:01$x}"
,
d
,
flags
.precision
)
}
}
Format
HEX
=>
{
Format
Op
::
UpperHex
=>
{
if
flags
.alternate
&&
d
!=
0
{
format!
(
"0X{:01$X}"
,
d
,
flags
.precision
)
}
else
{
format!
(
"{:01$X}"
,
d
,
flags
.precision
)
}
}
FormatString
=>
return
Err
(
"non-number on stack with %s"
.to_string
()),
Format
Op
::
String
=>
return
Err
(
"non-number on stack with %s"
.to_string
()),
}
.into_bytes
()
}
Words
(
s
)
=>
{
match
op
{
FormatString
=>
{
Format
Op
::
String
=>
{
let
mut
s
=
s
.into_bytes
();
if
flags
.precision
>
0
&&
flags
.precision
<
s
.len
()
{
s
.truncate
(
flags
.precision
);
...
...
src/libterm/win.rs
浏览文件 @
535bd13f
...
...
@@ -198,11 +198,11 @@ fn reset(&mut self) -> io::Result<bool> {
Ok
(
true
)
}
fn
get_ref
<
'a
>
(
&
'a
self
)
->
&
'a
T
{
fn
get_ref
(
&
self
)
->
&
T
{
&
self
.buf
}
fn
get_mut
<
'a
>
(
&
'a
mut
self
)
->
&
'a
mut
T
{
fn
get_mut
(
&
mut
self
)
->
&
mut
T
{
&
mut
self
.buf
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录