Skip to content

Commit 989f104

Browse files
committed
---
yaml --- r: 11215 b: refs/heads/master c: 0121cd5 h: refs/heads/master i: 11213: 63427f6 11211: d29467d 11207: 047a017 11199: b8e9f37 v: v3
1 parent 68c1c69 commit 989f104

File tree

9 files changed

+98
-177
lines changed

9 files changed

+98
-177
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: e0af23b664a1307fe376f2638bb7a69f04e2ac1c
2+
refs/heads/master: 0121cd5b0e302746d2cfe1b5524c2909fcc96ccf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/cargo/cargo.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -651,27 +651,25 @@ fn cmd_install(c: cargo) unsafe {
651651

652652
if str::starts_with(target, "uuid:") {
653653
let uuid = rest(target, 5u);
654-
alt str::index(uuid, '/') {
655-
option::some(idx) {
656-
let source = str::slice(uuid, 0u, idx);
657-
uuid = str::slice(uuid, idx + 1u, str::char_len(uuid));
658-
install_uuid_specific(c, wd, source, uuid);
659-
}
660-
option::none {
661-
install_uuid(c, wd, uuid);
662-
}
654+
let idx = str::index(uuid, '/' as u8);
655+
if idx != -1 {
656+
let source = str::unsafe::slice_bytes(uuid, 0u, idx as uint);
657+
uuid = str::unsafe::slice_bytes(uuid, idx as uint + 1u,
658+
str::byte_len(uuid));
659+
install_uuid_specific(c, wd, source, uuid);
660+
} else {
661+
install_uuid(c, wd, uuid);
663662
}
664663
} else {
665664
let name = target;
666-
alt str::index(name, '/') {
667-
option::some(idx) {
668-
let source = str::slice(name, 0u, idx);
669-
name = str::slice(name, idx + 1u, str::char_len(name));
670-
install_named_specific(c, wd, source, name);
671-
}
672-
option::none {
673-
install_named(c, wd, name);
674-
}
665+
let idx = str::index(name, '/' as u8);
666+
if idx != -1 {
667+
let source = str::unsafe::slice_bytes(name, 0u, idx as uint);
668+
name = str::unsafe::slice_bytes(name, idx as uint + 1u,
669+
str::byte_len(name));
670+
install_named_specific(c, wd, source, name);
671+
} else {
672+
install_named(c, wd, name);
675673
}
676674
}
677675
}

trunk/src/comp/back/link.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,14 @@ mod write {
109109
// Decides what to call an intermediate file, given the name of the output
110110
// and the extension to use.
111111
fn mk_intermediate_name(output_path: str, extension: str) -> str unsafe {
112-
let stem = alt str::index(output_path, '.') {
113-
option::some(dot_pos) {
114-
str::slice(output_path, 0u, dot_pos)
115-
}
116-
option::none { output_path }
117-
};
118-
112+
let dot_pos = str::index(output_path, '.' as u8);
113+
let stem;
114+
if dot_pos < 0 {
115+
stem = output_path;
116+
} else { stem = str::unsafe::slice_bytes(output_path, 0u,
117+
dot_pos as uint); }
119118
ret stem + "." + extension;
120119
}
121-
122120
fn run_passes(sess: session, llmod: ModuleRef, output: str) {
123121
let opts = sess.opts;
124122
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }

trunk/src/comp/syntax/codemap.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,16 @@ fn get_line(fm: filemap, line: int) -> str unsafe {
119119
let end: uint;
120120
if line as uint < vec::len(fm.lines) - 1u {
121121
end = fm.lines[line + 1].byte - fm.start_pos.byte;
122-
ret str::unsafe::slice_bytes(*fm.src, begin, end);
123122
} else {
124123
// If we're not done parsing the file, we're at the limit of what's
125124
// parsed. If we just slice the rest of the string, we'll print out
126125
// the remainder of the file, which is undesirable.
127-
ret str::splitn_char(*fm.src, '\n', 1u)[0];
126+
end = str::byte_len(*fm.src);
127+
let rest = str::unsafe::slice_bytes(*fm.src, begin, end);
128+
let newline = str::index(rest, '\n' as u8);
129+
if newline != -1 { end = begin + (newline as uint); }
128130
}
131+
ret str::unsafe::slice_bytes(*fm.src, begin, end);
129132
}
130133

131134
fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)

trunk/src/fuzzer/fuzzer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ fn check_variants_T<T: copy>(
283283
}
284284
}
285285

286-
fn last_part(filename: str) -> str {
287-
let ix = option::get(str::rindex(filename, '/'));
288-
str::slice(filename, ix + 1u, str::char_len(filename) - 3u)
286+
fn last_part(filename: str) -> str unsafe {
287+
let ix = str::rindex(filename, 47u8 /* '/' */);
288+
assert ix >= 0;
289+
str::unsafe::slice_bytes(filename, ix as uint + 1u, str::byte_len(filename) - 3u)
289290
}
290291

291292
enum happiness { passed, cleanly_rejected(str), known_bug(str), failed(str), }

trunk/src/libcore/char.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export is_alphabetic,
3737
is_XID_start, is_XID_continue,
3838
is_lowercase, is_uppercase,
3939
is_whitespace, is_alphanumeric,
40+
is_ascii, is_digit,
4041
to_digit, to_lower, to_upper, maybe_digit, cmp;
4142

4243
import is_alphabetic = unicode::derived_property::Alphabetic;
@@ -84,6 +85,17 @@ pure fn is_alphanumeric(c: char) -> bool {
8485
unicode::general_category::No(c);
8586
}
8687

88+
#[doc( brief = "Indicates whether the character is an ASCII character" )]
89+
pure fn is_ascii(c: char) -> bool {
90+
c - ('\x7F' & c) == '\x00'
91+
}
92+
93+
#[doc( brief = "Indicates whether the character is numeric (Nd, Nl, or No)" )]
94+
pure fn is_digit(c: char) -> bool {
95+
ret unicode::general_category::Nd(c) ||
96+
unicode::general_category::Nl(c) ||
97+
unicode::general_category::No(c);
98+
}
8799

88100
#[doc(
89101
brief = "Convert a char to the corresponding digit. \
@@ -221,3 +233,20 @@ fn test_to_upper() {
221233
//assert (to_upper('ü') == 'Ü');
222234
assert (to_upper('ß') == 'ß');
223235
}
236+
237+
#[test]
238+
fn test_is_ascii() unsafe {
239+
assert str::all("banana", char::is_ascii);
240+
assert ! str::all("ประเทศไทย中华Việt Nam", char::is_ascii);
241+
}
242+
243+
#[test]
244+
fn test_is_digit() {
245+
assert is_digit('2');
246+
assert is_digit('7');
247+
assert ! is_digit('c');
248+
assert ! is_digit('i');
249+
assert ! is_digit('z');
250+
assert ! is_digit('Q');
251+
}
252+

trunk/src/libcore/str.rs

Lines changed: 14 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ export
7272
// Searching
7373
index,
7474
rindex,
75-
index_byte,
76-
rindex_byte,
7775
find,
7876
contains,
7977
starts_with,
@@ -255,12 +253,15 @@ Function: pop_char
255253
Remove the final character from a string and return it.
256254
257255
Failure:
256+
258257
If the string does not contain any characters.
259258
*/
260259
fn pop_char(&s: str) -> char unsafe {
261260
let end = byte_len(s);
262-
let {ch:ch, prev:end} = char_range_at_reverse(s, end);
263-
s = unsafe::slice_bytes(s, 0u, end);
261+
while end > 0u && s[end - 1u] & 192u8 == tag_cont_u8 { end -= 1u; }
262+
assert (end > 0u);
263+
let ch = char_at(s, end - 1u);
264+
s = unsafe::slice_bytes(s, 0u, end - 1u);
264265
ret ch;
265266
}
266267

@@ -867,52 +868,6 @@ fn lines_iter(ss: str, ff: fn(&&str)) {
867868
Section: Searching
868869
*/
869870

870-
// Function: index
871-
//
872-
// Returns the index of the first matching char
873-
// (as option some/none)
874-
fn index(ss: str, cc: char) -> option<uint> {
875-
let bii = 0u;
876-
let cii = 0u;
877-
let len = byte_len(ss);
878-
while bii < len {
879-
let {ch, next} = char_range_at(ss, bii);
880-
881-
// found here?
882-
if ch == cc {
883-
ret option::some(cii);
884-
}
885-
886-
cii += 1u;
887-
bii = next;
888-
}
889-
890-
// wasn't found
891-
ret option::none;
892-
}
893-
894-
// Function: rindex
895-
//
896-
// Returns the index of the first matching char
897-
// (as option some/none)
898-
fn rindex(ss: str, cc: char) -> option<uint> {
899-
let bii = byte_len(ss);
900-
let cii = char_len(ss);
901-
while bii > 0u {
902-
let {ch, prev} = char_range_at_reverse(ss, bii);
903-
cii -= 1u;
904-
bii = prev;
905-
906-
// found here?
907-
if ch == cc {
908-
ret option::some(cii);
909-
}
910-
}
911-
912-
// wasn't found
913-
ret option::none;
914-
}
915-
916871
/*
917872
Function: index
918873
@@ -921,7 +876,7 @@ no match is found.
921876
922877
FIXME: UTF-8
923878
*/
924-
fn index_byte(s: str, c: u8) -> int {
879+
fn index(s: str, c: u8) -> int {
925880
let i: int = 0;
926881
for k: u8 in s { if k == c { ret i; } i += 1; }
927882
ret -1;
@@ -935,7 +890,7 @@ if no match is found.
935890
936891
FIXME: UTF-8
937892
*/
938-
fn rindex_byte(s: str, c: u8) -> int {
893+
fn rindex(s: str, c: u8) -> int {
939894
let n: int = byte_len(s) as int;
940895
while n >= 0 { if s[n] == c { ret n; } n -= 1; }
941896
ret n;
@@ -1278,25 +1233,6 @@ Pluck a character out of a string
12781233
*/
12791234
fn char_at(s: str, i: uint) -> char { ret char_range_at(s, i).ch; }
12801235

1281-
// Function: char_range_at_reverse
1282-
//
1283-
// Given a byte position and a str, return the previous char and its position
1284-
// This function can be used to iterate over a unicode string in reverse.
1285-
fn char_range_at_reverse(ss: str, start: uint) -> {ch: char, prev: uint} {
1286-
let prev = start;
1287-
1288-
// while there is a previous byte == 10......
1289-
while prev > 0u && ss[prev - 1u] & 192u8 == tag_cont_u8 {
1290-
prev -= 1u;
1291-
}
1292-
1293-
// now refer to the initial byte of previous char
1294-
prev -= 1u;
1295-
1296-
let ch = char_at(ss, prev);
1297-
ret {ch:ch, prev:prev};
1298-
}
1299-
13001236
/*
13011237
Function: substr_all
13021238
@@ -1506,56 +1442,13 @@ mod tests {
15061442
}
15071443

15081444
#[test]
1509-
fn test_index() {
1510-
assert ( index("hello", 'h') == option::some(0u));
1511-
assert ( index("hello", 'e') == option::some(1u));
1512-
assert ( index("hello", 'o') == option::some(4u));
1513-
assert ( index("hello", 'z') == option::none);
1514-
}
1515-
1516-
#[test]
1517-
fn test_rindex() {
1518-
assert (rindex("hello", 'l') == option::some(3u));
1519-
assert (rindex("hello", 'o') == option::some(4u));
1520-
assert (rindex("hello", 'h') == option::some(0u));
1521-
assert (rindex("hello", 'z') == option::none);
1522-
}
1523-
1524-
#[test]
1525-
fn test_index_byte() {
1526-
assert ( index_byte("hello", 'e' as u8) == 1);
1527-
assert ( index_byte("hello", 'o' as u8) == 4);
1528-
assert ( index_byte("hello", 'z' as u8) == -1);
1529-
}
1530-
1531-
#[test]
1532-
fn test_rindex_byte() {
1533-
assert (rindex_byte("hello", 'l' as u8) == 3);
1534-
assert (rindex_byte("hello", 'h' as u8) == 0);
1535-
assert (rindex_byte("hello", 'z' as u8) == -1);
1536-
}
1537-
1538-
#[test]
1539-
fn test_pop_char() {
1540-
let data = "ประเทศไทย中华";
1541-
let cc = pop_char(data);
1542-
assert "ประเทศไทย中" == data;
1543-
assert '华' == cc;
1544-
}
1545-
1546-
#[test]
1547-
fn test_pop_char_2() {
1548-
let data2 = "华";
1549-
let cc2 = pop_char(data2);
1550-
assert "" == data2;
1551-
assert '华' == cc2;
1552-
}
1553-
1554-
#[test]
1555-
#[should_fail]
1556-
fn test_pop_char_fail() {
1557-
let data = "";
1558-
let _cc3 = pop_char(data);
1445+
fn test_index_and_rindex() {
1446+
assert (index("hello", 'e' as u8) == 1);
1447+
assert (index("hello", 'o' as u8) == 4);
1448+
assert (index("hello", 'z' as u8) == -1);
1449+
assert (rindex("hello", 'l' as u8) == 3);
1450+
assert (rindex("hello", 'h' as u8) == 0);
1451+
assert (rindex("hello", 'z' as u8) == -1);
15591452
}
15601453

15611454
#[test]

0 commit comments

Comments
 (0)