back-renamed slice_DBG_BRWD, slice_V_DBG_BRWD -> slice, slice_DBG_UNIQ -> slice_unique
This commit is contained in:
parent
8f4448837b
commit
9d9a209e9a
32 changed files with 124 additions and 124 deletions
|
@ -50,7 +50,7 @@ pub pure fn from_bytes(vv: &[const u8]) -> ~str {
|
|||
|
||||
/// Copy a slice into a new unique str
|
||||
pub pure fn from_slice(s: &str) -> ~str {
|
||||
unsafe { raw::slice_DBG_UNIQ_bytes(s, 0, len(s)) }
|
||||
unsafe { raw::slice_bytes_unique(s, 0, len(s)) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -265,7 +265,7 @@ pub fn pop_char(s: &mut ~str) -> char {
|
|||
*/
|
||||
pub fn shift_char(s: &mut ~str) -> char {
|
||||
let CharRange {ch, next} = char_range_at(*s, 0u);
|
||||
*s = unsafe { raw::slice_DBG_UNIQ_bytes(*s, next, len(*s)) };
|
||||
*s = unsafe { raw::slice_bytes_unique(*s, next, len(*s)) };
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ pub fn shift_char(s: &mut ~str) -> char {
|
|||
#[inline]
|
||||
pub fn slice_shift_char(s: &'a str) -> (char, &'a str) {
|
||||
let CharRange {ch, next} = char_range_at(s, 0u);
|
||||
let next_s = unsafe { raw::slice_DBG_BRWD_bytes(s, next, len(s)) };
|
||||
let next_s = unsafe { raw::slice_bytes(s, next, len(s)) };
|
||||
return (ch, next_s);
|
||||
}
|
||||
|
||||
|
@ -304,7 +304,7 @@ pub pure fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str {
|
|||
|
||||
match find(s, |c| !chars_to_trim.contains(&c)) {
|
||||
None => ~"",
|
||||
Some(first) => unsafe { raw::slice_DBG_UNIQ_bytes(s, first, s.len()) }
|
||||
Some(first) => unsafe { raw::slice_bytes_unique(s, first, s.len()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ pub pure fn trim_right_chars(s: &str, chars_to_trim: &[char]) -> ~str {
|
|||
None => ~"",
|
||||
Some(last) => {
|
||||
let next = char_range_at(s, last).next;
|
||||
unsafe { raw::slice_DBG_UNIQ_bytes(s, 0u, next) }
|
||||
unsafe { raw::slice_bytes_unique(s, 0u, next) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ pub pure fn trim_chars(s: &str, chars_to_trim: &[char]) -> ~str {
|
|||
pub pure fn trim_left(s: &str) -> ~str {
|
||||
match find(s, |c| !char::is_whitespace(c)) {
|
||||
None => ~"",
|
||||
Some(first) => unsafe { raw::slice_DBG_UNIQ_bytes(s, first, len(s)) }
|
||||
Some(first) => unsafe { raw::slice_bytes_unique(s, first, len(s)) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ pub pure fn trim_right(s: &str) -> ~str {
|
|||
None => ~"",
|
||||
Some(last) => {
|
||||
let next = char_range_at(s, last).next;
|
||||
unsafe { raw::slice_DBG_UNIQ_bytes(s, 0u, next) }
|
||||
unsafe { raw::slice_bytes_unique(s, 0u, next) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ pub pure fn chars(s: &str) -> ~[char] {
|
|||
* `begin`.
|
||||
*/
|
||||
pub pure fn substr(s: &str, begin: uint, n: uint) -> ~str {
|
||||
slice_DBG_BRWD(s, begin, begin + count_bytes(s, begin, n)).to_owned()
|
||||
slice(s, begin, begin + count_bytes(s, begin, n)).to_owned()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -417,10 +417,10 @@ pub pure fn substr(s: &str, begin: uint, n: uint) -> ~str {
|
|||
* Fails when `begin` and `end` do not point to valid characters or beyond
|
||||
* the last character of the string
|
||||
*/
|
||||
pub pure fn slice_DBG_BRWD(s: &'a str, begin: uint, end: uint) -> &'a str {
|
||||
pub pure fn slice(s: &'a str, begin: uint, end: uint) -> &'a str {
|
||||
fail_unless!(is_char_boundary(s, begin));
|
||||
fail_unless!(is_char_boundary(s, end));
|
||||
unsafe { raw::slice_DBG_BRWD_bytes(s, begin, end) }
|
||||
unsafe { raw::slice_bytes(s, begin, end) }
|
||||
}
|
||||
|
||||
/// Splits a string into substrings at each occurrence of a given character
|
||||
|
@ -453,7 +453,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
|
|||
if s[i] == b {
|
||||
if allow_empty || start < i {
|
||||
unsafe {
|
||||
result.push(raw::slice_DBG_UNIQ_bytes(s, start, i));
|
||||
result.push(raw::slice_bytes_unique(s, start, i));
|
||||
}
|
||||
}
|
||||
start = i + 1u;
|
||||
|
@ -462,7 +462,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
|
|||
i += 1u;
|
||||
}
|
||||
if allow_empty || start < l {
|
||||
unsafe { result.push(raw::slice_DBG_UNIQ_bytes(s, start, l) ) };
|
||||
unsafe { result.push(raw::slice_bytes_unique(s, start, l) ) };
|
||||
}
|
||||
result
|
||||
} else {
|
||||
|
@ -501,7 +501,7 @@ pure fn split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint,
|
|||
if sepfn(ch) {
|
||||
if allow_empty || start < i {
|
||||
unsafe {
|
||||
result.push(raw::slice_DBG_UNIQ_bytes(s, start, i));
|
||||
result.push(raw::slice_bytes_unique(s, start, i));
|
||||
}
|
||||
}
|
||||
start = next;
|
||||
|
@ -511,7 +511,7 @@ pure fn split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint,
|
|||
}
|
||||
if allow_empty || start < l {
|
||||
unsafe {
|
||||
result.push(raw::slice_DBG_UNIQ_bytes(s, start, l));
|
||||
result.push(raw::slice_bytes_unique(s, start, l));
|
||||
}
|
||||
}
|
||||
result
|
||||
|
@ -566,7 +566,7 @@ pure fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) {
|
|||
pub pure fn split_str(s: &'a str, sep: &'b str) -> ~[~str] {
|
||||
let mut result = ~[];
|
||||
do iter_between_matches(s, sep) |from, to| {
|
||||
unsafe { result.push(raw::slice_DBG_UNIQ_bytes(s, from, to)); }
|
||||
unsafe { result.push(raw::slice_bytes_unique(s, from, to)); }
|
||||
}
|
||||
result
|
||||
}
|
||||
|
@ -575,7 +575,7 @@ pub pure fn split_str_nonempty(s: &'a str, sep: &'b str) -> ~[~str] {
|
|||
let mut result = ~[];
|
||||
do iter_between_matches(s, sep) |from, to| {
|
||||
if to > from {
|
||||
unsafe { result.push(raw::slice_DBG_UNIQ_bytes(s, from, to)); }
|
||||
unsafe { result.push(raw::slice_bytes_unique(s, from, to)); }
|
||||
}
|
||||
}
|
||||
result
|
||||
|
@ -709,7 +709,7 @@ pub pure fn replace(s: &str, from: &str, to: &str) -> ~str {
|
|||
} else {
|
||||
unsafe { push_str(&mut result, to); }
|
||||
}
|
||||
unsafe { push_str(&mut result, raw::slice_DBG_UNIQ_bytes(s, start, end)); }
|
||||
unsafe { push_str(&mut result, raw::slice_bytes_unique(s, start, end)); }
|
||||
}
|
||||
result
|
||||
}
|
||||
|
@ -2123,7 +2123,7 @@ pub mod raw {
|
|||
* If begin is greater than end.
|
||||
* If end is greater than the length of the string.
|
||||
*/
|
||||
pub unsafe fn slice_DBG_UNIQ_bytes(s: &str, begin: uint, end: uint) -> ~str {
|
||||
pub unsafe fn slice_bytes_unique(s: &str, begin: uint, end: uint) -> ~str {
|
||||
do as_buf(s) |sbuf, n| {
|
||||
fail_unless!((begin <= end));
|
||||
fail_unless!((end <= n));
|
||||
|
@ -2153,7 +2153,7 @@ pub mod raw {
|
|||
* If end is greater than the length of the string.
|
||||
*/
|
||||
#[inline]
|
||||
pub unsafe fn slice_DBG_BRWD_bytes(s: &str, begin: uint, end: uint) -> &str {
|
||||
pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str {
|
||||
do as_buf(s) |sbuf, n| {
|
||||
fail_unless!((begin <= end));
|
||||
fail_unless!((end <= n));
|
||||
|
@ -2195,7 +2195,7 @@ pub mod raw {
|
|||
let len = len(*s);
|
||||
fail_unless!((len > 0u));
|
||||
let b = s[0];
|
||||
*s = unsafe { raw::slice_DBG_UNIQ_bytes(*s, 1u, len) };
|
||||
*s = unsafe { raw::slice_bytes_unique(*s, 1u, len) };
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -2275,7 +2275,7 @@ pub trait StrSlice {
|
|||
pure fn is_alphanumeric(&self) -> bool;
|
||||
pure fn len(&self) -> uint;
|
||||
pure fn char_len(&self) -> uint;
|
||||
pure fn slice_DBG_BRWD(&self, begin: uint, end: uint) -> &'self str;
|
||||
pure fn slice(&self, begin: uint, end: uint) -> &'self str;
|
||||
pure fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str];
|
||||
pure fn split_char(&self, sep: char) -> ~[~str];
|
||||
pure fn split_str(&self, sep: &'a str) -> ~[~str];
|
||||
|
@ -2390,8 +2390,8 @@ impl StrSlice for &'self str {
|
|||
* beyond the last character of the string
|
||||
*/
|
||||
#[inline]
|
||||
pure fn slice_DBG_BRWD(&self, begin: uint, end: uint) -> &'self str {
|
||||
slice_DBG_BRWD(*self, begin, end)
|
||||
pure fn slice(&self, begin: uint, end: uint) -> &'self str {
|
||||
slice(*self, begin, end)
|
||||
}
|
||||
/// Splits a string into substrings using a character function
|
||||
#[inline]
|
||||
|
@ -2511,8 +2511,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_eq_slice() {
|
||||
fail_unless!((eq_slice(slice_DBG_BRWD("foobar", 0, 3), "foo")));
|
||||
fail_unless!((eq_slice(slice_DBG_BRWD("barfoo", 3, 6), "foo")));
|
||||
fail_unless!((eq_slice(slice("foobar", 0, 3), "foo")));
|
||||
fail_unless!((eq_slice(slice("barfoo", 3, 6), "foo")));
|
||||
fail_unless!((!eq_slice("foo1", "foo2")));
|
||||
}
|
||||
|
||||
|
@ -2879,9 +2879,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_unsafe_slice() {
|
||||
fail_unless!("ab" == unsafe {raw::slice_DBG_BRWD_bytes("abc", 0, 2)});
|
||||
fail_unless!("bc" == unsafe {raw::slice_DBG_BRWD_bytes("abc", 1, 3)});
|
||||
fail_unless!("" == unsafe {raw::slice_DBG_BRWD_bytes("abc", 1, 1)});
|
||||
fail_unless!("ab" == unsafe {raw::slice_bytes("abc", 0, 2)});
|
||||
fail_unless!("bc" == unsafe {raw::slice_bytes("abc", 1, 3)});
|
||||
fail_unless!("" == unsafe {raw::slice_bytes("abc", 1, 1)});
|
||||
fn a_million_letter_a() -> ~str {
|
||||
let mut i = 0;
|
||||
let mut rs = ~"";
|
||||
|
@ -2896,7 +2896,7 @@ mod tests {
|
|||
}
|
||||
let letters = a_million_letter_a();
|
||||
fail_unless!(half_a_million_letter_a() ==
|
||||
unsafe {raw::slice_DBG_BRWD_bytes(letters, 0u, 500000)}.to_owned());
|
||||
unsafe {raw::slice_bytes(letters, 0u, 500000)}.to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2976,16 +2976,16 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_slice() {
|
||||
fail_unless!("ab" == slice_DBG_BRWD("abc", 0, 2));
|
||||
fail_unless!("bc" == slice_DBG_BRWD("abc", 1, 3));
|
||||
fail_unless!("" == slice_DBG_BRWD("abc", 1, 1));
|
||||
fail_unless!("\u65e5" == slice_DBG_BRWD("\u65e5\u672c", 0, 3));
|
||||
fail_unless!("ab" == slice("abc", 0, 2));
|
||||
fail_unless!("bc" == slice("abc", 1, 3));
|
||||
fail_unless!("" == slice("abc", 1, 1));
|
||||
fail_unless!("\u65e5" == slice("\u65e5\u672c", 0, 3));
|
||||
|
||||
let data = "ประเทศไทย中华";
|
||||
fail_unless!("ป" == slice_DBG_BRWD(data, 0, 3));
|
||||
fail_unless!("ร" == slice_DBG_BRWD(data, 3, 6));
|
||||
fail_unless!("" == slice_DBG_BRWD(data, 3, 3));
|
||||
fail_unless!("华" == slice_DBG_BRWD(data, 30, 33));
|
||||
fail_unless!("ป" == slice(data, 0, 3));
|
||||
fail_unless!("ร" == slice(data, 3, 6));
|
||||
fail_unless!("" == slice(data, 3, 3));
|
||||
fail_unless!("华" == slice(data, 30, 33));
|
||||
|
||||
fn a_million_letter_X() -> ~str {
|
||||
let mut i = 0;
|
||||
|
@ -3004,23 +3004,23 @@ mod tests {
|
|||
}
|
||||
let letters = a_million_letter_X();
|
||||
fail_unless!(half_a_million_letter_X() ==
|
||||
slice_DBG_BRWD(letters, 0u, 3u * 500000u).to_owned());
|
||||
slice(letters, 0u, 3u * 500000u).to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_slice_2() {
|
||||
let ss = "中华Việt Nam";
|
||||
|
||||
fail_unless!("华" == slice_DBG_BRWD(ss, 3u, 6u));
|
||||
fail_unless!("Việt Nam" == slice_DBG_BRWD(ss, 6u, 16u));
|
||||
fail_unless!("华" == slice(ss, 3u, 6u));
|
||||
fail_unless!("Việt Nam" == slice(ss, 6u, 16u));
|
||||
|
||||
fail_unless!("ab" == slice_DBG_BRWD("abc", 0u, 2u));
|
||||
fail_unless!("bc" == slice_DBG_BRWD("abc", 1u, 3u));
|
||||
fail_unless!("" == slice_DBG_BRWD("abc", 1u, 1u));
|
||||
fail_unless!("ab" == slice("abc", 0u, 2u));
|
||||
fail_unless!("bc" == slice("abc", 1u, 3u));
|
||||
fail_unless!("" == slice("abc", 1u, 1u));
|
||||
|
||||
fail_unless!("中" == slice_DBG_BRWD(ss, 0u, 3u));
|
||||
fail_unless!("华V" == slice_DBG_BRWD(ss, 3u, 7u));
|
||||
fail_unless!("" == slice_DBG_BRWD(ss, 3u, 3u));
|
||||
fail_unless!("中" == slice(ss, 0u, 3u));
|
||||
fail_unless!("华V" == slice(ss, 3u, 7u));
|
||||
fail_unless!("" == slice(ss, 3u, 3u));
|
||||
/*0: 中
|
||||
3: 华
|
||||
6: V
|
||||
|
@ -3037,7 +3037,7 @@ mod tests {
|
|||
#[should_fail]
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_slice_fail() {
|
||||
slice_DBG_BRWD("中华Việt Nam", 0u, 2u);
|
||||
slice("中华Việt Nam", 0u, 2u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3633,7 +3633,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_to_managed() {
|
||||
fail_unless!((~"abc").to_managed() == @"abc");
|
||||
fail_unless!(slice_DBG_BRWD("abcdef", 1, 5).to_managed() == @"bcde");
|
||||
fail_unless!(slice("abcdef", 1, 5).to_managed() == @"bcde");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue