Made xml schema validator send

This commit is contained in:
2025-04-07 19:27:03 +02:00
parent 2d4a57a706
commit 3826c45240
12 changed files with 59 additions and 48 deletions

View File

@@ -1,14 +1,15 @@
use std::sync::Arc;
use crate::*;
/// Represents the text content within an XML element
#[derive(Clone, Debug)]
pub struct TextContent {
element: schema::XsElement,
element: Arc<schema::XsElement>,
buffer: String,
}
impl TextContent {
pub fn new(element: schema::XsElement) -> Self {
pub fn new(element: Arc<schema::XsElement>) -> Self {
Self {
element,
buffer: String::new(),
@@ -16,20 +17,20 @@ impl TextContent {
}
/// Create a new TextContent with the given initial buffer
pub fn with_buffer(element: schema::XsElement, buffer: String) -> Self {
pub fn with_buffer(element: Arc<schema::XsElement>, buffer: String) -> Self {
Self {
element,
buffer,
}
}
pub fn append(&self, c: char) -> Vec<Token> {
pub fn append(self, c: char) -> Vec<Token> {
if c == '<' {
vec![Token::ElementCloseStart(ElementCloseStart::new(self.element.clone()))]
vec![Token::ElementCloseStart(ElementCloseStart::new(Arc::clone(&self.element)))]
} else {
vec![Token::TextContent(TextContent::with_buffer(
self.element.clone(),
self.buffer.clone() + &c.to_string(),
Arc::clone(&self.element),
self.buffer + &c.to_string(),
))]
}
}