Skip to content

Commit 62bd055

Browse files
cpetersomarijnh
authored andcommitted
---
yaml --- r: 14334 b: refs/heads/try c: aec76d2 h: refs/heads/master v: v3
1 parent f104c09 commit 62bd055

File tree

4 files changed

+49
-98
lines changed

4 files changed

+49
-98
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 23703c06613b6740113ac799747c394f37eb51e7
5+
refs/heads/try: aec76d25152035878cb0b502e2b4dc1d637cff5b
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/comp/syntax/codemap.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
157157

158158
fn get_line(fm: filemap, line: int) -> str unsafe {
159159
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
160-
let end = alt str::byte_index_from(*fm.src, '\n' as u8, begin,
161-
str::len(*fm.src)) {
160+
let end = alt str::byte_index(*fm.src, '\n' as u8, begin) {
162161
some(e) { e }
163162
none { str::len(*fm.src) }
164163
};

branches/try/src/libcore/str.rs

Lines changed: 46 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ for correctness, but some UTF-8 unsafe functions are also provided.
99
For some heavy-duty uses, we recommend trying std::rope.
1010
*/
1111

12-
import option::{some, none};
13-
1412
export
1513
// Creating a string
1614
from_bytes,
@@ -71,11 +69,9 @@ export
7169
// Searching
7270
index,
7371
byte_index,
74-
byte_index_from,
7572
rindex,
7673
find,
7774
find_bytes,
78-
find_from_bytes,
7975
contains,
8076
starts_with,
8177
ends_with,
@@ -669,8 +665,8 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe {
669665
} else {
670666
let idx;
671667
alt find_bytes(s, from) {
672-
some(x) { idx = x; }
673-
none { ret s; }
668+
option::some(x) { idx = x; }
669+
option::none { ret s; }
674670
}
675671
let before = unsafe::slice_bytes(s, 0u, idx as uint);
676672
let after = unsafe::slice_bytes(s, idx as uint + len_bytes(from),
@@ -846,34 +842,28 @@ fn index(ss: str, cc: char) -> option<uint> {
846842

847843
// found here?
848844
if ch == cc {
849-
ret some(cii);
845+
ret option::some(cii);
850846
}
851847

852848
cii += 1u;
853849
bii = next;
854850
}
855851

856852
// wasn't found
857-
ret none;
853+
ret option::none;
858854
}
859855

860856
// Function: byte_index
861857
//
862858
// Returns the index of the first matching byte
863859
// (as option some/none)
864-
fn byte_index(s: str, b: u8) -> option<uint> {
865-
byte_index_from(s, b, 0u, len_bytes(s))
866-
}
867-
868-
// Function: byte_index_from
869-
//
870-
// Returns the index of the first matching byte within the range [`start`,
871-
// `end`).
872-
// (as option some/none)
873-
fn byte_index_from(s: str, b: u8, start: uint, end: uint) -> option<uint> {
874-
assert end <= len_bytes(s);
875-
876-
str::as_bytes(s) { |v| vec::position_from(v, start, end) { |x| x == b } }
860+
fn byte_index(s: str, b: u8, start: uint) -> option<uint> {
861+
let i = start, l = len_bytes(s);
862+
while i < l {
863+
if s[i] == b { ret some(i); }
864+
i += 1u;
865+
}
866+
ret none;
877867
}
878868

879869
// Function: rindex
@@ -890,50 +880,40 @@ fn rindex(ss: str, cc: char) -> option<uint> {
890880

891881
// found here?
892882
if ch == cc {
893-
ret some(cii);
883+
ret option::some(cii);
894884
}
895885
}
896886

897887
// wasn't found
898-
ret none;
888+
ret option::none;
899889
}
900890

901891
//Function: find_bytes
902892
//
903893
// Find the char position of the first instance of one string
904894
// within another, or return option::none
905-
fn find_bytes(haystack: str, needle: str) -> option<uint> {
906-
find_from_bytes(haystack, needle, 0u, len_bytes(haystack))
907-
}
908-
909-
//Function: find_from_bytes
910-
//
911-
// Find the char position of the first instance of one string
912-
// within another, or return option::none
913895
//
914896
// FIXME: Boyer-Moore should be significantly faster
915-
fn find_from_bytes(haystack: str, needle: str, start: uint, end:uint)
916-
-> option<uint> {
917-
assert end <= len_bytes(haystack);
918-
919-
let needle_len = len_bytes(needle);
897+
fn find_bytes(haystack: str, needle: str) -> option<uint> {
898+
let haystack_len = len_bytes(haystack);
899+
let needle_len = len_bytes(needle);
920900

921-
if needle_len == 0u { ret some(start); }
922-
if needle_len > end { ret none; }
901+
if needle_len == 0u { ret option::some(0u); }
902+
if needle_len > haystack_len { ret option::none; }
923903

924904
fn match_at(haystack: str, needle: str, ii: uint) -> bool {
925905
let jj = ii;
926906
for c: u8 in needle { if haystack[jj] != c { ret false; } jj += 1u; }
927907
ret true;
928908
}
929909

930-
let ii = start;
931-
while ii <= end - needle_len {
932-
if match_at(haystack, needle, ii) { ret some(ii); }
910+
let ii = 0u;
911+
while ii <= haystack_len - needle_len {
912+
if match_at(haystack, needle, ii) { ret option::some(ii); }
933913
ii += 1u;
934914
}
935915

936-
ret none;
916+
ret option::none;
937917
}
938918

939919
// Function: find
@@ -942,8 +922,8 @@ fn find_from_bytes(haystack: str, needle: str, start: uint, end:uint)
942922
// within another, or return option::none
943923
fn find(haystack: str, needle: str) -> option<uint> {
944924
alt find_bytes(haystack, needle) {
945-
none { ret none; }
946-
some(nn) { ret some(b2c_pos(haystack, nn)); }
925+
option::none { ret option::none; }
926+
option::some(nn) { ret option::some(b2c_pos(haystack, nn)); }
947927
}
948928
}
949929

@@ -1542,18 +1522,18 @@ mod tests {
15421522

15431523
#[test]
15441524
fn test_index() {
1545-
assert ( index("hello", 'h') == some(0u));
1546-
assert ( index("hello", 'e') == some(1u));
1547-
assert ( index("hello", 'o') == some(4u));
1548-
assert ( index("hello", 'z') == none);
1525+
assert ( index("hello", 'h') == option::some(0u));
1526+
assert ( index("hello", 'e') == option::some(1u));
1527+
assert ( index("hello", 'o') == option::some(4u));
1528+
assert ( index("hello", 'z') == option::none);
15491529
}
15501530

15511531
#[test]
15521532
fn test_rindex() {
1553-
assert (rindex("hello", 'l') == some(3u));
1554-
assert (rindex("hello", 'o') == some(4u));
1555-
assert (rindex("hello", 'h') == some(0u));
1556-
assert (rindex("hello", 'z') == none);
1533+
assert (rindex("hello", 'l') == option::some(3u));
1534+
assert (rindex("hello", 'o') == option::some(4u));
1535+
assert (rindex("hello", 'h') == option::some(0u));
1536+
assert (rindex("hello", 'z') == option::none);
15571537
}
15581538

15591539
#[test]
@@ -1757,57 +1737,29 @@ mod tests {
17571737
#[test]
17581738
fn test_find_bytes() {
17591739
// byte positions
1760-
assert (find_bytes("banana", "apple pie") == none);
1761-
assert (find_bytes("", "") == some(0u));
1740+
assert (find_bytes("banana", "apple pie") == option::none);
1741+
assert (find_bytes("", "") == option::some(0u));
17621742

17631743
let data = "ประเทศไทย中华Việt Nam";
1764-
assert (find_bytes(data, "") == some(0u));
1765-
assert (find_bytes(data, "ประเ") == some( 0u));
1766-
assert (find_bytes(data, "ะเ") == some( 6u));
1767-
assert (find_bytes(data, "中华") == some(27u));
1768-
assert (find_bytes(data, "ไท华") == none);
1769-
}
1770-
1771-
#[test]
1772-
fn test_find_from_bytes() {
1773-
// byte positions
1774-
assert (find_from_bytes("", "", 0u, 0u) == some(0u));
1775-
1776-
let data = "abcabc";
1777-
assert find_from_bytes(data, "ab", 0u, 6u) == some(0u);
1778-
assert find_from_bytes(data, "ab", 2u, 6u) == some(3u);
1779-
assert find_from_bytes(data, "ab", 2u, 4u) == none;
1780-
1781-
let data = "ประเทศไทย中华Việt Nam";
1782-
data += data;
1783-
assert find_from_bytes(data, "", 0u, 43u) == some(0u);
1784-
assert find_from_bytes(data, "", 6u, 43u) == some(6u);
1785-
1786-
assert find_from_bytes(data, "ประ", 0u, 43u) == some( 0u);
1787-
assert find_from_bytes(data, "ทศไ", 0u, 43u) == some(12u);
1788-
assert find_from_bytes(data, "ย中", 0u, 43u) == some(24u);
1789-
assert find_from_bytes(data, "iệt", 0u, 43u) == some(34u);
1790-
assert find_from_bytes(data, "Nam", 0u, 43u) == some(40u);
1791-
1792-
assert find_from_bytes(data, "ประ", 43u, 86u) == some(43u);
1793-
assert find_from_bytes(data, "ทศไ", 43u, 86u) == some(55u);
1794-
assert find_from_bytes(data, "ย中", 43u, 86u) == some(67u);
1795-
assert find_from_bytes(data, "iệt", 43u, 86u) == some(77u);
1796-
assert find_from_bytes(data, "Nam", 43u, 86u) == some(83u);
1744+
assert (find_bytes(data, "") == option::some(0u));
1745+
assert (find_bytes(data, "ประเ") == option::some( 0u));
1746+
assert (find_bytes(data, "ะเ") == option::some( 6u));
1747+
assert (find_bytes(data, "中华") == option::some(27u));
1748+
assert (find_bytes(data, "ไท华") == option::none);
17971749
}
17981750

17991751
#[test]
18001752
fn test_find() {
18011753
// char positions
1802-
assert (find("banana", "apple pie") == none);
1803-
assert (find("", "") == some(0u));
1754+
assert (find("banana", "apple pie") == option::none);
1755+
assert (find("", "") == option::some(0u));
18041756

18051757
let data = "ประเทศไทย中华Việt Nam";
1806-
assert (find(data, "") == some(0u));
1807-
assert (find(data, "ประเ") == some(0u));
1808-
assert (find(data, "ะเ") == some(2u));
1809-
assert (find(data, "中华") == some(9u));
1810-
assert (find(data, "ไท华") == none);
1758+
assert (find(data, "") == option::some(0u));
1759+
assert (find(data, "ประเ") == option::some(0u));
1760+
assert (find(data, "ะเ") == option::some(2u));
1761+
assert (find(data, "中华") == option::some(9u));
1762+
assert (find(data, "ไท华") == option::none);
18111763
}
18121764

18131765
#[test]

branches/try/src/libstd/generic_os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn setenv(n: str, v: str) { }
2121
fn env() -> [(str,str)] {
2222
let pairs = [];
2323
for p in os::rustrt::rust_env_pairs() {
24-
let vs = str::split_char(p, '=');
24+
let vs = str::splitn_char(p, '=', 1u);
2525
assert vec::len(vs) == 2u;
2626
pairs += [(vs[0], vs[1])];
2727
}

0 commit comments

Comments
 (0)