Skip to content

Commit a22f373

Browse files
committed
---
yaml --- r: 14331 b: refs/heads/try c: d1c9b16 h: refs/heads/master i: 14329: 692d3e5 14327: 3b7ae02 v: v3
1 parent c636a8a commit a22f373

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
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: 75503570c79d461ccb6e4ef0a9ad872a77ba60c4
5+
refs/heads/try: d1c9b160adf5f13bca690e114f254b5353fe798d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/str.rs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ 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+
1214
export
1315
// Creating a string
1416
from_bytes,
@@ -665,8 +667,8 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe {
665667
} else {
666668
let idx;
667669
alt find_bytes(s, from) {
668-
option::some(x) { idx = x; }
669-
option::none { ret s; }
670+
some(x) { idx = x; }
671+
none { ret s; }
670672
}
671673
let before = unsafe::slice_bytes(s, 0u, idx as uint);
672674
let after = unsafe::slice_bytes(s, idx as uint + len_bytes(from),
@@ -842,15 +844,15 @@ fn index(ss: str, cc: char) -> option<uint> {
842844

843845
// found here?
844846
if ch == cc {
845-
ret option::some(cii);
847+
ret some(cii);
846848
}
847849

848850
cii += 1u;
849851
bii = next;
850852
}
851853

852854
// wasn't found
853-
ret option::none;
855+
ret none;
854856
}
855857

856858
// Function: byte_index
@@ -880,12 +882,12 @@ fn rindex(ss: str, cc: char) -> option<uint> {
880882

881883
// found here?
882884
if ch == cc {
883-
ret option::some(cii);
885+
ret some(cii);
884886
}
885887
}
886888

887889
// wasn't found
888-
ret option::none;
890+
ret none;
889891
}
890892

891893
//Function: find_bytes
@@ -898,8 +900,8 @@ fn find_bytes(haystack: str, needle: str) -> option<uint> {
898900
let haystack_len = len_bytes(haystack);
899901
let needle_len = len_bytes(needle);
900902

901-
if needle_len == 0u { ret option::some(0u); }
902-
if needle_len > haystack_len { ret option::none; }
903+
if needle_len == 0u { ret some(0u); }
904+
if needle_len > haystack_len { ret none; }
903905

904906
fn match_at(haystack: str, needle: str, ii: uint) -> bool {
905907
let jj = ii;
@@ -909,11 +911,11 @@ fn find_bytes(haystack: str, needle: str) -> option<uint> {
909911

910912
let ii = 0u;
911913
while ii <= haystack_len - needle_len {
912-
if match_at(haystack, needle, ii) { ret option::some(ii); }
914+
if match_at(haystack, needle, ii) { ret some(ii); }
913915
ii += 1u;
914916
}
915917

916-
ret option::none;
918+
ret none;
917919
}
918920

919921
// Function: find
@@ -922,8 +924,8 @@ fn find_bytes(haystack: str, needle: str) -> option<uint> {
922924
// within another, or return option::none
923925
fn find(haystack: str, needle: str) -> option<uint> {
924926
alt find_bytes(haystack, needle) {
925-
option::none { ret option::none; }
926-
option::some(nn) { ret option::some(b2c_pos(haystack, nn)); }
927+
none { ret none; }
928+
some(nn) { ret some(b2c_pos(haystack, nn)); }
927929
}
928930
}
929931

@@ -1522,18 +1524,18 @@ mod tests {
15221524

15231525
#[test]
15241526
fn test_index() {
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);
1527+
assert ( index("hello", 'h') == some(0u));
1528+
assert ( index("hello", 'e') == some(1u));
1529+
assert ( index("hello", 'o') == some(4u));
1530+
assert ( index("hello", 'z') == none);
15291531
}
15301532

15311533
#[test]
15321534
fn test_rindex() {
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);
1535+
assert (rindex("hello", 'l') == some(3u));
1536+
assert (rindex("hello", 'o') == some(4u));
1537+
assert (rindex("hello", 'h') == some(0u));
1538+
assert (rindex("hello", 'z') == none);
15371539
}
15381540

15391541
#[test]
@@ -1737,29 +1739,29 @@ mod tests {
17371739
#[test]
17381740
fn test_find_bytes() {
17391741
// byte positions
1740-
assert (find_bytes("banana", "apple pie") == option::none);
1741-
assert (find_bytes("", "") == option::some(0u));
1742+
assert (find_bytes("banana", "apple pie") == none);
1743+
assert (find_bytes("", "") == some(0u));
17421744

17431745
let data = "ประเทศไทย中华Việt Nam";
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);
1746+
assert (find_bytes(data, "") == some(0u));
1747+
assert (find_bytes(data, "ประเ") == some( 0u));
1748+
assert (find_bytes(data, "ะเ") == some( 6u));
1749+
assert (find_bytes(data, "中华") == some(27u));
1750+
assert (find_bytes(data, "ไท华") == none);
17491751
}
17501752

17511753
#[test]
17521754
fn test_find() {
17531755
// char positions
1754-
assert (find("banana", "apple pie") == option::none);
1755-
assert (find("", "") == option::some(0u));
1756+
assert (find("banana", "apple pie") == none);
1757+
assert (find("", "") == some(0u));
17561758

17571759
let data = "ประเทศไทย中华Việt Nam";
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);
1760+
assert (find(data, "") == some(0u));
1761+
assert (find(data, "ประเ") == some(0u));
1762+
assert (find(data, "ะเ") == some(2u));
1763+
assert (find(data, "中华") == some(9u));
1764+
assert (find(data, "ไท华") == none);
17631765
}
17641766

17651767
#[test]

0 commit comments

Comments
 (0)