1
- #[ forbid( deprecated_mode) ] ;
2
- #[ forbid( deprecated_pattern) ] ;
3
-
4
1
import libc:: { c_char, c_int, c_long, size_t, time_t} ;
5
2
import io:: Reader ;
6
3
import result:: { result, ok, err} ;
@@ -131,7 +128,7 @@ fn now() -> tm {
131
128
}
132
129
133
130
/// Parses the time from the string according to the format string.
134
- fn strptime ( s : & str , format : & str ) -> result < tm , ~str > {
131
+ fn strptime ( s : ~ str , format : ~ str ) -> result < tm , ~str > {
135
132
type tm_mut = {
136
133
mut tm_sec : i32 ,
137
134
mut tm_min : i32 ,
@@ -147,7 +144,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
147
144
mut tm_nsec : i32 ,
148
145
} ;
149
146
150
- fn match_str ( s : & str , pos : uint , needle : & str ) -> bool {
147
+ fn match_str ( s : ~ str , pos : uint , needle : ~ str ) -> bool {
151
148
let mut i = pos;
152
149
for str:: each( needle) |ch| {
153
150
if s[ i] != ch {
@@ -158,14 +155,14 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
158
155
return true ;
159
156
}
160
157
161
- fn match_strs ( ss : & str , pos : uint , strs : & [ ( ~str , i32 ) ] )
158
+ fn match_strs ( s : ~ str , pos : uint , strs : ~ [ ( ~str , i32 ) ] )
162
159
-> option < ( i32 , uint ) > {
163
160
let mut i = 0 u;
164
161
let len = vec:: len ( strs) ;
165
162
while i < len {
166
163
let ( needle, value) = strs[ i] ;
167
164
168
- if match_str ( ss , pos, needle) {
165
+ if match_str ( s , pos, needle) {
169
166
return some ( ( value, pos + str:: len ( needle) ) ) ;
170
167
}
171
168
i += 1 u;
@@ -174,14 +171,14 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
174
171
none
175
172
}
176
173
177
- fn match_digits ( ss : & str , pos : uint , digits : uint , ws : bool )
174
+ fn match_digits ( s : ~ str , pos : uint , digits : uint , ws : bool )
178
175
-> option < ( i32 , uint ) > {
179
176
let mut pos = pos;
180
177
let mut value = 0_i32 ;
181
178
182
179
let mut i = 0 u;
183
180
while i < digits {
184
- let { ch, next} = str:: char_range_at ( str :: from_slice ( ss ) , pos) ;
181
+ let { ch, next} = str:: char_range_at ( s , pos) ;
185
182
pos = next;
186
183
187
184
match ch {
@@ -197,7 +194,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
197
194
some ( ( value, pos) )
198
195
}
199
196
200
- fn parse_char ( s : & str , pos : uint , c : char ) -> result < uint , ~str > {
197
+ fn parse_char ( s : ~ str , pos : uint , c : char ) -> result < uint , ~str > {
201
198
let { ch, next} = str:: char_range_at ( s, pos) ;
202
199
203
200
if c == ch {
@@ -209,7 +206,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
209
206
}
210
207
}
211
208
212
- fn parse_type ( s : & str , pos : uint , ch : char , tm : & tm_mut )
209
+ fn parse_type ( s : ~ str , pos : uint , ch : char , tm : tm_mut )
213
210
-> result < uint , ~str > {
214
211
match ch {
215
212
'A' => match match_strs ( s, pos, ~[
@@ -519,7 +516,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
519
516
}
520
517
}
521
518
522
- do io:: with_str_reader ( str :: from_slice ( format) ) |rdr| {
519
+ do io:: with_str_reader ( format) |rdr| {
523
520
let tm = {
524
521
mut tm_sec: 0_i32 ,
525
522
mut tm_min: 0_i32 ,
@@ -542,7 +539,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
542
539
let { ch, next} = str:: char_range_at ( s, pos) ;
543
540
544
541
match rdr. read_char ( ) {
545
- '%' => match parse_type ( s, pos, rdr. read_char ( ) , & tm) {
542
+ '%' => match parse_type ( s, pos, rdr. read_char ( ) , tm) {
546
543
ok( next) => pos = next,
547
544
err( e) => { result = err ( e) ; break ; }
548
545
} ,
@@ -572,8 +569,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
572
569
}
573
570
}
574
571
575
- fn strftime( format : & str , + tm : tm ) -> ~str {
576
- fn parse_type ( ch : char , tm : & tm ) -> ~str {
572
+ fn strftime( format : ~ str , tm : tm ) -> ~str {
573
+ fn parse_type ( ch : char , tm : tm ) -> ~str {
577
574
//FIXME (#2350): Implement missing types.
578
575
let die = || #fmt ( "strftime: can't understand this format %c " ,
579
576
ch) ;
@@ -728,10 +725,10 @@ fn strftime(format: &str, +tm: tm) -> ~str {
728
725
729
726
let mut buf = ~" ";
730
727
731
- do io:: with_str_reader ( str :: from_slice ( format) ) |rdr| {
728
+ do io:: with_str_reader ( format) |rdr| {
732
729
while !rdr. eof ( ) {
733
730
match rdr. read_char ( ) {
734
- '%' => buf += parse_type ( rdr. read_char ( ) , & tm) ,
731
+ '%' => buf += parse_type ( rdr. read_char ( ) , tm) ,
735
732
ch => str:: push_char ( buf, ch)
736
733
}
737
734
}
@@ -769,7 +766,7 @@ impl tm {
769
766
fn ctime( ) -> ~str { self . strftime ( ~"%c") }
770
767
771
768
/// Formats the time according to the format string.
772
- fn strftime(format: & str) -> ~str { strftime(format, self) }
769
+ fn strftime(format: ~ str) -> ~str { strftime(format, self) }
773
770
774
771
/**
775
772
* Returns a time string formatted according to RFC 822.
@@ -986,9 +983,9 @@ mod tests {
986
983
}
987
984
}
988
985
989
- fn test ( s : & str , format : & str ) -> bool {
986
+ fn test ( s : ~ str , format : ~ str ) -> bool {
990
987
match strptime ( s, format) {
991
- ok( tm) => tm. strftime ( format) == str :: from_slice ( s ) ,
988
+ ok( tm) => tm. strftime ( format) == s ,
992
989
err( e) => fail e
993
990
}
994
991
}
0 commit comments