#[must_use]
fn is_valid_db_key(key: &str) -> bool {
!key.contains('"') && !key.contains('\'') && !key.contains(':') && !key.contains('{') && !key.contains('}')
}
#[must_use]
pub fn is_const_assignment(key: &str) -> bool {
!key.starts_with('{') && !key.ends_with('}') || key.contains('"') || key.contains(':') || key.contains('\'')
}
#[must_use]
pub fn is_board_pointer(key: &str) -> bool {
key.starts_with('{') && key.ends_with('}') && is_valid_db_key(&key[1..key.len() - 1])
}
#[must_use]
pub fn strip_board_pointer(key: &str) -> Option<&str> {
if is_board_pointer(key) {
Some(&key[1..key.len() - 1])
} else {
None
}
}
pub fn check_board_pointer(key: &str) -> core::result::Result<&str, &str> {
if is_board_pointer(key) {
Ok(&key[1..key.len() - 1])
} else {
Err(key)
}
}
pub fn check_local_key(key: &str) -> core::result::Result<&str, &str> {
if key.starts_with('_') && is_valid_db_key(&key[1..]) {
Ok(&key[1..])
} else {
Err(key)
}
}
#[must_use]
pub fn is_local_pointer(key: &str) -> bool {
key.starts_with("{_") && key.ends_with('}') && is_valid_db_key(&key[2..key.len() - 1])
}
#[must_use]
pub fn strip_local_pointer(key: &str) -> Option<&str> {
if is_local_pointer(key) {
Some(&key[2..key.len() - 1])
} else {
None
}
}
pub fn check_local_pointer(key: &str) -> core::result::Result<&str, &str> {
if is_local_pointer(key) {
Ok(&key[2..key.len() - 1])
} else {
Err(key)
}
}
pub fn check_top_level_key(key: &str) -> core::result::Result<&str, &str> {
if key.starts_with('@') && is_valid_db_key(&key[1..]) {
Ok(&key[1..])
} else {
Err(key)
}
}
#[must_use]
pub fn is_top_level_pointer(key: &str) -> bool {
key.starts_with("{@") && key.ends_with('}') && is_valid_db_key(&key[2..key.len() - 1])
}
#[must_use]
pub fn strip_top_level_pointer(key: &str) -> Option<&str> {
if is_top_level_pointer(key) {
Some(&key[2..key.len() - 1])
} else {
None
}
}
pub fn check_top_level_pointer(key: &str) -> core::result::Result<&str, &str> {
if is_top_level_pointer(key) {
Ok(&key[2..key.len() - 1])
} else {
Err(key)
}
}