Skip to content

Commit 6e653f4

Browse files
committed
---
yaml --- r: 56800 b: refs/heads/try c: 74807b1 h: refs/heads/master v: v3
1 parent e684294 commit 6e653f4

File tree

5 files changed

+22
-162
lines changed

5 files changed

+22
-162
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: 4ad76e66aad1813bc927ae1b5cf8205c8c5a8944
5+
refs/heads/try: 74807b15944205beb2b86ea5422927c47cac3ecc
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/str.rs

Lines changed: 8 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Section: Creating a string
3838
*/
3939

4040
/**
41-
* Convert a vector of bytes to a new UTF-8 string
41+
* Convert a vector of bytes to a UTF-8 string
4242
*
4343
* # Failure
4444
*
@@ -49,26 +49,9 @@ pub fn from_bytes(vv: &const [u8]) -> ~str {
4949
return unsafe { raw::from_bytes(vv) };
5050
}
5151

52-
/**
53-
* Convert a vector of bytes to a UTF-8 string.
54-
* The vector needs to be one byte longer than the string, and end with a 0 byte.
55-
*
56-
* Compared to `from_bytes()`, this fn doesn't need to allocate a new owned str.
57-
*
58-
* # Failure
59-
*
60-
* Fails if invalid UTF-8
61-
* Fails if not null terminated
62-
*/
63-
pub fn from_bytes_with_null<'a>(vv: &'a [u8]) -> &'a str {
64-
assert!(vv[vv.len() - 1] == 0);
65-
assert!(is_utf8(vv));
66-
return unsafe { raw::from_bytes_with_null(vv) };
67-
}
68-
6952
/// Copy a slice into a new unique str
7053
pub fn from_slice(s: &str) -> ~str {
71-
unsafe { raw::slice_bytes_owned(s, 0, len(s)) }
54+
unsafe { raw::slice_bytes_unique(s, 0, len(s)) }
7255
}
7356

7457
impl ToStr for ~str {
@@ -296,7 +279,7 @@ pub fn pop_char(s: &mut ~str) -> char {
296279
*/
297280
pub fn shift_char(s: &mut ~str) -> char {
298281
let CharRange {ch, next} = char_range_at(*s, 0u);
299-
*s = unsafe { raw::slice_bytes_owned(*s, next, len(*s)) };
282+
*s = unsafe { raw::slice_bytes_unique(*s, next, len(*s)) };
300283
return ch;
301284
}
302285

@@ -801,9 +784,9 @@ pub fn replace(s: &str, from: &str, to: &str) -> ~str {
801784
if first {
802785
first = false;
803786
} else {
804-
push_str(&mut result, to);
787+
unsafe { push_str(&mut result, to); }
805788
}
806-
push_str(&mut result, unsafe{raw::slice_bytes(s, start, end)});
789+
unsafe { push_str(&mut result, raw::slice_bytes_unique(s, start, end)); }
807790
}
808791
result
809792
}
@@ -2054,37 +2037,6 @@ pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
20542037
}
20552038
}
20562039

