Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ca61fd56
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ca61fd56
编写于
4月 19, 2020
作者:
E
Eric Huss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update pattern docs.
上级
1b7dec9e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
150 addition
and
37 deletion
+150
-37
src/libcore/str/mod.rs
src/libcore/str/mod.rs
+115
-36
src/libcore/str/pattern.rs
src/libcore/str/pattern.rs
+35
-1
未找到文件。
src/libcore/str/mod.rs
浏览文件 @
ca61fd56
...
...
@@ -3010,6 +3010,12 @@ pub fn encode_utf16(&self) -> EncodeUtf16<'_> {
///
/// Returns `false` if it does not.
///
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
/// Basic usage:
...
...
@@ -3031,6 +3037,12 @@ pub fn contains<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
///
/// Returns `false` if it does not.
///
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
/// Basic usage:
...
...
@@ -3051,6 +3063,12 @@ pub fn starts_with<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
///
/// Returns `false` if it does not.
///
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
/// Basic usage:
...
...
@@ -3074,10 +3092,12 @@ pub fn ends_with<'a, P>(&'a self, pat: P) -> bool
///
/// Returns [`None`] if the pattern doesn't match.
///
/// The
pattern can be a `&str`, [`char`], or a closure that determines if
/// a character matches.
/// The
[pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
///
function or closure that determines if
a character matches.
///
/// [`None`]: option/enum.Option.html#variant.None
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
...
...
@@ -3121,10 +3141,12 @@ pub fn find<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize> {
///
/// Returns [`None`] if the pattern doesn't match.
///
/// The
pattern can be a `&str`, [`char`], or a closure that determines if
/// a character matches.
/// The
[pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
///
function or closure that determines if
a character matches.
///
/// [`None`]: option/enum.Option.html#variant.None
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
...
...
@@ -3166,8 +3188,11 @@ pub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize>
/// An iterator over substrings of this string slice, separated by
/// characters matched by a pattern.
///
/// The pattern can be any type that implements the Pattern trait. Notable
/// examples are `&str`, [`char`], and closures that determines the split.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Iterator behavior
///
...
...
@@ -3285,6 +3310,12 @@ pub fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> {
/// `split` in that `split_inclusive` leaves the matched part as the
/// terminator of the substring.
///
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
/// ```
...
...
@@ -3319,8 +3350,11 @@ pub fn split_inclusive<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitInclusive<'
/// An iterator over substrings of the given string slice, separated by
/// characters matched by a pattern and yielded in reverse order.
///
/// The pattern can be any type that implements the Pattern trait. Notable
/// examples are `&str`, [`char`], and closures that determines the split.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Iterator behavior
///
...
...
@@ -3370,8 +3404,11 @@ pub fn rsplit<'a, P>(&'a self, pat: P) -> RSplit<'a, P>
/// An iterator over substrings of the given string slice, separated by
/// characters matched by a pattern.
///
/// The pattern can be any type that implements the Pattern trait. Notable
/// examples are `&str`, [`char`], and closures that determines the split.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// Equivalent to [`split`], except that the trailing substring
/// is skipped if empty.
...
...
@@ -3414,10 +3451,11 @@ pub fn split_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitTerminator
/// An iterator over substrings of `self`, separated by characters
/// matched by a pattern and yielded in reverse order.
///
/// The pattern can be any type that implements the Pattern trait. Notable
/// examples are `&str`, [`char`], and closures that determines the split.
/// Additional libraries might provide more complex patterns like
/// regular expressions.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// Equivalent to [`split`], except that the trailing substring is
/// skipped if empty.
...
...
@@ -3462,8 +3500,11 @@ pub fn rsplit_terminator<'a, P>(&'a self, pat: P) -> RSplitTerminator<'a, P>
/// If `n` substrings are returned, the last substring (the `n`th substring)
/// will contain the remainder of the string.
///
/// The pattern can be any type that implements the Pattern trait. Notable
/// examples are `&str`, [`char`], and closures that determines the split.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Iterator behavior
///
...
...
@@ -3512,8 +3553,11 @@ pub fn splitn<'a, P: Pattern<'a>>(&'a self, n: usize, pat: P) -> SplitN<'a, P> {
/// If `n` substrings are returned, the last substring (the `n`th substring)
/// will contain the remainder of the string.
///
/// The pattern can be any type that implements the Pattern trait. Notable
/// examples are `&str`, [`char`], and closures that determines the split.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Iterator behavior
///
...
...
@@ -3557,8 +3601,11 @@ pub fn rsplitn<'a, P>(&'a self, n: usize, pat: P) -> RSplitN<'a, P>
/// An iterator over the disjoint matches of a pattern within the given string
/// slice.
///
/// The pattern can be a `&str`, [`char`], or a closure that determines if
/// a character matches.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Iterator behavior
///
...
...
@@ -3593,8 +3640,11 @@ pub fn matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> Matches<'a, P> {
/// An iterator over the disjoint matches of a pattern within this string slice,
/// yielded in reverse order.
///
/// The pattern can be a `&str`, [`char`], or a closure that determines if
/// a character matches.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Iterator behavior
///
...
...
@@ -3634,8 +3684,11 @@ pub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P>
/// For matches of `pat` within `self` that overlap, only the indices
/// corresponding to the first match are returned.
///
/// The pattern can be a `&str`, [`char`], or a closure that determines
/// if a character matches.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Iterator behavior
///
...
...
@@ -3676,8 +3729,11 @@ pub fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P
/// For matches of `pat` within `self` that overlap, only the indices
/// corresponding to the last match are returned.
///
/// The pattern can be a `&str`, [`char`], or a closure that determines if a
/// character matches.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Iterator behavior
///
...
...
@@ -3894,8 +3950,11 @@ pub fn trim_right(&self) -> &str {
/// Returns a string slice with all prefixes and suffixes that match a
/// pattern repeatedly removed.
///
/// The pattern can be a [`char`] or a closure that determines if a
/// character matches.
/// The [pattern] can be a [`char`], a slice of [`char`]s, or a function
/// or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
...
...
@@ -3939,8 +3998,11 @@ pub fn trim_matches<'a, P>(&'a self, pat: P) -> &'a str
/// Returns a string slice with all prefixes that match a pattern
/// repeatedly removed.
///
/// The pattern can be a `&str`, [`char`], or a closure that determines if
/// a character matches.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Text directionality
///
...
...
@@ -3981,6 +4043,12 @@ pub fn trim_start_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str {
///
/// If the string does not start with `prefix`, `None` is returned.
///
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
/// ```
...
...
@@ -4005,6 +4073,12 @@ pub fn strip_prefix<'a, P: Pattern<'a>>(&'a self, prefix: P) -> Option<&'a str>
///
/// If the string does not end with `suffix`, `None` is returned.
///
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Examples
///
/// ```
...
...
@@ -4027,8 +4101,11 @@ pub fn strip_suffix<'a, P>(&'a self, suffix: P) -> Option<&'a str>
/// Returns a string slice with all suffixes that match a pattern
/// repeatedly removed.
///
/// The pattern can be a `&str`, [`char`], or a closure that
/// determines if a character matches.
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Text directionality
///
...
...
@@ -4073,10 +4150,11 @@ pub fn trim_end_matches<'a, P>(&'a self, pat: P) -> &'a str
/// Returns a string slice with all prefixes that match a pattern
/// repeatedly removed.
///
/// The
pattern can be a `&str`, [`char`], or a closure that determines if
/// a character matches.
/// The
[pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
///
function or closure that determines if
a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Text directionality
///
...
...
@@ -4109,10 +4187,11 @@ pub fn trim_left_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str {
/// Returns a string slice with all suffixes that match a pattern
/// repeatedly removed.
///
/// The
pattern can be a `&str`, [`char`], or a closure that
/// determines if a character matches.
/// The
[pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
///
function or closure that
determines if a character matches.
///
/// [`char`]: primitive.char.html
/// [pattern]: str/pattern/index.html
///
/// # Text directionality
///
...
...
src/libcore/str/pattern.rs
浏览文件 @
ca61fd56
//! The string Pattern API.
//!
//! The Pattern API provides a generic mechanism for using different pattern
//! types when searching through a string.
//!
//! For more details, see the traits [`Pattern`], [`Searcher`],
//! [`ReverseSearcher`], and [`DoubleEndedSearcher`].
//!
//! Although this API is unstable, it is exposed via stable APIs on the
//! [`str`] type.
//!
//! # Examples
//!
//! [`Pattern`] is [implemented][pattern-impls] in the stable API for
//! [`&str`], [`char`], slices of [`char`], and functions and closures
//! implementing `FnMut(char) -> bool`.
//!
//! ```
//! let s = "Can you find a needle in a haystack?";
//!
//! // &str pattern
//! assert_eq!(s.find("you"), Some(4));
//! // char pattern
//! assert_eq!(s.find('n'), Some(2));
//! // slice of chars pattern
//! assert_eq!(s.find(&['a', 'e', 'i', 'o', 'u'][..]), Some(1));
//! // closure pattern
//! assert_eq!(s.find(|c: char| c.is_ascii_punctuation()), Some(35));
//! ```
//!
//! [`&str`]: ../../../std/primitive.str.html
//! [`char`]: ../../../std/primitive.char.html
//! [`str`]: ../../../std/primitive.str.html
//! [`DoubleEndedSearcher`]: trait.DoubleEndedSearcher.html
//! [`Pattern`]: trait.Pattern.html
//! [`ReverseSearcher`]: trait.ReverseSearcher.html
//! [`Searcher`]: trait.Searcher.html
//! [pattern-impls]: trait.Pattern.html#implementors
#![unstable(
feature
=
"pattern"
,
...
...
@@ -702,7 +736,7 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
impl
<
'a
,
'b
>
DoubleEndedSearcher
<
'a
>
for
CharSliceSearcher
<
'a
,
'b
>
{}
/// Searches for chars that are equal to any of the chars in the
array
.
/// Searches for chars that are equal to any of the chars in the
slice
.
///
/// # Examples
///
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录