@@ -19,37 +19,38 @@ export abs;
19
19
export parse_bytes, from_str, to_str, to_str_bytes, str;
20
20
export num, ord, eq, times, timesi;
21
21
export bits, bytes;
22
+ export str;
22
23
23
- const bits : uint = inst:: bits;
24
- const bytes : uint = ( inst:: bits / 8 ) ;
24
+ pub const bits : uint = inst:: bits;
25
+ pub const bytes : uint = ( inst:: bits / 8 ) ;
25
26
26
- const min_value: T = ( -1 as T ) << ( bits - 1 ) ;
27
- const max_value: T = min_value - 1 as T ;
27
+ pub const min_value: T = ( -1 as T ) << ( bits - 1 ) ;
28
+ pub const max_value: T = min_value - 1 as T ;
28
29
29
- pure fn min ( x : T , y : T ) -> T { if x < y { x } else { y } }
30
- pure fn max ( x : T , y : T ) -> T { if x > y { x } else { y } }
30
+ pub pure fn min ( x : T , y : T ) -> T { if x < y { x } else { y } }
31
+ pub pure fn max ( x : T , y : T ) -> T { if x > y { x } else { y } }
31
32
32
- pure fn add ( x : T , y : T ) -> T { x + y }
33
- pure fn sub ( x : T , y : T ) -> T { x - y }
34
- pure fn mul ( x : T , y : T ) -> T { x * y }
35
- pure fn div ( x : T , y : T ) -> T { x / y }
36
- pure fn rem ( x : T , y : T ) -> T { x % y }
33
+ pub pure fn add ( x : T , y : T ) -> T { x + y }
34
+ pub pure fn sub ( x : T , y : T ) -> T { x - y }
35
+ pub pure fn mul ( x : T , y : T ) -> T { x * y }
36
+ pub pure fn div ( x : T , y : T ) -> T { x / y }
37
+ pub pure fn rem ( x : T , y : T ) -> T { x % y }
37
38
38
- pure fn lt ( x : T , y : T ) -> bool { x < y }
39
- pure fn le ( x : T , y : T ) -> bool { x <= y }
40
- pure fn eq ( x : T , y : T ) -> bool { x == y }
41
- pure fn ne ( x : T , y : T ) -> bool { x != y }
42
- pure fn ge ( x : T , y : T ) -> bool { x >= y }
43
- pure fn gt ( x : T , y : T ) -> bool { x > y }
39
+ pub pure fn lt ( x : T , y : T ) -> bool { x < y }
40
+ pub pure fn le ( x : T , y : T ) -> bool { x <= y }
41
+ pub pure fn eq ( x : T , y : T ) -> bool { x == y }
42
+ pub pure fn ne ( x : T , y : T ) -> bool { x != y }
43
+ pub pure fn ge ( x : T , y : T ) -> bool { x >= y }
44
+ pub pure fn gt ( x : T , y : T ) -> bool { x > y }
44
45
45
- pure fn is_positive ( x : T ) -> bool { x > 0 as T }
46
- pure fn is_negative ( x : T ) -> bool { x < 0 as T }
47
- pure fn is_nonpositive ( x : T ) -> bool { x <= 0 as T }
48
- pure fn is_nonnegative ( x : T ) -> bool { x >= 0 as T }
46
+ pub pure fn is_positive ( x : T ) -> bool { x > 0 as T }
47
+ pub pure fn is_negative ( x : T ) -> bool { x < 0 as T }
48
+ pub pure fn is_nonpositive ( x : T ) -> bool { x <= 0 as T }
49
+ pub pure fn is_nonnegative ( x : T ) -> bool { x >= 0 as T }
49
50
50
51
#[ inline( always) ]
51
52
/// Iterate over the range [`lo`..`hi`)
52
- fn range ( lo : T , hi : T , it : fn ( T ) -> bool ) {
53
+ pub fn range ( lo : T , hi : T , it : fn ( T ) -> bool ) {
53
54
let mut i = lo;
54
55
while i < hi {
55
56
if !it ( i) { break }
@@ -58,13 +59,13 @@ fn range(lo: T, hi: T, it: fn(T) -> bool) {
58
59
}
59
60
60
61
/// Computes the bitwise complement
61
- pure fn compl ( i : T ) -> T {
62
+ pub pure fn compl ( i : T ) -> T {
62
63
-1 as T ^ i
63
64
}
64
65
65
66
/// Computes the absolute value
66
67
// FIXME: abs should return an unsigned int (#2353)
67
- pure fn abs ( i : T ) -> T {
68
+ pub pure fn abs ( i : T ) -> T {
68
69
if is_negative ( i) { -i } else { i }
69
70
}
70
71
@@ -137,7 +138,7 @@ impl T: iter::TimesIx {
137
138
* * buf - A byte buffer
138
139
* * radix - The base of the number
139
140
*/
140
- fn parse_bytes ( buf : & [ u8 ] , radix : uint ) -> Option < T > {
141
+ pub fn parse_bytes ( buf : & [ u8 ] , radix : uint ) -> Option < T > {
141
142
if vec:: len ( buf) == 0 u { return None ; }
142
143
let mut i = vec:: len ( buf) - 1 u;
143
144
let mut start = 0 u;
@@ -160,22 +161,22 @@ fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
160
161
}
161
162
162
163
/// Parse a string to an int
163
- fn from_str ( s : & str ) -> Option < T > { parse_bytes ( str:: to_bytes ( s) , 10 u) }
164
+ pub fn from_str ( s : & str ) -> Option < T > { parse_bytes ( str:: to_bytes ( s) , 10 u) }
164
165
165
166
impl T : FromStr {
166
167
static fn from_str( s : & str ) -> Option < T > { from_str( s ) }
167
168
}
168
169
169
170
/// Convert to a string in a given base
170
- fn to_str ( n : T , radix : uint ) -> ~str {
171
+ pub fn to_str ( n : T , radix : uint ) -> ~str {
171
172
do to_str_bytes ( n, radix) |slice| {
172
173
do vec:: as_imm_buf ( slice) |p, len| {
173
174
unsafe { str:: raw:: from_buf_len ( p, len) }
174
175
}
175
176
}
176
177
}
177
178
178
- fn to_str_bytes < U > ( n : T , radix : uint , f : fn ( v : & [ u8 ] ) -> U ) -> U {
179
+ pub fn to_str_bytes < U > ( n : T , radix : uint , f : fn ( v : & [ u8 ] ) -> U ) -> U {
179
180
if n < 0 as T {
180
181
uint:: to_str_bytes ( true , -n as uint , radix, f)
181
182
} else {
@@ -184,12 +185,12 @@ fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
184
185
}
185
186
186
187
/// Convert to a string
187
- fn str ( i : T ) -> ~str { return to_str ( i, 10 u) ; }
188
+ pub fn str ( i : T ) -> ~str { return to_str ( i, 10 u) ; }
188
189
189
190
// FIXME: Has alignment issues on windows and 32-bit linux (#2609)
190
191
#[ test]
191
192
#[ ignore]
192
- fn test_from_str ( ) {
193
+ pub fn test_from_str ( ) {
193
194
assert from_str ( ~"0 ") == Some ( 0 as T ) ;
194
195
assert from_str ( ~"3 ") == Some ( 3 as T ) ;
195
196
assert from_str ( ~"10 ") == Some ( 10 as T ) ;
@@ -209,7 +210,7 @@ fn test_from_str() {
209
210
// FIXME: Has alignment issues on windows and 32-bit linux (#2609)
210
211
#[ test]
211
212
#[ ignore]
212
- fn test_parse_bytes ( ) {
213
+ pub fn test_parse_bytes ( ) {
213
214
use str:: to_bytes;
214
215
assert parse_bytes ( to_bytes ( ~"123 ") , 10 u) == Some ( 123 as T ) ;
215
216
assert parse_bytes ( to_bytes ( ~"1001 ") , 2 u) == Some ( 9 as T ) ;
@@ -234,7 +235,7 @@ fn test_parse_bytes() {
234
235
}
235
236
236
237
#[ test]
237
- fn test_to_str ( ) {
238
+ pub fn test_to_str ( ) {
238
239
assert ( to_str ( 0 as T , 10 u) == ~"0 ") ;
239
240
assert ( to_str ( 1 as T , 10 u) == ~"1 ") ;
240
241
assert ( to_str ( -1 as T , 10 u) == ~"-1 ") ;
@@ -243,7 +244,7 @@ fn test_to_str() {
243
244
}
244
245
245
246
#[ test]
246
- fn test_interfaces ( ) {
247
+ pub fn test_interfaces ( ) {
247
248
fn test < U : num:: Num cmp:: Eq > ( +ten : U ) {
248
249
assert ( ten. to_int ( ) == 10 ) ;
249
250
@@ -262,7 +263,7 @@ fn test_interfaces() {
262
263
}
263
264
264
265
#[ test]
265
- fn test_times ( ) {
266
+ pub fn test_times ( ) {
266
267
use iter:: Times ;
267
268
let ten = 10 as T ;
268
269
let mut accum = 0 ;
@@ -273,7 +274,7 @@ fn test_times() {
273
274
#[ test]
274
275
#[ should_fail]
275
276
#[ ignore( cfg( windows) ) ]
276
- fn test_times_negative ( ) {
277
+ pub fn test_times_negative ( ) {
277
278
use iter:: Times ;
278
279
for ( -10 ) . times { log( error, ~"nope!") ; }
279
280
}
0 commit comments