Skip to content

Commit 23deed1

Browse files
committed
Merge pull request #3269 from killerswan/modes3
Remove deprecated modes from libstd/time.rs
2 parents c284b8b + 2dc9be7 commit 23deed1

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/libstd/time.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[forbid(deprecated_mode)];
2+
#[forbid(deprecated_pattern)];
3+
14
import libc::{c_char, c_int, c_long, size_t, time_t};
25
import io::Reader;
36
import result::{result, ok, err};
@@ -128,7 +131,7 @@ fn now() -> tm {
128131
}
129132

130133
/// Parses the time from the string according to the format string.
131-
fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
134+
fn strptime(s: &str, format: &str) -> result<tm, ~str> {
132135
type tm_mut = {
133136
mut tm_sec: i32,
134137
mut tm_min: i32,
@@ -144,7 +147,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
144147
mut tm_nsec: i32,
145148
};
146149

147-
fn match_str(s: ~str, pos: uint, needle: ~str) -> bool {
150+
fn match_str(s: &str, pos: uint, needle: &str) -> bool {
148151
let mut i = pos;
149152
for str::each(needle) |ch| {
150153
if s[i] != ch {
@@ -155,14 +158,14 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
155158
return true;
156159
}
157160

158-
fn match_strs(s: ~str, pos: uint, strs: ~[(~str, i32)])
161+
fn match_strs(ss: &str, pos: uint, strs: &[(~str, i32)])
159162
-> option<(i32, uint)> {
160163
let mut i = 0u;
161164
let len = vec::len(strs);
162165
while i < len {
163166
let (needle, value) = strs[i];
164167

165-
if match_str(s, pos, needle) {
168+
if match_str(ss, pos, needle) {
166169
return some((value, pos + str::len(needle)));
167170
}
168171
i += 1u;
@@ -171,14 +174,14 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
171174
none
172175
}
173176

174-
fn match_digits(s: ~str, pos: uint, digits: uint, ws: bool)
177+
fn match_digits(ss: &str, pos: uint, digits: uint, ws: bool)
175178
-> option<(i32, uint)> {
176179
let mut pos = pos;
177180
let mut value = 0_i32;
178181

179182
let mut i = 0u;
180183
while i < digits {
181-
let {ch, next} = str::char_range_at(s, pos);
184+
let {ch, next} = str::char_range_at(str::from_slice(ss), pos);
182185
pos = next;
183186

184187
match ch {
@@ -194,7 +197,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
194197
some((value, pos))
195198
}
196199

197-
fn parse_char(s: ~str, pos: uint, c: char) -> result<uint, ~str> {
200+
fn parse_char(s: &str, pos: uint, c: char) -> result<uint, ~str> {
198201
let {ch, next} = str::char_range_at(s, pos);
199202

200203
if c == ch {
@@ -206,7 +209,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
206209
}
207210
}
208211

209-
fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut)
212+
fn parse_type(s: &str, pos: uint, ch: char, tm: &tm_mut)
210213
-> result<uint, ~str> {
211214
match ch {
212215
'A' => match match_strs(s, pos, ~[
@@ -516,7 +519,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
516519
}
517520
}
518521

519-
do io::with_str_reader(format) |rdr| {
522+
do io::with_str_reader(str::from_slice(format)) |rdr| {
520523
let tm = {
521524
mut tm_sec: 0_i32,
522525
mut tm_min: 0_i32,
@@ -539,7 +542,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
539542
let {ch, next} = str::char_range_at(s, pos);
540543

541544
match rdr.read_char() {
542-
'%' => match parse_type(s, pos, rdr.read_char(), tm) {
545+
'%' => match parse_type(s, pos, rdr.read_char(), &tm) {
543546
ok(next) => pos = next,
544547
err(e) => { result = err(e); break; }
545548
},
@@ -569,8 +572,8 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
569572
}
570573
}
571574

572-
fn strftime(format: ~str, tm: tm) -> ~str {
573-
fn parse_type(ch: char, tm: tm) -> ~str {
575+
fn strftime(format: &str, +tm: tm) -> ~str {
576+
fn parse_type(ch: char, tm: &tm) -> ~str {
574577
//FIXME (#2350): Implement missing types.
575578
let die = || #fmt("strftime: can't understand this format %c ",
576579
ch);
@@ -725,10 +728,10 @@ fn strftime(format: ~str, tm: tm) -> ~str {
725728
726729
let mut buf = ~"";
727730

728-
do io::with_str_reader(format) |rdr| {
731+
do io::with_str_reader(str::from_slice(format)) |rdr| {
729732
while !rdr.eof() {
730733
match rdr.read_char() {
731-
'%' => buf += parse_type(rdr.read_char(), tm),
734+
'%' => buf += parse_type(rdr.read_char(), &tm),
732735
ch => str::push_char(buf, ch)
733736
}
734737
}
@@ -766,7 +769,7 @@ impl tm {
766769
fn ctime() -> ~str { self.strftime(~"%c") }
767770
768771
/// Formats the time according to the format string.
769-
fn strftime(format: ~str) -> ~str { strftime(format, self) }
772+
fn strftime(format: &str) -> ~str { strftime(format, self) }
770773
771774
/**
772775
* Returns a time string formatted according to RFC 822.
@@ -983,9 +986,9 @@ mod tests {
983986
}
984987
}
985988

986-
fn test(s: ~str, format: ~str) -> bool {
989+
fn test(s: &str, format: &str) -> bool {
987990
match strptime(s, format) {
988-
ok(tm) => tm.strftime(format) == s,
991+
ok(tm) => tm.strftime(format) == str::from_slice(s),
989992
err(e) => fail e
990993
}
991994
}

0 commit comments

Comments
 (0)