2057-
/**
2058-
* Returns the byte offset of an inner slice relative to an enclosing outer slice
2059-
*
2060-
* # Example
2061-
*
2062-
* ~~~
2063-
* let string = "a\nb\nc";
2064-
* let mut lines = ~[];
2065-
* for each_line(string) |line| { lines.push(line) }
2066-
*
2067-
* assert!(subslice_offset(string, lines[0]) == 0); // &"a"
2068-
* assert!(subslice_offset(string, lines[1]) == 2); // &"b"
2069-
* assert!(subslice_offset(string, lines[2]) == 4); // &"c"
2070-
* ~~~
2071-
*/
2072-
#[inline(always)]
2073-
pub fn subslice_offset(outer: &str, inner: &str) -> uint {
2074-
do as_buf(outer) |a, a_len| {
2075-
do as_buf(inner) |b, b_len| {
2076-
let a_start: uint, a_end: uint, b_start: uint, b_end: uint;
2077-
unsafe {
2078-
a_start = cast::transmute(a); a_end = a_len + cast::transmute(a);
2079-
b_start = cast::transmute(b); b_end = b_len + cast::transmute(b);
2080-
}
2081-
assert!(a_start <= b_start);
2082-
assert!(b_end <= a_end);
2083-
b_start - a_start
2084-
}
2085-
}
2086-
}
2087-
20882040
/**
20892041
* Reserves capacity for exactly `n` bytes in the given string, not including
20902042
* the null terminator.
@@ -2206,20 +2158,13 @@ pub mod raw {
22062158
from_buf_len(::cast::reinterpret_cast(&c_str), len)
22072159
}
22082160

2209-
/// Converts a vector of bytes to a new owned string.
2161+
/// Converts a vector of bytes to a string.
22102162
pub unsafe fn from_bytes(v: &const [u8]) -> ~str {
22112163
do vec::as_const_buf(v) |buf, len| {
22122164
from_buf_len(buf, len)
22132165
}
22142166
}
22152167

2216-
/// Converts a vector of bytes to a string.
2217-
/// The byte slice needs to contain valid utf8 and needs to be one byte longer than
2218-
/// the string, if possible ending in a 0 byte.
2219-
pub unsafe fn from_bytes_with_null<'a>(v: &'a [u8]) -> &'a str {
2220-
cast::transmute(v)
2221-
}
2222-
22232168
/// Converts a byte to a string.
22242169
pub unsafe fn from_byte(u: u8) -> ~str { raw::from_bytes([u]) }
22252170

@@ -2241,7 +2186,7 @@ pub mod raw {
22412186
* If begin is greater than end.
22422187
* If end is greater than the length of the string.
22432188
*/
2244-
pub unsafe fn slice_bytes_owned(s: &str, begin: uint, end: uint) -> ~str {
2189+
pub unsafe fn slice_bytes_unique(s: &str, begin: uint, end: uint) -> ~str {
22452190
do as_buf(s) |sbuf, n| {
22462191
assert!((begin <= end));
22472192
assert!((end <= n));
@@ -2313,7 +2258,7 @@ pub mod raw {
23132258
let len = len(*s);
23142259
assert!((len > 0u));
23152260
let b = s[0];
2316-
*s = unsafe { raw::slice_bytes_owned(*s, 1u, len) };
2261+
*s = unsafe { raw::slice_bytes_unique(*s, 1u, len) };
23172262
return b;
23182263
}
23192264

@@ -3344,66 +3289,6 @@ mod tests {
33443289
let _x = from_bytes(bb);
33453290
}
33463291
3347-
#[test]
3348-
fn test_unsafe_from_bytes_with_null() {
3349-
let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
3350-
let b = unsafe { raw::from_bytes_with_null(a) };
3351-
assert_eq!(b, "AAAAAAA");
3352-
}
3353-
3354-
#[test]
3355-
fn test_from_bytes_with_null() {
3356-
let ss = "ศไทย中华Việt Nam";
3357-
let bb = [0xe0_u8, 0xb8_u8, 0xa8_u8,
3358-
0xe0_u8, 0xb9_u8, 0x84_u8,
3359-
0xe0_u8, 0xb8_u8, 0x97_u8,
3360-
0xe0_u8, 0xb8_u8, 0xa2_u8,
3361-
0xe4_u8, 0xb8_u8, 0xad_u8,
3362-
0xe5_u8, 0x8d_u8, 0x8e_u8,
3363-
0x56_u8, 0x69_u8, 0xe1_u8,
3364-
0xbb_u8, 0x87_u8, 0x74_u8,
3365-
0x20_u8, 0x4e_u8, 0x61_u8,
3366-
0x6d_u8, 0x0_u8];
3367-
3368-
assert_eq!(ss, from_bytes_with_null(bb));
3369-
}
3370-
3371-
#[test]
3372-
#[should_fail]
3373-
#[ignore(cfg(windows))]
3374-
fn test_from_bytes_with_null_fail() {
3375-
let bb = [0xff_u8, 0xb8_u8, 0xa8_u8,
3376-
0xe0_u8, 0xb9_u8, 0x84_u8,
3377-
0xe0_u8, 0xb8_u8, 0x97_u8,
3378-
0xe0_u8, 0xb8_u8, 0xa2_u8,
3379-
0xe4_u8, 0xb8_u8, 0xad_u8,
3380-
0xe5_u8, 0x8d_u8, 0x8e_u8,
3381-
0x56_u8, 0x69_u8, 0xe1_u8,
3382-
0xbb_u8, 0x87_u8, 0x74_u8,
3383-
0x20_u8, 0x4e_u8, 0x61_u8,
3384-
0x6d_u8, 0x0_u8];
3385-
3386-
let _x = from_bytes_with_null(bb);
3387-
}
3388-
3389-
#[test]
3390-
#[should_fail]
3391-
#[ignore(cfg(windows))]
3392-
fn test_from_bytes_with_null_fail_2() {
3393-
let bb = [0xff_u8, 0xb8_u8, 0xa8_u8,
3394-
0xe0_u8, 0xb9_u8, 0x84_u8,
3395-
0xe0_u8, 0xb8_u8, 0x97_u8,
3396-
0xe0_u8, 0xb8_u8, 0xa2_u8,
3397-
0xe4_u8, 0xb8_u8, 0xad_u8,
3398-
0xe5_u8, 0x8d_u8, 0x8e_u8,
3399-
0x56_u8, 0x69_u8, 0xe1_u8,
3400-
0xbb_u8, 0x87_u8, 0x74_u8,
3401-
0x20_u8, 0x4e_u8, 0x61_u8,
3402-
0x6d_u8, 0x60_u8];
3403-
3404-
let _x = from_bytes_with_null(bb);
3405-
}
3406-
34073292
#[test]
34083293
fn test_from_buf() {
34093294
unsafe {
@@ -3466,30 +3351,6 @@ mod tests {
34663351
}
34673352
}
34683353
3469-
#[test]
3470-
fn test_subslice_offset() {
3471-
let a = "kernelsprite";
3472-
let b = slice(a, 7, len(a));
3473-
let c = slice(a, 0, len(a) - 6);
3474-
assert!(subslice_offset(a, b) == 7);
3475-
assert!(subslice_offset(a, c) == 0);
3476-
3477-
let string = "a\nb\nc";
3478-
let mut lines = ~[];
3479-
for each_line(string) |line| { lines.push(line) }
3480-
assert!(subslice_offset(string, lines[0]) == 0);
3481-
assert!(subslice_offset(string, lines[1]) == 2);
3482-
assert!(subslice_offset(string, lines[2]) == 4);
3483-
}
3484-
3485-
#[test]
3486-
#[should_fail]
3487-
fn test_subslice_offset_2() {
3488-
let a = "alchemiter";
3489-
let b = "cruxtruder";
3490-
subslice_offset(a, b);
3491-
}
3492-
34933354
#[test]
34943355
fn vec_str_conversions() {
34953356
let s1: ~str = ~"All mimsy were the borogoves";

branches/try/src/libsyntax/print/pprust.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub fn rust_printer(writer: @io::Writer, intr: @ident_interner) -> @ps {
9595
}
9696

9797
pub static indent_unit: uint = 4u;
98-
pub static match_indent_unit: uint = 2u;
9998

10099
pub static default_columns: uint = 78u;
101100

@@ -1227,16 +1226,16 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
12271226
print_block(s, blk);
12281227
}
12291228
ast::expr_match(expr, ref arms) => {
1230-
cbox(s, match_indent_unit);
1229+
cbox(s, indent_unit);
12311230
ibox(s, 4);
12321231
word_nbsp(s, ~"match");
12331232
print_expr(s, expr);
12341233
space(s.s);
12351234
bopen(s);
1236-
let len = (*arms).len();
1237-
for (*arms).eachi |i, arm| {
1235+
let len = arms.len();
1236+
for arms.eachi |i, arm| {
12381237
space(s.s);
1239-
cbox(s, match_indent_unit);
1238+
cbox(s, indent_unit);
12401239
ibox(s, 0u);
12411240
let mut first = true;
12421241
for arm.pats.each |p| {
@@ -1269,7 +1268,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
12691268
ast::expr_block(ref blk) => {
12701269
// the block will close the pattern's ibox
12711270
print_block_unclosed_indent(
1272-
s, blk, match_indent_unit);
1271+
s, blk, indent_unit);
12731272
}
12741273
_ => {
12751274
end(s); // close the ibox for the pattern
@@ -1286,10 +1285,10 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
12861285
}
12871286
} else {
12881287
// the block will close the pattern's ibox
1289-
print_block_unclosed_indent(s, &arm.body, match_indent_unit);
1288+
print_block_unclosed_indent(s, &arm.body, indent_unit);
12901289
}
12911290
}
1292-
bclose_(s, expr.span, match_indent_unit);
1291+
bclose_(s, expr.span, indent_unit);
12931292
}
12941293
ast::expr_fn_block(ref decl, ref body) => {
12951294
// in do/for blocks we don't want to show an empty

branches/try/src/test/pretty/alt-naked-expr-long.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ fn main() {
1717
let x = Some(3);
1818
let y =
1919
match x {
20-
Some(_) =>
21-
~"some" + ~"very" + ~"very" + ~"very" + ~"very" + ~"very" + ~"very"
22-
+ ~"very" + ~"very" + ~"long" + ~"string",
23-
None => ~"none"
20+
Some(_) =>
21+
~"some" + ~"very" + ~"very" + ~"very" + ~"very" + ~"very" +
22+
~"very" + ~"very" + ~"very" + ~"long" + ~"string",
23+
None => ~"none"
2424
};
2525
}

branches/try/src/test/pretty/alt-naked-expr-medium.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
let x = Some(3);
1515
let _y =
1616
match x {
17-
Some(_) => ~[~"some(_)", ~"not", ~"SO", ~"long", ~"string"],
18-
None => ~[~"none"]
17+
Some(_) => ~[~"some(_)", ~"not", ~"SO", ~"long", ~"string"],
18+
None => ~[~"none"]
1919
};
2020
}

0 commit comments

Comments
 (0)