use super::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SourceLocation {
pub file: &'static str,
pub line: u32,
pub column: u32,
pub function: &'static str,
}
pub fn portable_path(file: &str) -> String {
if file.contains('\\') {
file.replace('\\', "/")
} else {
file.to_owned()
}
}
pub fn source_file_matches(file: &str, needle: &str) -> bool {
if file.contains('\\') {
portable_path(file).to_ascii_lowercase().contains(needle)
} else {
file.to_ascii_lowercase().contains(needle)
}
}
impl fmt::Display for SourceLocation {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"{}:{}:{}",
portable_path(self.file),
self.line,
self.column
)
}
}
impl SourceLocation {
pub fn is_synthetic(self) -> bool {
self.file.starts_with('<') && self.file.ends_with('>')
}
pub fn describe(self) -> String {
format!(
"{}:{}:{} function={}",
portable_path(self.file),
self.line,
self.column,
self.function
)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct LocalizedText {
pub zh: &'static str,
pub en: &'static str,
}
#[cfg(test)]
#[path = "source_location_tests.rs"]
mod source_location_tests;