2012-12-10 19:32:48 -06:00
|
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
2012-09-11 19:46:20 -05:00
|
|
|
|
extern mod std;
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
|
pub fn main() {
|
2011-07-27 07:19:39 -05:00
|
|
|
|
// Chars of 1, 2, 3, and 4 bytes
|
2012-06-29 18:26:56 -05:00
|
|
|
|
let chs: ~[char] = ~['e', 'é', '€', 0x10000 as char];
|
2012-07-14 00:57:48 -05:00
|
|
|
|
let s: ~str = str::from_chars(chs);
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2012-02-23 03:44:04 -06:00
|
|
|
|
assert (str::len(s) == 10u);
|
2012-02-23 09:59:30 -06:00
|
|
|
|
assert (str::char_len(s) == 4u);
|
|
|
|
|
assert (vec::len(str::chars(s)) == 4u);
|
2012-08-02 17:42:56 -05:00
|
|
|
|
assert (str::from_chars(str::chars(s)) == s);
|
2011-09-01 19:27:58 -05:00
|
|
|
|
assert (str::char_at(s, 0u) == 'e');
|
|
|
|
|
assert (str::char_at(s, 1u) == 'é');
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2012-08-23 17:44:57 -05:00
|
|
|
|
assert (str::is_utf8(str::to_bytes(s)));
|
2012-06-29 18:26:56 -05:00
|
|
|
|
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
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
|
let mut stack = ~"a×c€";
|
2012-09-21 20:36:32 -05:00
|
|
|
|
assert (str::pop_char(&mut stack) == '€');
|
|
|
|
|
assert (str::pop_char(&mut stack) == 'c');
|
|
|
|
|
str::push_char(&mut stack, 'u');
|
2012-08-02 17:42:56 -05:00
|
|
|
|
assert (stack == ~"a×u");
|
2012-09-21 20:36:32 -05:00
|
|
|
|
assert (str::shift_char(&mut stack) == 'a');
|
|
|
|
|
assert (str::shift_char(&mut stack) == '×');
|
|
|
|
|
str::unshift_char(&mut stack, 'ß');
|
2012-08-02 17:42:56 -05:00
|
|
|
|
assert (stack == ~"ßu");
|
2011-08-10 11:27:22 -05:00
|
|
|
|
}
|