#[cfg(feature = "nostd")]
use alloc::{string::String, vec::Vec};
#[cfg(not(feature = "nostd"))]
use std::{string::String, vec::Vec};
pub(super) fn split_tags_carefully(content: &str) -> Vec<String> {
let mut parts = Vec::new();
let mut current = String::new();
let mut depth = 0;
let mut chars = content.chars().peekable();
while let Some(ch) = chars.next() {
if ch == '\\' && depth == 0 {
if !current.is_empty() {
parts.push(current);
current = String::new();
}
} else {
current.push(ch);
if ch == '(' {
depth += 1;
} else if ch == ')' {
depth -= 1;
if depth == 0 && !current.is_empty() {
if chars.peek() == Some(&'\\') {
parts.push(current.clone());
current = String::new();
}
}
}
}
}
if !current.is_empty() {
parts.push(current);
}
parts
}
pub(super) fn extract_tag_name_and_args(part: &str) -> (&str, &str) {
if part.starts_with("fn") && part.len() > 2 {
("fn", &part[2..])
} else if part.starts_with(|c: char| c.is_ascii_digit()) {
if part.len() >= 2 {
(&part[..2], &part[2..])
} else {
(part, "")
}
} else if let Some(idx) = part.find(|c: char| !c.is_ascii_alphabetic()) {
(&part[..idx], &part[idx..])
} else {
(part, "")
}
}