INNER CODE UNIT · Rust

improve_query

aome510/spotify-player · lyric_finder/src/lib.rs:152

fn improve_query(query: &str) -> String {
    // flag for doing something wrong if the song name (after removing remix metadata) is too short.
    const SONG_MIN_LENGTH_WO_REMIX_METADATA: usize = 3;

    let is_dash = |c: char| c == '-';

    // reverse finder for non-filler (space, dashes) chars before an index.
    // Acts like a trim to remove undesired spaces and dashes.
    let rfind_non_filler = |s: &str, idx: usize| {
        let Some(s) = s.get(..idx) else { return idx };
        s.char_indices()
            .rfind(|(_, c)| !(is_dash(*c) || c.is_whitespace()))
            .map_or(idx, |(idx, c)| idx + c.len_utf8())
    };
    // used to handle longer variants of words: `remixed`, `remastered`, etc.
    let end_of_word = |s: &str, idx: usize| {
        let Some(s) = s.get(idx..) else { return idx };
        s.find(|c: char| !c.is_alphanumeric())

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…