2011-03-24 06:11:32 -05:00
|
|
|
|
use std;
|
2011-05-17 13:41:41 -05:00
|
|
|
|
import std::str;
|
|
|
|
|
import std::vec;
|
2011-05-12 10:24:54 -05:00
|
|
|
|
import std::io;
|
2011-08-11 18:36:20 -05:00
|
|
|
|
import std::ivec;
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
|
|
|
|
fn main() {
|
2011-07-27 07:19:39 -05:00
|
|
|
|
// Chars of 1, 2, 3, and 4 bytes
|
|
|
|
|
let chs: vec[char] = ['e', 'é', '€', 0x10000 as char];
|
|
|
|
|
let s: str = str::from_chars(chs);
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
|
assert (str::byte_len(s) == 10u);
|
|
|
|
|
assert (str::char_len(s) == 4u);
|
|
|
|
|
assert (vec::len[char](str::to_chars(s)) == 4u);
|
|
|
|
|
assert (str::eq(str::from_chars(str::to_chars(s)), s));
|
|
|
|
|
assert (str::char_at(s, 0u) == 'e');
|
|
|
|
|
assert (str::char_at(s, 1u) == 'é');
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2011-08-11 18:45:07 -05:00
|
|
|
|
assert (str::is_utf8(str::bytes(s)));
|
|
|
|
|
assert (!str::is_utf8(~[0x80_u8]));
|
|
|
|
|
assert (!str::is_utf8(~[0xc0_u8]));
|
|
|
|
|
assert (!str::is_utf8(~[0xc0_u8, 0x10_u8]));
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
|
let stack = "a×c€";
|
|
|
|
|
assert (str::pop_char(stack) == '€');
|
|
|
|
|
assert (str::pop_char(stack) == 'c');
|
|
|
|
|
str::push_char(stack, 'u');
|
|
|
|
|
assert (str::eq(stack, "a×u"));
|
|
|
|
|
assert (str::shift_char(stack) == 'a');
|
|
|
|
|
assert (str::shift_char(stack) == '×');
|
|
|
|
|
str::unshift_char(stack, 'ß');
|
|
|
|
|
assert (str::eq(stack, "ßu"));
|
|
|
|
|
}
|