Repository: TabbyML/tabby
File: ee/tabby-webserver/src/service/utils/prompt.rs (Rust)

Code before:
        .map(|x| x.to_owned())
        .collect()
}

/// Trims leading and trailing bullet-like characters or digits from the provided string and returns the trimmed result.
fn trim_bullet(s: &str) -> &str {
    let s = s.trim();
    if s.starts_with('-') || s.starts_with('+') || s.starts_with('*') {
        return s.trim_matches(&['-', '+', '*', ' '][..]);
    }

    // Check for numbered list
    if let Some(pos) = s.find(". ") {
        let prefix = &s[..pos];
        if prefix.chars().all(|c| c.is_numeric()) {
            return trim_bullet(s[pos + 2..].trim_start());
        }
    }

    s
}

pub fn trim_title(title: &str) -> &str {
    // take first line.
    let title = title.lines().next().unwrap_or(title).trim();
    trim_bullet(title.trim_matches(&['"', '#', ' ', '-', '*'][..]))
}

/// Checks if the `check` string is contained within `content` in a case-insensitive manner.
pub fn detect_content(content: &str, check: &str) -> bool {
    content.to_lowercase().contains(check)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_trim_bullet() {
        assert_eq!(trim_bullet("- Hello"), "Hello");
        assert_eq!(trim_bullet("* World"), "World");
        assert_eq!(trim_bullet("1. Test"), "Test");

        assert_eq!(trim_bullet("- Hello -"), "Hello");
        assert_eq!(trim_bullet("1. Test 1"), "Test 1");
        assert_eq!(trim_bullet("12. Test 1"), "Test 1");
        assert_eq!(trim_bullet("1. Test 1."), "Test 1.");
        assert_eq!(trim_bullet("1 Test "), "1 Test");

        assert_eq!(trim_bullet("--** Mixed"), "Mixed");


Review comment (suggestion):
```suggestion
   title.trim_matches(&['"', '#'][..])
```

remove chars handled by trim_bullet

Code after:
        .map(|x| x.to_owned())
        .collect()
}

/// Trims leading and trailing bullet-like characters or digits from the provided string and returns the trimmed result.
fn trim_bullet(s: &str) -> &str {
    let s = s.trim().trim_matches(['-', '+', '*', ' ']).trim();

    // Check for numbered list, like "1. Hello", "12. Hello"
    if let Some(pos) = s.find(". ") {
        let prefix = &s[..pos];
        if prefix.chars().all(|c| c.is_numeric()) {
            return trim_bullet(s[pos + 2..].trim_start());
        }
    }

    s
}

pub fn trim_title(title: &str) -> &str {
    // take first line.
    let title = title.lines().next().unwrap_or(title).trim();
    trim_bullet(title.trim_matches(&['"', '#'][..]))
}

/// Checks if the `check` string is contained within `content` in a case-insensitive manner.
pub fn detect_content(content: &str, check: &str) -> bool {
    content.to_lowercase().contains(check)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_trim_bullet() {
        assert_eq!(trim_bullet("- Hello"), "Hello");
        assert_eq!(trim_bullet("* World"), "World");
        assert_eq!(trim_bullet("1. Test"), "Test");

        assert_eq!(trim_bullet("- Hello -"), "Hello");
        assert_eq!(trim_bullet("1. Test 1"), "Test 1");
        assert_eq!(trim_bullet("12. Test 1"), "Test 1");
        assert_eq!(trim_bullet("1. Test 1."), "Test 1.");
        assert_eq!(trim_bullet("1 Test "), "1 Test");

        assert_eq!(trim_bullet("--** Mixed"), "Mixed");

        assert_eq!(trim_bullet("  - Hello  "), "Hello");

        assert_eq!(trim_bullet("-"), "");