@@ -9,6 +9,8 @@ for correctness, but some UTF-8 unsafe functions are also provided.
9
9
For some heavy-duty uses, we recommend trying std::rope.
10
10
*/
11
11
12
+ import option:: { some, none} ;
13
+
12
14
export
13
15
// Creating a string
14
16
from_bytes,
@@ -665,8 +667,8 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe {
665
667
} else {
666
668
let idx;
667
669
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; }
670
672
}
671
673
let before = unsafe :: slice_bytes ( s, 0 u, idx as uint ) ;
672
674
let after = unsafe :: slice_bytes ( s, idx as uint + len_bytes ( from) ,
@@ -842,15 +844,15 @@ fn index(ss: str, cc: char) -> option<uint> {
842
844
843
845
// found here?
844
846
if ch == cc {
845
- ret option :: some ( cii) ;
847
+ ret some ( cii) ;
846
848
}
847
849
848
850
cii += 1 u;
849
851
bii = next;
850
852
}
851
853
852
854
// wasn't found
853
- ret option :: none;
855
+ ret none;
854
856
}
855
857
856
858
// Function: byte_index
@@ -880,12 +882,12 @@ fn rindex(ss: str, cc: char) -> option<uint> {
880
882
881
883
// found here?
882
884
if ch == cc {
883
- ret option :: some ( cii) ;
885
+ ret some ( cii) ;
884
886
}
885
887
}
886
888
887
889
// wasn't found
888
- ret option :: none;
890
+ ret none;
889
891
}
890
892
891
893
//Function: find_bytes
@@ -898,8 +900,8 @@ fn find_bytes(haystack: str, needle: str) -> option<uint> {
898
900
let haystack_len = len_bytes ( haystack) ;
899
901
let needle_len = len_bytes ( needle) ;
900
902
901
- if needle_len == 0 u { ret option :: some ( 0 u) ; }
902
- if needle_len > haystack_len { ret option :: none; }
903
+ if needle_len == 0 u { ret some ( 0 u) ; }
904
+ if needle_len > haystack_len { ret none; }
903
905
904
906
fn match_at ( haystack : str , needle : str , ii : uint ) -> bool {
905
907
let jj = ii;
@@ -909,11 +911,11 @@ fn find_bytes(haystack: str, needle: str) -> option<uint> {
909
911
910
912
let ii = 0 u;
911
913
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) ; }
913
915
ii += 1 u;
914
916
}
915
917
916
- ret option :: none;
918
+ ret none;
917
919
}
918
920
919
921
// Function: find
@@ -922,8 +924,8 @@ fn find_bytes(haystack: str, needle: str) -> option<uint> {
922
924
// within another, or return option::none
923
925
fn find ( haystack : str , needle : str ) -> option < uint > {
924
926
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) ) ; }
927
929
}
928
930
}
929
931
@@ -1522,18 +1524,18 @@ mod tests {
1522
1524
1523
1525
#[ test]
1524
1526
fn test_index ( ) {
1525
- assert ( index ( "hello" , 'h' ) == option :: some ( 0 u) ) ;
1526
- assert ( index ( "hello" , 'e' ) == option :: some ( 1 u) ) ;
1527
- assert ( index ( "hello" , 'o' ) == option :: some ( 4 u) ) ;
1528
- assert ( index ( "hello" , 'z' ) == option :: none) ;
1527
+ assert ( index ( "hello" , 'h' ) == some ( 0 u) ) ;
1528
+ assert ( index ( "hello" , 'e' ) == some ( 1 u) ) ;
1529
+ assert ( index ( "hello" , 'o' ) == some ( 4 u) ) ;
1530
+ assert ( index ( "hello" , 'z' ) == none) ;
1529
1531
}
1530
1532
1531
1533
#[ test]
1532
1534
fn test_rindex ( ) {
1533
- assert ( rindex ( "hello" , 'l' ) == option :: some ( 3 u) ) ;
1534
- assert ( rindex ( "hello" , 'o' ) == option :: some ( 4 u) ) ;
1535
- assert ( rindex ( "hello" , 'h' ) == option :: some ( 0 u) ) ;
1536
- assert ( rindex ( "hello" , 'z' ) == option :: none) ;
1535
+ assert ( rindex ( "hello" , 'l' ) == some ( 3 u) ) ;
1536
+ assert ( rindex ( "hello" , 'o' ) == some ( 4 u) ) ;
1537
+ assert ( rindex ( "hello" , 'h' ) == some ( 0 u) ) ;
1538
+ assert ( rindex ( "hello" , 'z' ) == none) ;
1537
1539
}
1538
1540
1539
1541
#[ test]
@@ -1737,29 +1739,29 @@ mod tests {
1737
1739
#[ test]
1738
1740
fn test_find_bytes ( ) {
1739
1741
// byte positions
1740
- assert ( find_bytes ( "banana" , "apple pie" ) == option :: none) ;
1741
- assert ( find_bytes ( "" , "" ) == option :: some ( 0 u) ) ;
1742
+ assert ( find_bytes ( "banana" , "apple pie" ) == none) ;
1743
+ assert ( find_bytes ( "" , "" ) == some ( 0 u) ) ;
1742
1744
1743
1745
let data = "ประเทศไทย中华Việt Nam" ;
1744
- assert ( find_bytes ( data, "" ) == option :: some ( 0 u) ) ;
1745
- assert ( find_bytes ( data, "ประเ" ) == option :: some ( 0 u) ) ;
1746
- assert ( find_bytes ( data, "ะเ" ) == option :: some ( 6 u) ) ;
1747
- assert ( find_bytes ( data, "中华" ) == option :: some ( 27 u) ) ;
1748
- assert ( find_bytes ( data, "ไท华" ) == option :: none) ;
1746
+ assert ( find_bytes ( data, "" ) == some ( 0 u) ) ;
1747
+ assert ( find_bytes ( data, "ประเ" ) == some ( 0 u) ) ;
1748
+ assert ( find_bytes ( data, "ะเ" ) == some ( 6 u) ) ;
1749
+ assert ( find_bytes ( data, "中华" ) == some ( 27 u) ) ;
1750
+ assert ( find_bytes ( data, "ไท华" ) == none) ;
1749
1751
}
1750
1752
1751
1753
#[ test]
1752
1754
fn test_find ( ) {
1753
1755
// char positions
1754
- assert ( find ( "banana" , "apple pie" ) == option :: none) ;
1755
- assert ( find ( "" , "" ) == option :: some ( 0 u) ) ;
1756
+ assert ( find ( "banana" , "apple pie" ) == none) ;
1757
+ assert ( find ( "" , "" ) == some ( 0 u) ) ;
1756
1758
1757
1759
let data = "ประเทศไทย中华Việt Nam" ;
1758
- assert ( find ( data, "" ) == option :: some ( 0 u) ) ;
1759
- assert ( find ( data, "ประเ" ) == option :: some ( 0 u) ) ;
1760
- assert ( find ( data, "ะเ" ) == option :: some ( 2 u) ) ;
1761
- assert ( find ( data, "中华" ) == option :: some ( 9 u) ) ;
1762
- assert ( find ( data, "ไท华" ) == option :: none) ;
1760
+ assert ( find ( data, "" ) == some ( 0 u) ) ;
1761
+ assert ( find ( data, "ประเ" ) == some ( 0 u) ) ;
1762
+ assert ( find ( data, "ะเ" ) == some ( 2 u) ) ;
1763
+ assert ( find ( data, "中华" ) == some ( 9 u) ) ;
1764
+ assert ( find ( data, "ไท华" ) == none) ;
1763
1765
}
1764
1766
1765
1767
#[ test]
0 commit comments