Skip to content

Commit ac8052f

Browse files
killerswanbrson
authored andcommitted
---
yaml --- r: 11100 b: refs/heads/master c: 2b0396c h: refs/heads/master v: v3
1 parent a3a7a6e commit ac8052f

File tree

8 files changed

+46
-41
lines changed

8 files changed

+46
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a3f5626ad1b5bc47ceddfb0d600cf6fd8a6dad8c
2+
refs/heads/master: 2b0396c34adc95efc0451536554a6f7c928c1e61
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/comp/back/link.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ mod write {
113113

114114
// Decides what to call an intermediate file, given the name of the output
115115
// and the extension to use.
116-
fn mk_intermediate_name(output_path: str, extension: str) -> str {
116+
fn mk_intermediate_name(output_path: str, extension: str) -> str unsafe {
117117
let dot_pos = str::index(output_path, '.' as u8);
118118
let stem;
119119
if dot_pos < 0 {
120120
stem = output_path;
121-
} else { stem = str::substr(output_path, 0u, dot_pos as uint); }
121+
} else { stem = str::unsafe::slice_bytes(output_path, 0u,
122+
dot_pos as uint); }
122123
ret stem + "." + extension;
123124
}
124125
fn run_passes(sess: session, llmod: ModuleRef, output: str) {
@@ -480,8 +481,8 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
480481
ret {name: name, vers: vers, extras_hash: extras_hash};
481482
}
482483

483-
fn truncated_sha1_result(sha: sha1) -> str {
484-
ret str::substr(sha.result_str(), 0u, 16u);
484+
fn truncated_sha1_result(sha: sha1) -> str unsafe {
485+
ret str::unsafe::slice_bytes(sha.result_str(), 0u, 16u);
485486
}
486487

487488

trunk/src/comp/util/ppaux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
116116
}
117117
}
118118

