Skip to content

Commit 9af02c3

Browse files
committed
---
yaml --- r: 11938 b: refs/heads/master c: f80008f h: refs/heads/master v: v3
1 parent a24e935 commit 9af02c3

File tree

2 files changed

+248
-33
lines changed

2 files changed

+248
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f6a792585b6311ea6cc9f73f8735116bf8246f5b
2+
refs/heads/master: f80008f04b9be5aa57d055d57ef1ab77684f4aea
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libcore/str.rs

Lines changed: 247 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ fn words_iter(ss: str, ff: fn(&&str)) {
664664
vec::iter(words(ss), ff)
665665
}
666666

667-
#[doc = "Apply a function to each lines (by '\\n')"]
667+
#[doc = "Apply a function to each line (by '\\n')"]
668668
fn lines_iter(ss: str, ff: fn(&&str)) {
669669
vec::iter(lines(ss), ff)
670670
}
@@ -674,23 +674,66 @@ Section: Searching
674674
*/
675675

676676
#[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
678688
"]
679689
fn find_char(s: str, c: char) -> option<uint> {
680690
find_char_between(s, c, 0u, len(s))
681691
}
682692

683693
#[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`.
686712
"]
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))
689715
}
690716

691717
#[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`.
694737
"]
695738
fn find_char_between(s: str, c: char, start: uint, end: uint)
696739
-> option<uint> {
@@ -710,24 +753,66 @@ fn find_char_between(s: str, c: char, start: uint, end: uint)
710753
}
711754

712755
#[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
714767
"]
715768
fn rfind_char(s: str, c: char) -> option<uint> {
716769
rfind_char_between(s, c, len(s), 0u)
717770
}
718771

719772
#[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`.
722791
"]
723792
fn rfind_char_from(s: str, c: char, start: uint) -> option<uint> {
724793
rfind_char_between(s, c, start, 0u)
725794
}
726795

727796
#[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`.
731816
"]
732817
fn rfind_char_between(s: str, c: char, start: uint, end: uint)
733818
-> option<uint> {
@@ -747,24 +832,68 @@ fn rfind_char_between(s: str, c: char, start: uint, end: uint)
747832
}
748833

749834
#[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
752847
"]
753848
fn find(s: str, f: fn(char) -> bool) -> option<uint> {
754849
find_between(s, 0u, len(s), f)
755850
}
756851

757852
#[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`.
760871
"]
761872
fn find_from(s: str, start: uint, f: fn(char) -> bool) -> option<uint> {
762873
find_between(s, start, len(s), f)
763874
}
764875

765876
#[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`.
768897
"]
769898
fn find_between(s: str, start: uint, end: uint, f: fn(char) -> bool)
770899
-> option<uint> {
@@ -781,25 +910,68 @@ fn find_between(s: str, start: uint, end: uint, f: fn(char) -> bool)
781910
}
782911

783912
#[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
785914
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
786925
"]
787926
fn rfind(s: str, f: fn(char) -> bool) -> option<uint> {
788927
rfind_between(s, len(s), 0u, f)
789928
}
790929

791930
#[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`
794949
"]
795950
fn rfind_from(s: str, start: uint, f: fn(char) -> bool) -> option<uint> {
796951
rfind_between(s, start, 0u, f)
797952
}
798953

799954
#[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`
803975
"]
804976
fn rfind_between(s: str, start: uint, end: uint, f: fn(char) -> bool)
805977
-> option<uint> {
@@ -823,25 +995,65 @@ fn match_at(haystack: str, needle: str, at: uint) -> bool {
823995
}
824996

825997
#[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
8281009
"]
8291010
fn find_str(haystack: str, needle: str) -> option<uint> {
8301011
find_str_between(haystack, needle, 0u, len(haystack))
8311012
}
8321013

8331014
#[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)`
8361032
"]
8371033
fn find_str_from(haystack: str, needle: str, start: uint)
8381034
-> option<uint> {
8391035
find_str_between(haystack, needle, start, len(haystack))
8401036
}
8411037

8421038
#[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)`.
8451057
"]
8461058
fn find_str_between(haystack: str, needle: str, start: uint, end:uint)
8471059
-> option<uint> {
@@ -1413,6 +1625,9 @@ mod unsafe {
14131625
ret b;
14141626
}
14151627

1628+
#[doc = "
1629+
Sets the length of the string and adds the null terminator
1630+
"]
14161631
unsafe fn set_len(&v: str, new_len: uint) {
14171632
let repr: *vec::unsafe::vec_repr = ::unsafe::reinterpret_cast(v);
14181633
(*repr).fill = new_len + 1u;

0 commit comments

Comments
 (0)