Begin XML Schema Validator
This commit is contained in:
36
lib/xml_schema_validator/src/token/text_content.rs
Normal file
36
lib/xml_schema_validator/src/token/text_content.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use crate::*;
|
||||
|
||||
/// Represents the text content within an XML element
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TextContent {
|
||||
element: std::rc::Rc<schema::XsElement>,
|
||||
buffer: String,
|
||||
}
|
||||
|
||||
impl TextContent {
|
||||
pub fn new(element: std::rc::Rc<schema::XsElement>) -> Self {
|
||||
Self {
|
||||
element,
|
||||
buffer: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new TextContent with the given initial buffer
|
||||
pub fn with_buffer(element: std::rc::Rc<schema::XsElement>, buffer: String) -> Self {
|
||||
Self {
|
||||
element,
|
||||
buffer,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn append(&self, c: char) -> Vec<std::rc::Rc<Token>> {
|
||||
if c == '<' {
|
||||
vec![std::rc::Rc::new(Token::ElementCloseStart(ElementCloseStart::new(self.element.clone())))]
|
||||
} else {
|
||||
vec![std::rc::Rc::new(Token::TextContent(TextContent::with_buffer(
|
||||
self.element.clone(),
|
||||
self.buffer.clone() + &c.to_string(),
|
||||
)))]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user