119-
fn ty_to_short_str(cx: ctxt, typ: t) -> str {
119+
fn ty_to_short_str(cx: ctxt, typ: t) -> str unsafe {
120120
let s = encoder::encoded_ty(cx, typ);
121-
if str::byte_len(s) >= 32u { s = str::substr(s, 0u, 32u); }
121+
if str::byte_len(s) >= 32u { s = str::unsafe::slice_bytes(s, 0u, 32u); }
122122
ret s;
123123
}
124124

trunk/src/libcore/extfmt.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ mod ct {
8080
enum piece { piece_string(str), piece_conv(conv), }
8181
type error_fn = fn@(str) -> ! ;
8282

83-
fn parse_fmt_string(s: str, error: error_fn) -> [piece] {
83+
fn parse_fmt_string(s: str, error: error_fn) -> [piece] unsafe {
8484
let pieces: [piece] = [];
8585
let lim = str::byte_len(s);
8686
let buf = "";
@@ -93,13 +93,13 @@ mod ct {
9393
}
9494
let i = 0u;
9595
while i < lim {
96-
let curr = str::substr(s, i, 1u);
96+
let curr = str::unsafe::slice_bytes(s, i, i+1u);
9797
if str::eq(curr, "%") {
9898
i += 1u;
9999
if i >= lim {
100100
error("unterminated conversion at end of string");
101101
}
102-
let curr2 = str::substr(s, i, 1u);
102+
let curr2 = str::unsafe::slice_bytes(s, i, i+1u);
103103
if str::eq(curr2, "%") {
104104
buf += curr2;
105105
i += 1u;
@@ -223,9 +223,9 @@ mod ct {
223223
} else { {count: count_implied, next: i} };
224224
}
225225
fn parse_type(s: str, i: uint, lim: uint, error: error_fn) ->
226-
{ty: ty, next: uint} {
226+
{ty: ty, next: uint} unsafe {
227227
if i >= lim { error("missing type in conversion"); }
228-
let tstr = str::substr(s, i, 1u);
228+
let tstr = str::unsafe::slice_bytes(s, i, i+1u);
229229
// TODO: Do we really want two signed types here?
230230
// How important is it to be printf compatible?
231231
let t =
@@ -317,7 +317,7 @@ mod rt {
317317
fn conv_char(cv: conv, c: char) -> str {
318318
ret pad(cv, str::from_char(c), pad_nozero);
319319
}
320-
fn conv_str(cv: conv, s: str) -> str {
320+
fn conv_str(cv: conv, s: str) -> str unsafe {
321321
// For strings, precision is the maximum characters
322322
// displayed
323323

@@ -327,7 +327,7 @@ mod rt {
327327
count_implied { s }
328328
count_is(max) {
329329
if max as uint < str::char_len(s) {
330-
str::substr(s, 0u, max as uint)
330+
str::unsafe::slice_bytes(s, 0u, max as uint)
331331
} else { s }
332332
}
333333
};
@@ -391,7 +391,7 @@ mod rt {
391391
ret str::from_bytes(svec);
392392
}
393393
enum pad_mode { pad_signed, pad_unsigned, pad_nozero, }
394-
fn pad(cv: conv, s: str, mode: pad_mode) -> str {
394+
fn pad(cv: conv, s: str, mode: pad_mode) -> str unsafe {
395395
let uwidth;
396396
alt cv.width {
397397
count_implied { ret s; }
@@ -440,7 +440,7 @@ mod rt {
440440
let headstr = str::from_bytes([head]);
441441
// FIXME: not UTF-8 safe
442442
let bytelen = str::byte_len(s);
443-
let numpart = str::substr(s, 1u, bytelen - 1u);
443+
let numpart = str::unsafe::slice_bytes(s, 1u, bytelen);
444444
ret headstr + padstr + numpart;
445445
}
446446
}

trunk/src/libcore/str.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ Failure:
249249
250250
If the string does not contain any characters.
251251
*/
252-
fn pop_char(&s: str) -> char {
252+
fn pop_char(&s: str) -> char unsafe {
253253
let end = byte_len(s);
254254
while end > 0u && s[end - 1u] & 192u8 == tag_cont_u8 { end -= 1u; }
255255
assert (end > 0u);
256256
let ch = char_at(s, end - 1u);
257-
s = substr(s, 0u, end - 1u);
257+
s = unsafe::slice_bytes(s, 0u, end - 1u);
258258
ret ch;
259259
}
260260

@@ -267,9 +267,9 @@ Failure:
267267
268268
If the string does not contain any characters.
269269
*/
270-
fn shift_char(&s: str) -> char {
270+
fn shift_char(&s: str) -> char unsafe {
271271
let r = char_range_at(s, 0u);
272-
s = substr(s, r.next, byte_len(s) - r.next);
272+
s = unsafe::slice_bytes(s, r.next, byte_len(s));
273273
ret r.ch;
274274
}
275275

@@ -306,12 +306,13 @@ Function: pop_byte
306306
Removes the last byte from a string and returns it.
307307
308308
This function is not unicode-safe.
309+
FIXME: move to unsafe?
309310
*/
310-
fn pop_byte(&s: str) -> u8 {
311+
fn pop_byte(&s: str) -> u8 unsafe {
311312
let len = byte_len(s);
312313
assert (len > 0u);
313314
let b = s[len - 1u];
314-
s = substr(s, 0u, len - 1u);
315+
s = unsafe::slice_bytes(s, 0u, len - 1u);
315316
ret b;
316317
}
317318

@@ -321,12 +322,13 @@ Function: shift_byte
321322
Removes the first byte from a string and returns it.
322323
323324
This function is not unicode-safe.
325+
FIXME: move to unsafe?
324326
*/
325-
fn shift_byte(&s: str) -> u8 {
327+
fn shift_byte(&s: str) -> u8 unsafe {
326328
let len = byte_len(s);
327329
assert (len > 0u);
328330
let b = s[0];
329-
s = substr(s, 1u, len - 1u);
331+
s = unsafe::slice_bytes(s, 1u, len);
330332
ret b;
331333
}
332334

@@ -413,17 +415,15 @@ fn chars(s: str) -> [char] {
413415
/*
414416
Function: substr
415417
416-
Take a substring of another. Returns a string containing `len` bytes
417-
starting at byte offset `begin`.
418-
419-
FIXME: This function is not unicode-safe.
418+
Take a substring of another. Returns a string containing `len` chars
419+
starting at char offset `begin`.
420420
421421
Failure:
422422
423-
If `begin` + `len` is is greater than the byte length of the string
423+
If `begin` + `len` is is greater than the char length of the string
424424
*/
425-
fn substr(s: str, begin: uint, len: uint) -> str unsafe {
426-
ret unsafe::slice_bytes(s, begin, begin + len);
425+
fn substr(s: str, begin: uint, len: uint) -> str {
426+
ret slice(s, begin, begin + len);
427427
}
428428

429429
/*
@@ -941,8 +941,8 @@ haystack - The string to look in
941941
needle - The string to look for
942942
*/
943943
fn ends_with(haystack: str, needle: str) -> bool {
944-
let haystack_len: uint = byte_len(haystack);
945-
let needle_len: uint = byte_len(needle);
944+
let haystack_len: uint = char_len(haystack);
945+
let needle_len: uint = char_len(needle);
946946
ret if needle_len == 0u {
947947
true
948948
} else if needle_len > haystack_len {
@@ -1598,7 +1598,9 @@ mod tests {
15981598
}
15991599
t("hello", "llo", 2);
16001600
t("hello", "el", 1);
1601-
t("substr should not be a challenge", "not", 14);
1601+
1602+
assert "ะเทศไท"
1603+
== substr("ประเทศไทย中华Việt Nam", 2u, 6u);
16021604
}
16031605

16041606
#[test]

trunk/src/libstd/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ The dirname of "/usr/share" will be "/usr", but the dirname of
4343
4444
If the path is not prefixed with a directory, then "." is returned.
4545
*/
46-
fn dirname(p: path) -> path {
46+
fn dirname(p: path) -> path unsafe {
4747
let i: int = str::rindex(p, os_fs::path_sep as u8);
4848
if i == -1 {
4949
i = str::rindex(p, os_fs::alt_path_sep as u8);
5050
if i == -1 { ret "."; }
5151
}
52-
ret str::substr(p, 0u, i as uint);
52+
ret str::unsafe::slice_bytes(p, 0u, i as uint);
5353
}
5454

5555
/*

trunk/src/libstd/rope.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,11 +1341,12 @@ mod tests {
13411341
node::empty { ret "" }
13421342
node::content(x) {
13431343
let str = @mutable "";
1344-
fn aux(str: @mutable str, node: @node::node) {
1344+
fn aux(str: @mutable str, node: @node::node) unsafe {
13451345
alt(*node) {
13461346
node::leaf(x) {
1347-
*str += str::substr(
1348-
*x.content, x.byte_offset, x.byte_len);
1347+
*str += str::unsafe::slice_bytes(
1348+
*x.content, x.byte_offset,
1349+
x.byte_offset + x.byte_len);
13491350
}
13501351
node::concat(x) {
13511352
aux(str, x.left);

trunk/src/libstd/sha1.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ fn mk_sha1() -> sha1 {
291291
mod tests {
292292

293293
#[test]
294-
fn test() {
294+
fn test() unsafe {
295295
type test = {input: str, output: [u8]};
296296

297297
fn a_million_letter_a() -> str {
@@ -372,7 +372,8 @@ mod tests {
372372
let left = len;
373373
while left > 0u {
374374
let take = (left + 1u) / 2u;
375-
sh.input_str(str::substr(t.input, len - left, take));
375+
sh.input_str(str::unsafe::slice_bytes(t.input, len - left,
376+
take + len - left));
376377
left = left - take;
377378
}
378379
let out = sh.result();

0 commit comments

Comments
 (0)