use crate::uuid::UUID;
#[allow(dead_code)]
pub fn test_correct_chars(key: String, charset: &str) -> bool {
let mut result = true;
for key_c in key.chars() {
if !&charset.contains(key_c) {
result = false;
}
}
result
}
#[allow(dead_code)]
pub fn split_uuid(key: &str) -> Vec<String> {
let mut result = Vec::new();
let mut current_chunk = String::new();
for c in key.chars() {
if c == '-' {
result.push(current_chunk.clone());
current_chunk.clear();
} else {
current_chunk.push(c);
}
}
if !current_chunk.is_empty() {
result.push(current_chunk);
}
result
}
pub fn test_correct_uuid_chars(version: UUID, chunk: String) -> bool {
let charset: String = match version {
UUID::V4 => {
let mut cs = String::from("");
cs.push_str(crate::char::HEX_LETTERS);
cs.push_str(crate::char::NUMBERS);
cs
}
UUID::Nonstandard => {
let mut cs = String::from("");
cs.push_str(crate::char::LETTERS);
cs.push_str(crate::char::NUMBERS);
cs
}
};
test_correct_chars(chunk, &charset)
}
#[allow(dead_code)]
pub fn test_valid_uuid(version: UUID) -> bool {
use crate::uuid::{uuid4, uuidn};
let mut success = true;
let key: String = match version {
UUID::V4 => uuid4(),
UUID::Nonstandard => uuidn(),
};
let chunks = &split_uuid(&key);
let mut current_set = 1;
for chunk in chunks {
if !success {
break;
}
success = test_correct_uuid_chars(version, String::from(chunk));
if current_set == 1 && chunk.len() != 8 {
success = false;
}
if (current_set == 2 || current_set == 3 || current_set == 4)
&& chunk.len() != 4
{
success = false;
}
if current_set == 5 && chunk.len() != 12 {
success = false;
}
current_set += 1;
}
success
}