use crate::errors::{LimaDiagnosticCode as Code, LimaError};
pub const DOCUMENT_SIZE_LIMIT: usize = 65_536;
pub const KEY_LENGTH_LIMIT: usize = 128;
pub const TOP_LEVEL_KEY_LIMIT: usize = 128;
pub const NESTING_DEPTH_LIMIT: usize = 16;
pub fn check_key_length(key: &str, line: u32) -> Result<(), LimaError> {
if key.chars().count() > KEY_LENGTH_LIMIT {
return Err(LimaError::new(
Code::ResourceLimit,
line,
format!("Lima: key \"{key}\" exceeds maximum length of {KEY_LENGTH_LIMIT} code points at line {line}"),
));
}
Ok(())
}
pub fn check_duplicate_key(
exists: bool,
key: &str,
line: u32,
strict: bool,
) -> Result<(), LimaError> {
if !exists || !strict {
return Ok(());
}
Err(LimaError::new(
Code::DuplicateKey,
line,
format!("Lima: duplicate key \"{key}\" at line {line} — last value wins"),
))
}