File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -920,7 +920,7 @@ fn find(haystack: str, needle: str) -> option<uint> {
920
920
// Convert a byte position into a char position
921
921
// within a given string
922
922
fn b2c_pos ( ss : str , bpos : uint ) -> uint {
923
- assert bpos < len_bytes ( ss) ;
923
+ assert bpos == 0 u || bpos < len_bytes ( ss) ;
924
924
925
925
let ii = 0 u;
926
926
let cpos = 0 u;
@@ -1725,6 +1725,9 @@ mod tests {
1725
1725
#[ test]
1726
1726
fn test_find_bytes ( ) {
1727
1727
// byte positions
1728
+ assert ( find_bytes ( "banana" , "apple pie" ) == option:: none) ;
1729
+ assert ( find_bytes ( "" , "" ) == option:: some ( 0 u) ) ;
1730
+
1728
1731
let data = "ประเทศไทย中华Việt Nam" ;
1729
1732
assert ( find_bytes ( data, "" ) == option:: some ( 0 u) ) ;
1730
1733
assert ( find_bytes ( data, "ประเ" ) == option:: some ( 0 u) ) ;
@@ -1736,6 +1739,9 @@ mod tests {
1736
1739
#[ test]
1737
1740
fn test_find ( ) {
1738
1741
// char positions
1742
+ assert ( find ( "banana" , "apple pie" ) == option:: none) ;
1743
+ assert ( find ( "" , "" ) == option:: some ( 0 u) ) ;
1744
+
1739
1745
let data = "ประเทศไทย中华Việt Nam" ;
1740
1746
assert ( find ( data, "" ) == option:: some ( 0 u) ) ;
1741
1747
assert ( find ( data, "ประเ" ) == option:: some ( 0 u) ) ;
You can’t perform that action at this time.
0 commit comments