2010-06-23 23:03:09 -05:00
|
|
|
import rustrt.sbuf;
|
|
|
|
|
|
|
|
native "rust" mod rustrt {
|
|
|
|
type sbuf;
|
|
|
|
fn str_buf(str s) -> sbuf;
|
|
|
|
fn str_len(str s) -> uint;
|
2010-07-05 16:42:12 -05:00
|
|
|
fn str_alloc(uint n_bytes) -> str;
|
2010-07-13 16:23:49 -05:00
|
|
|
fn refcount[T](str s) -> uint;
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_utf8(vec[u8] v) -> bool {
|
2010-07-16 17:33:30 -05:00
|
|
|
fail; // FIXME
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
2010-08-05 01:09:25 -05:00
|
|
|
fn is_ascii(str s) -> bool {
|
|
|
|
let uint i = len(s);
|
|
|
|
while (i > 0u) {
|
|
|
|
i -= 1u;
|
2010-08-05 12:10:39 -05:00
|
|
|
if ((s.(i) & 0x80u8) != 0u8) {
|
2010-08-05 01:09:25 -05:00
|
|
|
ret false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret true;
|
|
|
|
}
|
|
|
|
|
2010-07-05 16:42:12 -05:00
|
|
|
fn alloc(uint n_bytes) -> str {
|
2010-06-23 23:03:09 -05:00
|
|
|
ret rustrt.str_alloc(n_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn len(str s) -> uint {
|
|
|
|
ret rustrt.str_len(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn buf(str s) -> sbuf {
|
|
|
|
ret rustrt.str_buf(s);
|
|
|
|
}
|
2010-08-05 01:09:25 -05:00
|
|
|
|
|
|
|
fn bytes(&str s) -> vec[u8] {
|
|
|
|
fn ith(str s, uint i) -> u8 {
|
2010-08-05 12:10:39 -05:00
|
|
|
ret s.(i);
|
2010-08-05 01:09:25 -05:00
|
|
|
}
|
|
|
|
ret _vec.init_fn[u8](bind ith(s, _), _str.len(s));
|
|
|
|
}
|