@@ -9,6 +9,8 @@ for correctness, but some UTF-8 unsafe functions are also provided.
99For some heavy-duty uses, we recommend trying std::rope.
1010*/
1111
12+ import option:: { some, none} ;
13+
1214export
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, 0 u, 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 += 1 u;
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 == 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; }
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 = 0 u;
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 += 1 u;
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
923925fn 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 ( 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) ;
15291531 }
15301532
15311533 #[ test]
15321534 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) ;
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 ( 0 u) ) ;
1742+ assert ( find_bytes ( "banana" , "apple pie" ) == none) ;
1743+ assert ( find_bytes ( "" , "" ) == some ( 0 u) ) ;
17421744
17431745 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) ;
17491751 }
17501752
17511753 #[ test]
17521754 fn test_find ( ) {
17531755 // 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) ) ;
17561758
17571759 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) ;
17631765 }
17641766
17651767 #[ test]
0 commit comments