Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e16f94f6
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,发现更多精彩内容 >>
提交
e16f94f6
编写于
3月 28, 2013
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #5607 : brson/rust/shapshot3, r=brson
上级
86024e39
145f66fd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
189 deletion
+8
-189
src/libcore/unstable/extfmt.rs
src/libcore/unstable/extfmt.rs
+0
-189
src/snapshots.txt
src/snapshots.txt
+8
-0
未找到文件。
src/libcore/unstable/extfmt.rs
浏览文件 @
e16f94f6
...
...
@@ -470,9 +470,6 @@ fn test_peek_num() {
// decisions made a runtime. If it proves worthwhile then some of these
// conditions can be evaluated at compile-time. For now though it's cleaner to
// implement it this way, I think.
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
#[doc(hidden)]
pub
mod
rt
{
use
float
;
...
...
@@ -676,192 +673,6 @@ pub fn have_flag(flags: u32, f: u32) -> bool {
}
}
// XXX: remove after a snapshot of the above changes have gone in
#[cfg(stage0)]
#[doc(hidden)]
pub
mod
rt
{
use
float
;
use
str
;
use
sys
;
use
uint
;
use
vec
;
pub
static
flag_none
:
u32
=
0u32
;
pub
static
flag_left_justify
:
u32
=
0b00000000000001u32
;
pub
static
flag_left_zero_pad
:
u32
=
0b00000000000010u32
;
pub
static
flag_space_for_sign
:
u32
=
0b00000000000100u32
;
pub
static
flag_sign_always
:
u32
=
0b00000000001000u32
;
pub
static
flag_alternate
:
u32
=
0b00000000010000u32
;
pub
enum
Count
{
CountIs
(
uint
),
CountImplied
,
}
pub
enum
Ty
{
TyDefault
,
TyBits
,
TyHexUpper
,
TyHexLower
,
TyOctal
,
}
pub
struct
Conv
{
flags
:
u32
,
width
:
Count
,
precision
:
Count
,
ty
:
Ty
,
}
pub
fn
conv_int
(
cv
:
Conv
,
i
:
int
)
->
~
str
{
let
radix
=
10
;
let
prec
=
get_int_precision
(
cv
);
let
mut
s
:
~
str
=
int_to_str_prec
(
i
,
radix
,
prec
);
if
0
<=
i
{
if
have_flag
(
cv
.flags
,
flag_sign_always
)
{
unsafe
{
str
::
unshift_char
(
&
mut
s
,
'+'
)
};
}
else
if
have_flag
(
cv
.flags
,
flag_space_for_sign
)
{
unsafe
{
str
::
unshift_char
(
&
mut
s
,
' '
)
};
}
}
return
unsafe
{
pad
(
cv
,
s
,
PadSigned
)
};
}
pub
fn
conv_uint
(
cv
:
Conv
,
u
:
uint
)
->
~
str
{
let
prec
=
get_int_precision
(
cv
);
let
mut
rs
=
match
cv
.ty
{
TyDefault
=>
uint_to_str_prec
(
u
,
10
,
prec
),
TyHexLower
=>
uint_to_str_prec
(
u
,
16
,
prec
),
TyHexUpper
=>
str
::
to_upper
(
uint_to_str_prec
(
u
,
16
,
prec
)),
TyBits
=>
uint_to_str_prec
(
u
,
2
,
prec
),
TyOctal
=>
uint_to_str_prec
(
u
,
8
,
prec
)
};
return
unsafe
{
pad
(
cv
,
rs
,
PadUnsigned
)
};
}
pub
fn
conv_bool
(
cv
:
Conv
,
b
:
bool
)
->
~
str
{
let
s
=
if
b
{
~
"true"
}
else
{
~
"false"
};
// run the boolean conversion through the string conversion logic,
// giving it the same rules for precision, etc.
return
conv_str
(
cv
,
s
);
}
pub
fn
conv_char
(
cv
:
Conv
,
c
:
char
)
->
~
str
{
let
mut
s
=
str
::
from_char
(
c
);
return
unsafe
{
pad
(
cv
,
s
,
PadNozero
)
};
}
pub
fn
conv_str
(
cv
:
Conv
,
s
:
&
str
)
->
~
str
{
// For strings, precision is the maximum characters
// displayed
let
mut
unpadded
=
match
cv
.precision
{
CountImplied
=>
s
.to_owned
(),
CountIs
(
max
)
=>
if
(
max
as
uint
)
<
str
::
char_len
(
s
)
{
str
::
substr
(
s
,
0
,
max
as
uint
)
.to_owned
()
}
else
{
s
.to_owned
()
}
};
return
unsafe
{
pad
(
cv
,
unpadded
,
PadNozero
)
};
}
pub
fn
conv_float
(
cv
:
Conv
,
f
:
float
)
->
~
str
{
let
(
to_str
,
digits
)
=
match
cv
.precision
{
CountIs
(
c
)
=>
(
float
::
to_str_exact
,
c
as
uint
),
CountImplied
=>
(
float
::
to_str_digits
,
6u
)
};
let
mut
s
=
unsafe
{
to_str
(
f
,
digits
)
};
if
0.0
<=
f
{
if
have_flag
(
cv
.flags
,
flag_sign_always
)
{
s
=
~
"+"
+
s
;
}
else
if
have_flag
(
cv
.flags
,
flag_space_for_sign
)
{
s
=
~
" "
+
s
;
}
}
return
unsafe
{
pad
(
cv
,
s
,
PadFloat
)
};
}
pub
fn
conv_poly
<
T
>
(
cv
:
Conv
,
v
:
&
T
)
->
~
str
{
let
s
=
sys
::
log_str
(
v
);
return
conv_str
(
cv
,
s
);
}
// Convert an int to string with minimum number of digits. If precision is
// 0 and num is 0 then the result is the empty string.
pub
fn
int_to_str_prec
(
num
:
int
,
radix
:
uint
,
prec
:
uint
)
->
~
str
{
return
if
num
<
0
{
~
"-"
+
uint_to_str_prec
(
-
num
as
uint
,
radix
,
prec
)
}
else
{
uint_to_str_prec
(
num
as
uint
,
radix
,
prec
)
};
}
// Convert a uint to string with a minimum number of digits. If precision
// is 0 and num is 0 then the result is the empty string. Could move this
// to uint: but it doesn't seem all that useful.
pub
fn
uint_to_str_prec
(
num
:
uint
,
radix
:
uint
,
prec
:
uint
)
->
~
str
{
return
if
prec
==
0u
&&
num
==
0u
{
~
""
}
else
{
let
s
=
uint
::
to_str_radix
(
num
,
radix
);
let
len
=
str
::
char_len
(
s
);
if
len
<
prec
{
let
diff
=
prec
-
len
;
let
pad
=
str
::
from_chars
(
vec
::
from_elem
(
diff
,
'0'
));
pad
+
s
}
else
{
s
}
};
}
pub
fn
get_int_precision
(
cv
:
Conv
)
->
uint
{
return
match
cv
.precision
{
CountIs
(
c
)
=>
c
as
uint
,
CountImplied
=>
1u
};
}
#[deriving(Eq)]
pub
enum
PadMode
{
PadSigned
,
PadUnsigned
,
PadNozero
,
PadFloat
}
pub
fn
pad
(
cv
:
Conv
,
s
:
~
str
,
mode
:
PadMode
)
->
~
str
{
let
mut
s
=
s
;
// sadtimes
let
uwidth
:
uint
=
match
cv
.width
{
CountImplied
=>
return
(
s
),
CountIs
(
width
)
=>
{
width
as
uint
}
};
let
strlen
=
str
::
char_len
(
s
);
if
uwidth
<=
strlen
{
return
(
s
);
}
let
mut
padchar
=
' '
;
let
diff
=
uwidth
-
strlen
;
if
have_flag
(
cv
.flags
,
flag_left_justify
)
{
let
padstr
=
str
::
from_chars
(
vec
::
from_elem
(
diff
,
padchar
));
return
s
+
padstr
;
}
let
(
might_zero_pad
,
signed
)
=
match
mode
{
PadNozero
=>
(
false
,
true
),
PadSigned
=>
(
true
,
true
),
PadFloat
=>
(
true
,
true
),
PadUnsigned
=>
(
true
,
false
)
};
fn
have_precision
(
cv
:
Conv
)
->
bool
{
return
match
cv
.precision
{
CountImplied
=>
false
,
_
=>
true
};
}
let
zero_padding
=
{
if
might_zero_pad
&&
have_flag
(
cv
.flags
,
flag_left_zero_pad
)
&&
(
!
have_precision
(
cv
)
||
mode
==
PadFloat
)
{
padchar
=
'0'
;
true
}
else
{
false
}
};
let
padstr
=
str
::
from_chars
(
vec
::
from_elem
(
diff
,
padchar
));
// This is completely heinous. If we have a signed value then
// potentially rip apart the intermediate result and insert some
// zeros. It may make sense to convert zero padding to a precision
// instead.
if
signed
&&
zero_padding
&&
s
.len
()
>
0
{
let
head
=
str
::
shift_char
(
&
mut
s
);
if
head
==
'+'
||
head
==
'-'
||
head
==
' '
{
let
headstr
=
str
::
from_chars
(
vec
::
from_elem
(
1u
,
head
));
return
headstr
+
padstr
+
s
;
}
else
{
str
::
unshift_char
(
&
mut
s
,
head
);
}
}
return
padstr
+
s
;
}
pub
fn
have_flag
(
flags
:
u32
,
f
:
u32
)
->
bool
{
flags
&
f
!=
0
}
}
// Bulk of the tests are in src/test/run-pass/syntax-extension-fmt.rs
#[cfg(test)]
mod
test
{
...
...
src/snapshots.txt
浏览文件 @
e16f94f6
S 2013-03-27 8c15409
macos-x86_64 05eb3801b60056d95715c891d00c5d372e34d00c
macos-i386 4119e3fa614fa86adf60ed0183d00db3ce6d0dbc
linux-x86_64 e9308bade0e068bca4abe59ef4afe8c8bb7c134d
linux-i386 bcb30ed1817df1a07588cde2fb0ccaf9ffad7efb
winnt-i386 a16d409465e125bc6f779b45821ae1ea276c6bd4
freebsd-x86_64 348192f348f03541549f4e2c97af78901d59ca6e
S 2013-03-21 ed25a67
freebsd-x86_64 5f0b08839ae3d1207808f0d57cbfdb00eff9c883
linux-i386 54765a17c6b6d04a7013cada2a51d190462979b8
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录