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