mirror of
https://github.com/typst/typst
synced 2025-08-23 19:24:14 +08:00
Add links and examples in the docs of str
(#6751)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
e1c9fc36a5
commit
c7938e93dc
@ -42,9 +42,10 @@ pub use crate::__format_str as format_str;
|
|||||||
/// [joined together]($scripting/#blocks) and multiplied with integers.
|
/// [joined together]($scripting/#blocks) and multiplied with integers.
|
||||||
///
|
///
|
||||||
/// Typst provides utility methods for string manipulation. Many of these
|
/// Typst provides utility methods for string manipulation. Many of these
|
||||||
/// methods (e.g., `split`, `trim` and `replace`) operate on _patterns:_ A
|
/// methods (e.g., [`split`]($str.split), [`trim`]($str.trim) and
|
||||||
/// pattern can be either a string or a [regular expression]($regex). This makes
|
/// [`replace`]($str.replace)) operate on _patterns:_ A pattern can be either a
|
||||||
/// the methods quite versatile.
|
/// string or a [regular expression]($regex). This makes the methods quite
|
||||||
|
/// versatile.
|
||||||
///
|
///
|
||||||
/// All lengths and indices are expressed in terms of UTF-8 bytes. Indices are
|
/// All lengths and indices are expressed in terms of UTF-8 bytes. Indices are
|
||||||
/// zero-based and negative indices wrap around to the end of the string.
|
/// zero-based and negative indices wrap around to the end of the string.
|
||||||
@ -422,6 +423,17 @@ impl Str {
|
|||||||
/// group. The first item of the array contains the first matched
|
/// group. The first item of the array contains the first matched
|
||||||
/// capturing, not the whole match! This is empty unless the `pattern` was
|
/// capturing, not the whole match! This is empty unless the `pattern` was
|
||||||
/// a regex with capturing groups.
|
/// a regex with capturing groups.
|
||||||
|
///
|
||||||
|
/// ```example
|
||||||
|
/// #assert.eq("Is there a".match("for this?"), none)
|
||||||
|
/// #"The time of my life.".match(regex("[mit]+e"))
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```example
|
||||||
|
/// #let pat = regex("not (a|an) (apple|cat)")
|
||||||
|
/// #"I'm a doctor, not an apple.".match(pat) \
|
||||||
|
/// #"I am not a cat!".match(pat)
|
||||||
|
/// ```
|
||||||
#[func]
|
#[func]
|
||||||
pub fn match_(
|
pub fn match_(
|
||||||
&self,
|
&self,
|
||||||
@ -438,7 +450,11 @@ impl Str {
|
|||||||
|
|
||||||
/// Searches for the specified pattern in the string and returns an array of
|
/// Searches for the specified pattern in the string and returns an array of
|
||||||
/// dictionaries with details about all matches. For details about the
|
/// dictionaries with details about all matches. For details about the
|
||||||
/// returned dictionaries, see above.
|
/// returned dictionaries, see [above]($str.match).
|
||||||
|
///
|
||||||
|
/// ```example
|
||||||
|
/// #"Day by Day.".matches("Day")
|
||||||
|
/// ```
|
||||||
#[func]
|
#[func]
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
@ -473,6 +489,9 @@ impl Str {
|
|||||||
/// The string to replace the matches with or a function that gets a
|
/// The string to replace the matches with or a function that gets a
|
||||||
/// dictionary for each match and can return individual replacement
|
/// dictionary for each match and can return individual replacement
|
||||||
/// strings.
|
/// strings.
|
||||||
|
///
|
||||||
|
/// The dictionary passed to the function has the same shape as the
|
||||||
|
/// dictionary returned by [`match`]($str.match).
|
||||||
replacement: Replacement,
|
replacement: Replacement,
|
||||||
/// If given, only the first `count` matches of the pattern are placed.
|
/// If given, only the first `count` matches of the pattern are placed.
|
||||||
#[named]
|
#[named]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user