@@ -664,7 +664,7 @@ fn words_iter(ss: str, ff: fn(&&str)) {
664
664
vec:: iter ( words ( ss) , ff)
665
665
}
666
666
667
- #[ doc = "Apply a function to each lines (by '\\ n')" ]
667
+ #[ doc = "Apply a function to each line (by '\\ n')" ]
668
668
fn lines_iter ( ss : str , ff : fn ( & & str ) ) {
669
669
vec:: iter ( lines ( ss) , ff)
670
670
}
@@ -674,23 +674,66 @@ Section: Searching
674
674
*/
675
675
676
676
#[ doc = "
677
- Returns the byte index of the first matching char (as option some/none)
677
+ Returns the byte index of the first matching character
678
+
679
+ # Arguments
680
+
681
+ * `s` - The string to search
682
+ * `c` - The character to search for
683
+
684
+ # Return value
685
+
686
+ An `option` containing the byte index of the first matching character
687
+ or `none` if there is no match
678
688
" ]
679
689
fn find_char ( s : str , c : char ) -> option < uint > {
680
690
find_char_between ( s, c, 0 u, len ( s) )
681
691
}
682
692
683
693
#[ doc = "
684
- Returns the byte index of the first matching char as option
685
- some/none), starting from `start`
694
+ Returns the byte index of the first matching character beginning
695
+ from a given byte offset
696
+
697
+ # Arguments
698
+
699
+ * `s` - The string to search
700
+ * `c` - The character to search for
701
+ * `start` - The byte index to begin searching at, inclusive
702
+
703
+ # Return value
704
+
705
+ An `option` containing the byte index of the first matching character
706
+ or `none` if there is no match
707
+
708
+ # Failure
709
+
710
+ `start` must be less than or equal to `len(s)`. `start` must be the
711
+ index of a character boundary, as defined by `is_char_boundary`.
686
712
" ]
687
- fn find_char_from ( s : str , c : char , from : uint ) -> option < uint > {
688
- find_char_between ( s, c, from , len ( s) )
713
+ fn find_char_from ( s : str , c : char , start : uint ) -> option < uint > {
714
+ find_char_between ( s, c, start , len ( s) )
689
715
}
690
716
691
717
#[ doc = "
692
- Returns the byte index of the first matching char (as option
693
- some/none), between `start` and `end`
718
+ Returns the byte index of the first matching character within a given range
719
+
720
+ # Arguments
721
+
722
+ * `s` - The string to search
723
+ * `c` - The character to search for
724
+ * `start` - The byte index to begin searching at, inclusive
725
+ * `end` - The byte index to end searching at, exclusive
726
+
727
+ # Return value
728
+
729
+ An `option` containing the byte index of the first matching character
730
+ or `none` if there is no match
731
+
732
+ # Failure
733
+
734
+ `start` must be less than or equal to `end` and `end` must be less than
735
+ or equal to `len(s)`. `start` must be the index of a character boundary,
736
+ as defined by `is_char_boundary`.
694
737
" ]
695
738
fn find_char_between ( s : str , c : char , start : uint , end : uint )
696
739
-> option < uint > {
@@ -710,24 +753,66 @@ fn find_char_between(s: str, c: char, start: uint, end: uint)
710
753
}
711
754
712
755
#[ doc = "
713
- Returns the byte index of the last matching char as option some/none)
756
+ Returns the byte index of the last matching character
757
+
758
+ # Arguments
759
+
760
+ * `s` - The string to search
761
+ * `c` - The character to search for
762
+
763
+ # Return value
764
+
765
+ An `option` containing the byte index of the last matching character
766
+ or `none` if there is no match
714
767
" ]
715
768
fn rfind_char ( s : str , c : char ) -> option < uint > {
716
769
rfind_char_between ( s, c, len ( s) , 0 u)
717
770
}
718
771
719
772
#[ doc = "
720
- Returns the byte index of the last matching char (as option
721
- some/none), starting from `start`
773
+ Returns the byte index of the last matching character beginning
774
+ from a given byte offset
775
+
776
+ # Arguments
777
+
778
+ * `s` - The string to search
779
+ * `c` - The character to search for
780
+ * `start` - The byte index to begin searching at, exclusive
781
+
782
+ # Return value
783
+
784
+ An `option` containing the byte index of the last matching character
785
+ or `none` if there is no match
786
+
787
+ # Failure
788
+
789
+ `start` must be less than or equal to `len(s)`. `start` must be
790
+ the index of a character boundary, as defined by `is_char_boundary`.
722
791
" ]
723
792
fn rfind_char_from ( s : str , c : char , start : uint ) -> option < uint > {
724
793
rfind_char_between ( s, c, start, 0 u)
725
794
}
726
795
727
796
#[ doc = "
728
- Returns the byte index of the last matching char (as option
729
- some/none), between from `start` and `end` (start must be greater
730
- than or equal to end)
797
+ Returns the byte index of the last matching character within a given range
798
+
799
+ # Arguments
800
+
801
+ * `s` - The string to search
802
+ * `c` - The character to search for
803
+ * `start` - The byte index to begin searching at, exclusive
804
+ * `end` - The byte index to end searching at, inclusive
805
+
806
+ # Return value
807
+
808
+ An `option` containing the byte index of the last matching character
809
+ or `none` if there is no match
810
+
811
+ # Failure
812
+
813
+ `end` must be less than or equal to `start` and `start` must be less than
814
+ or equal to `len(s)`. `start` must be the index of a character boundary,
815
+ as defined by `is_char_boundary`.
731
816
" ]
732
817
fn rfind_char_between ( s : str , c : char , start : uint , end : uint )
733
818
-> option < uint > {
@@ -747,24 +832,68 @@ fn rfind_char_between(s: str, c: char, start: uint, end: uint)
747
832
}
748
833
749
834
#[ doc = "
750
- Returns, as an option, the first character that passes the given
751
- predicate
835
+ Returns the byte index of the first character that satisfies
836
+ the given predicate
837
+
838
+ # Arguments
839
+
840
+ * `s` - The string to search
841
+ * `f` - The predicate to satisfy
842
+
843
+ # Return value
844
+
845
+ An `option` containing the byte index of the first matching character
846
+ or `none` if there is no match
752
847
" ]
753
848
fn find ( s : str , f : fn ( char ) -> bool ) -> option < uint > {
754
849
find_between ( s, 0 u, len ( s) , f)
755
850
}
756
851
757
852
#[ doc = "
758
- Returns, as an option, the first character that passes the given
759
- predicate, starting at byte offset `start`
853
+ Returns the byte index of the first character that satisfies
854
+ the given predicate, beginning from a given byte offset
855
+
856
+ # Arguments
857
+
858
+ * `s` - The string to search
859
+ * `start` - The byte index to begin searching at, inclusive
860
+ * `f` - The predicate to satisfy
861
+
862
+ # Return value
863
+
864
+ An `option` containing the byte index of the first matching charactor
865
+ or `none` if there is no match
866
+
867
+ # Failure
868
+
869
+ `start` must be less than or equal to `len(s)`. `start` must be the
870
+ index of a character boundary, as defined by `is_char_boundary`.
760
871
" ]
761
872
fn find_from ( s : str , start : uint , f : fn ( char ) -> bool ) -> option < uint > {
762
873
find_between ( s, start, len ( s) , f)
763
874
}
764
875
765
876
#[ doc = "
766
- Returns, as an option, the first character that passes the given
767
- predicate, between byte offsets `start` and `end`
877
+ Returns the byte index of the first character that satisfies
878
+ the given predicate, within a given range
879
+
880
+ # Arguments
881
+
882
+ * `s` - The string to search
883
+ * `start` - The byte index to begin searching at, inclusive
884
+ * `end` - The byte index to end searching at, exclusive
885
+ * `f` - The predicate to satisfy
886
+
887
+ # Return value
888
+
889
+ An `option` containing the byte index of the first matching character
890
+ or `none` if there is no match
891
+
892
+ # Failure
893
+
894
+ `start` must be less than or equal to `end` and `end` must be less than
895
+ or equal to `len(s)`. `start` must be the index of a character
896
+ boundary, as defined by `is_char_boundary`.
768
897
" ]
769
898
fn find_between ( s : str , start : uint , end : uint , f : fn ( char ) -> bool )
770
899
-> option < uint > {
@@ -781,25 +910,68 @@ fn find_between(s: str, start: uint, end: uint, f: fn(char) -> bool)
781
910
}
782
911
783
912
#[ doc = "
784
- Returns, as an option, the last character in the string that passes
913
+ Returns the byte index of the last character that satisfies
785
914
the given predicate
915
+
916
+ # Arguments
917
+
918
+ * `s` - The string to search
919
+ * `f` - The predicate to satisfy
920
+
921
+ # Return value
922
+
923
+ An option containing the byte index of the last matching character
924
+ or `none` if there is no match
786
925
" ]
787
926
fn rfind ( s : str , f : fn ( char ) -> bool ) -> option < uint > {
788
927
rfind_between ( s, len ( s) , 0 u, f)
789
928
}
790
929
791
930
#[ doc = "
792
- Returns, as an option, the last character that passes the given
793
- predicate, up until byte offset `start`
931
+ Returns the byte index of the last character that satisfies
932
+ the given predicate, beginning from a given byte offset
933
+
934
+ # Arguments
935
+
936
+ * `s` - The string to search
937
+ * `start` - The byte index to begin searching at, exclusive
938
+ * `f` - The predicate to satisfy
939
+
940
+ # Return value
941
+
942
+ An `option` containing the byte index of the last matching character
943
+ or `none` if there is no match
944
+
945
+ # Failure
946
+
947
+ `start` must be less than or equal to `len(s)', `start` must be the
948
+ index of a character boundary, as defined by `is_char_boundary`
794
949
" ]
795
950
fn rfind_from ( s : str , start : uint , f : fn ( char ) -> bool ) -> option < uint > {
796
951
rfind_between ( s, start, 0 u, f)
797
952
}
798
953
799
954
#[ doc = "
800
- Returns, as an option, the last character that passes the given
801
- predicate, between byte offsets `start` and `end` (`start` must be
802
- greater than or equal to `end`)
955
+ Returns the byte index of the last character that satisfies
956
+ the given predicate, within a given range
957
+
958
+ # Arguments
959
+
960
+ * `s` - The string to search
961
+ * `start` - The byte index to begin searching at, exclusive
962
+ * `end` - The byte index to end searching at, inclusive
963
+ * `f` - The predicate to satisfy
964
+
965
+ # Return value
966
+
967
+ An `option` containing the byte index of the last matching character
968
+ or `none` if there is no match
969
+
970
+ # Failure
971
+
972
+ `end` must be less than or equal to `start` and `start` must be less
973
+ than or equal to `len(s)`. `start` must be the index of a character
974
+ boundary, as defined by `is_char_boundary`
803
975
" ]
804
976
fn rfind_between ( s : str , start : uint , end : uint , f : fn ( char ) -> bool )
805
977
-> option < uint > {
@@ -823,25 +995,65 @@ fn match_at(haystack: str, needle: str, at: uint) -> bool {
823
995
}
824
996
825
997
#[ doc = "
826
- Find the byte position of the first instance of one string
827
- within another, or return `option::none`
998
+ Returns the byte index of the first matching substring
999
+
1000
+ # Arguments
1001
+
1002
+ * `haystack` - The string to search
1003
+ * `needle` - The string to search for
1004
+
1005
+ # Return value
1006
+
1007
+ An `option` containing the byte index of the first matching substring
1008
+ or `none` if there is no match
828
1009
" ]
829
1010
fn find_str ( haystack : str , needle : str ) -> option < uint > {
830
1011
find_str_between ( haystack, needle, 0 u, len ( haystack) )
831
1012
}
832
1013
833
1014
#[ doc = "
834
- Find the byte position of the first instance of one string
835
- within another, or return `option::none`
1015
+ Returns the byte index of the first matching substring beginning
1016
+ from a given byte offset
1017
+
1018
+ # Arguments
1019
+
1020
+ * `haystack` - The string to search
1021
+ * `needle` - The string to search for
1022
+ * `start` - The byte index to begin searching at, inclusive
1023
+
1024
+ # Return value
1025
+
1026
+ An `option` containing the byte index of the last matching character
1027
+ or `none` if there is no match
1028
+
1029
+ # Failure
1030
+
1031
+ `start` must be less than or equal to `len(s)`
836
1032
" ]
837
1033
fn find_str_from ( haystack : str , needle : str , start : uint )
838
1034
-> option < uint > {
839
1035
find_str_between ( haystack, needle, start, len ( haystack) )
840
1036
}
841
1037
842
1038
#[ doc = "
843
- Find the byte position of the first instance of one string
844
- within another, or return `option::none`
1039
+ Returns the byte index of the first matching substring within a given range
1040
+
1041
+ # Arguments
1042
+
1043
+ * `haystack` - The string to search
1044
+ * `needle` - The string to search for
1045
+ * `start` - The byte index to begin searching at, inclusive
1046
+ * `end` - The byte index to end searching at, exclusive
1047
+
1048
+ # Return value
1049
+
1050
+ An `option` containing the byte index of the first matching character
1051
+ or `none` if there is no match
1052
+
1053
+ # Failure
1054
+
1055
+ `start` must be less than or equal to `end` and `end` must be less than
1056
+ or equal to `len(s)`.
845
1057
" ]
846
1058
fn find_str_between ( haystack : str , needle : str , start : uint , end : uint )
847
1059
-> option < uint > {
@@ -1413,6 +1625,9 @@ mod unsafe {
1413
1625
ret b;
1414
1626
}
1415
1627
1628
+ #[ doc = "
1629
+ Sets the length of the string and adds the null terminator
1630
+ " ]
1416
1631
unsafe fn set_len ( & v: str , new_len : uint ) {
1417
1632
let repr: * vec:: unsafe:: vec_repr = :: unsafe:: reinterpret_cast ( v) ;
1418
1633
( * repr) . fill = new_len + 1 u;
0 commit comments