Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify the matching pat in replacement documentation #1983

Open
nyurik opened this issue Mar 29, 2024 · 1 comment
Open

clarify the matching pat in replacement documentation #1983

nyurik opened this issue Mar 29, 2024 · 1 comment

Comments

@nyurik
Copy link
Contributor

nyurik commented Mar 29, 2024

String manipulation contains this section which is not very clear. Does pat refer to an exact string match, e.g. removing trim_end_match("foobar", "bar") would result in "foo", or does it support some pattern matching (as the variable name would imply)? I tried it with regex, but it seems like it is not working.

trim_end_match(s, pat) - Remove suffix of s matching pat.
trim_end_matches(s, pat) - Repeatedly remove suffixes of s matching pat.
trim_start_match(s, pat) - Remove prefix of s matching pat.
trim_start_matches(s, pat) - Repeatedly remove prefixes of s matching pat.
@laniakea64
Copy link
Contributor

It's an exact string match. These functions call Rust functions for these jobs, passing them the pat parameter string as-is:

just/src/function.rs

Lines 429 to 435 in d3d0dbe

fn trim_end_match(_context: &FunctionContext, s: &str, pat: &str) -> Result<String, String> {
Ok(s.strip_suffix(pat).unwrap_or(s).to_owned())
}
fn trim_end_matches(_context: &FunctionContext, s: &str, pat: &str) -> Result<String, String> {
Ok(s.trim_end_matches(pat).to_owned())
}

just/src/function.rs

Lines 441 to 447 in d3d0dbe

fn trim_start_match(_context: &FunctionContext, s: &str, pat: &str) -> Result<String, String> {
Ok(s.strip_prefix(pat).unwrap_or(s).to_owned())
}
fn trim_start_matches(_context: &FunctionContext, s: &str, pat: &str) -> Result<String, String> {
Ok(s.trim_start_matches(pat).to_owned())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants