Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e5ee13f1
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,发现更多精彩内容 >>
提交
e5ee13f1
编写于
9月 23, 2015
作者:
S
Steven Fackler
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add accessors for Formatter flags
cc #27726
上级
8fe79bdf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
7 deletion
+29
-7
src/libcore/fmt/mod.rs
src/libcore/fmt/mod.rs
+29
-7
未找到文件。
src/libcore/fmt/mod.rs
浏览文件 @
e5ee13f1
...
@@ -865,12 +865,12 @@ pub fn pad_integral(&mut self,
...
@@ -865,12 +865,12 @@ pub fn pad_integral(&mut self,
let
mut
sign
=
None
;
let
mut
sign
=
None
;
if
!
is_positive
{
if
!
is_positive
{
sign
=
Some
(
'-'
);
width
+=
1
;
sign
=
Some
(
'-'
);
width
+=
1
;
}
else
if
self
.
flags
&
(
1
<<
(
FlagV1
::
SignPlus
as
u32
))
!=
0
{
}
else
if
self
.
sign_plus
()
{
sign
=
Some
(
'+'
);
width
+=
1
;
sign
=
Some
(
'+'
);
width
+=
1
;
}
}
let
mut
prefixed
=
false
;
let
mut
prefixed
=
false
;
if
self
.
flags
&
(
1
<<
(
FlagV1
::
Alternate
as
u32
))
!=
0
{
if
self
.
alternate
()
{
prefixed
=
true
;
width
+=
prefix
.char_len
();
prefixed
=
true
;
width
+=
prefix
.char_len
();
}
}
...
@@ -900,7 +900,7 @@ pub fn pad_integral(&mut self,
...
@@ -900,7 +900,7 @@ pub fn pad_integral(&mut self,
}
}
// The sign and prefix goes before the padding if the fill character
// The sign and prefix goes before the padding if the fill character
// is zero
// is zero
Some
(
min
)
if
self
.
flags
&
(
1
<<
(
FlagV1
::
SignAwareZeroPad
as
u32
))
!=
0
=>
{
Some
(
min
)
if
self
.
sign_aware_zero_pad
()
=>
{
self
.fill
=
'0'
;
self
.fill
=
'0'
;
try!
(
write_prefix
(
self
));
try!
(
write_prefix
(
self
));
self
.with_padding
(
min
-
width
,
Alignment
::
Right
,
|
f
|
{
self
.with_padding
(
min
-
width
,
Alignment
::
Right
,
|
f
|
{
...
@@ -1013,7 +1013,7 @@ fn pad_formatted_parts(&mut self, formatted: &flt2dec::Formatted) -> Result {
...
@@ -1013,7 +1013,7 @@ fn pad_formatted_parts(&mut self, formatted: &flt2dec::Formatted) -> Result {
let
mut
formatted
=
formatted
.clone
();
let
mut
formatted
=
formatted
.clone
();
let
mut
align
=
self
.align
;
let
mut
align
=
self
.align
;
let
old_fill
=
self
.fill
;
let
old_fill
=
self
.fill
;
if
self
.
flags
&
(
1
<<
(
FlagV1
::
SignAwareZeroPad
as
u32
))
!=
0
{
if
self
.
sign_aware_zero_pad
()
{
// a sign always goes first
// a sign always goes first
let
sign
=
unsafe
{
str
::
from_utf8_unchecked
(
formatted
.sign
)
};
let
sign
=
unsafe
{
str
::
from_utf8_unchecked
(
formatted
.sign
)
};
try!
(
self
.buf
.write_str
(
sign
));
try!
(
self
.buf
.write_str
(
sign
));
...
@@ -1117,6 +1117,28 @@ pub fn width(&self) -> Option<usize> { self.width }
...
@@ -1117,6 +1117,28 @@ pub fn width(&self) -> Option<usize> { self.width }
issue
=
"27726"
)]
issue
=
"27726"
)]
pub
fn
precision
(
&
self
)
->
Option
<
usize
>
{
self
.precision
}
pub
fn
precision
(
&
self
)
->
Option
<
usize
>
{
self
.precision
}
/// Determines if the `+` flag was specified.
#[unstable(feature
=
"fmt_flags"
,
reason
=
"method was just created"
,
issue
=
"27726"
)]
pub
fn
sign_plus
(
&
self
)
->
bool
{
self
.flags
&
(
1
<<
FlagV1
::
SignPlus
as
u32
)
!=
0
}
/// Determines if the `-` flag was specified.
#[unstable(feature
=
"fmt_flags"
,
reason
=
"method was just created"
,
issue
=
"27726"
)]
pub
fn
sign_minus
(
&
self
)
->
bool
{
self
.flags
&
(
1
<<
FlagV1
::
SignMinus
as
u32
)
!=
0
}
/// Determines if the `#` flag was specified.
#[unstable(feature
=
"fmt_flags"
,
reason
=
"method was just created"
,
issue
=
"27726"
)]
pub
fn
alternate
(
&
self
)
->
bool
{
self
.flags
&
(
1
<<
FlagV1
::
Alternate
as
u32
)
!=
0
}
/// Determines if the `0` flag was specified.
#[unstable(feature
=
"fmt_flags"
,
reason
=
"method was just created"
,
issue
=
"27726"
)]
pub
fn
sign_aware_zero_pad
(
&
self
)
->
bool
{
self
.flags
&
(
1
<<
FlagV1
::
SignAwareZeroPad
as
u32
)
!=
0
}
/// Creates a `DebugStruct` builder designed to assist with creation of
/// Creates a `DebugStruct` builder designed to assist with creation of
/// `fmt::Debug` implementations for structs.
/// `fmt::Debug` implementations for structs.
///
///
...
@@ -1361,7 +1383,7 @@ fn fmt(&self, f: &mut Formatter) -> Result {
...
@@ -1361,7 +1383,7 @@ fn fmt(&self, f: &mut Formatter) -> Result {
// it denotes whether to prefix with 0x. We use it to work out whether
// it denotes whether to prefix with 0x. We use it to work out whether
// or not to zero extend, and then unconditionally set it to get the
// or not to zero extend, and then unconditionally set it to get the
// prefix.
// prefix.
if
f
.
flags
&
1
<<
(
FlagV1
::
Alternate
as
u32
)
>
0
{
if
f
.
alternate
()
{
f
.flags
|
=
1
<<
(
FlagV1
::
SignAwareZeroPad
as
u32
);
f
.flags
|
=
1
<<
(
FlagV1
::
SignAwareZeroPad
as
u32
);
if
let
None
=
f
.width
{
if
let
None
=
f
.width
{
...
@@ -1410,7 +1432,7 @@ fn fmt(&self, f: &mut Formatter) -> Result {
...
@@ -1410,7 +1432,7 @@ fn fmt(&self, f: &mut Formatter) -> Result {
fn
float_to_decimal_common
<
T
>
(
fmt
:
&
mut
Formatter
,
num
:
&
T
,
negative_zero
:
bool
)
->
Result
fn
float_to_decimal_common
<
T
>
(
fmt
:
&
mut
Formatter
,
num
:
&
T
,
negative_zero
:
bool
)
->
Result
where
T
:
flt2dec
::
DecodableFloat
where
T
:
flt2dec
::
DecodableFloat
{
{
let
force_sign
=
fmt
.
flags
&
(
1
<<
(
FlagV1
::
SignPlus
as
u32
))
!=
0
;
let
force_sign
=
fmt
.
sign_plus
()
;
let
sign
=
match
(
force_sign
,
negative_zero
)
{
let
sign
=
match
(
force_sign
,
negative_zero
)
{
(
false
,
false
)
=>
flt2dec
::
Sign
::
Minus
,
(
false
,
false
)
=>
flt2dec
::
Sign
::
Minus
,
(
false
,
true
)
=>
flt2dec
::
Sign
::
MinusRaw
,
(
false
,
true
)
=>
flt2dec
::
Sign
::
MinusRaw
,
...
@@ -1434,7 +1456,7 @@ fn float_to_decimal_common<T>(fmt: &mut Formatter, num: &T, negative_zero: bool)
...
@@ -1434,7 +1456,7 @@ fn float_to_decimal_common<T>(fmt: &mut Formatter, num: &T, negative_zero: bool)
fn
float_to_exponential_common
<
T
>
(
fmt
:
&
mut
Formatter
,
num
:
&
T
,
upper
:
bool
)
->
Result
fn
float_to_exponential_common
<
T
>
(
fmt
:
&
mut
Formatter
,
num
:
&
T
,
upper
:
bool
)
->
Result
where
T
:
flt2dec
::
DecodableFloat
where
T
:
flt2dec
::
DecodableFloat
{
{
let
force_sign
=
fmt
.
flags
&
(
1
<<
(
FlagV1
::
SignPlus
as
u32
))
!=
0
;
let
force_sign
=
fmt
.
sign_plus
()
;
let
sign
=
match
force_sign
{
let
sign
=
match
force_sign
{
false
=>
flt2dec
::
Sign
::
Minus
,
false
=>
flt2dec
::
Sign
::
Minus
,
true
=>
flt2dec
::
Sign
::
MinusPlus
,
true
=>
flt2dec
::
Sign
::
MinusPlus
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录