mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-22 07:42:22 +02:00
added transform to mapper
This commit is contained in:
@@ -71,10 +71,16 @@ pub(crate) fn read_config(config_path: &str, config_file: &str, sources_file: &s
|
||||
pub(crate) fn read_mapping(mapping_file: &str) -> Result<Option<Mappings>, M3uFilterError> {
|
||||
let mapping_file = std::path::PathBuf::from(mapping_file);
|
||||
if let Ok(file) = file_utils::open_file(&mapping_file) {
|
||||
info!("Mapping file: {}", mapping_file.to_str().unwrap_or("?"));
|
||||
let mapping: Result<Mappings, _> = serde_yaml::from_reader(file);
|
||||
if let Ok(mut result) = mapping {
|
||||
handle_m3u_filter_error_result!(M3uFilterErrorKind::Info, result.prepare());
|
||||
return Ok(Some(result));
|
||||
match mapping {
|
||||
Ok(mut result) => {
|
||||
handle_m3u_filter_error_result!(M3uFilterErrorKind::Info, result.prepare());
|
||||
return Ok(Some(result));
|
||||
},
|
||||
Err(err) => {
|
||||
return Err(M3uFilterError::new(M3uFilterErrorKind::Info, err.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
warn!("cant read mapping file: {}", mapping_file.to_str().unwrap_or("?"));
|
||||
|
||||
@@ -12,3 +12,25 @@ pub (crate) fn get_title_group(text: &str) -> String {
|
||||
}
|
||||
text.to_string()
|
||||
}
|
||||
|
||||
pub(crate) trait Capitalize {
|
||||
fn capitalize(&self) -> String;
|
||||
}
|
||||
|
||||
// Implement the Capitalize trait for &str
|
||||
impl Capitalize for &str {
|
||||
fn capitalize(&self) -> String {
|
||||
let mut chars = self.chars();
|
||||
match chars.next() {
|
||||
None => String::new(), // Handle empty string case
|
||||
Some(first_char) => first_char.to_uppercase().collect::<String>() + chars.as_str(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Implement the trait for String as well
|
||||
impl Capitalize for String {
|
||||
fn capitalize(&self) -> String {
|
||||
self.as_str().capitalize() // Reuse the &str implementation
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user