rlvgl 0.2.4

A modular, idiomatic Rust reimplementation of the LVGL graphics library for embedded and simulator use.
Documentation
//! Utility helpers for rlvgl-creator.

use std::path::Path;

/// Generate a SCREAMING_SNAKE constant name from a path.
pub(crate) fn const_name(path: &str) -> String {
    let name = path.replace(['/', '.', '-'], "_").to_uppercase();
    if let Some(stripped) = name.strip_prefix("ICONS_") {
        format!("ICON_{}", stripped)
    } else if let Some(stripped) = name.strip_prefix("FONTS_") {
        format!("FONT_{}", stripped)
    } else if let Some(stripped) = name.strip_prefix("MEDIA_") {
        format!("MEDIA_{}", stripped)
    } else {
        name
    }
}

/// Return true if the path begins with an allowed root directory.
pub(crate) fn valid_root(path: &str) -> bool {
    matches!(
        Path::new(path).iter().next().and_then(|p| p.to_str()),
        Some("icons") | Some("fonts") | Some("media")
    )
}