MCPcopy Create free account
hub / github.com/daisy/MathCAT / replace_nodes_string

Method replace_nodes_string

src/speech.rs:2404–2423  ·  view source on GitHub ↗
(&'r mut self, nodes: Vec<Node<'c>>, mathml: Element<'c>)

Source from the content-addressed store, hash-verified

2402 }
2403
2404 fn replace_nodes_string(&'r mut self, nodes: Vec<Node<'c>>, mathml: Element<'c>) -> Result<String> {
2405 // debug!("replace_nodes: working on {} nodes", nodes.len());
2406 let mut result = String::with_capacity(3*nodes.len()); // guess (2 chars/node + space)
2407 let mut first_time = true;
2408 for node in nodes {
2409 if first_time {
2410 first_time = false;
2411 } else {
2412 result.push(' ');
2413 };
2414 let matched = match node {
2415 Node::Element(n) => self.match_pattern::<String>(n)?,
2416 Node::Text(t) => self.replace_chars(t.text(), mathml)?,
2417 Node::Attribute(attr) => self.replace_chars(attr.value(), mathml)?,
2418 _ => bail!("replace_nodes: found unexpected node type!!!"),
2419 };
2420 result += &matched;
2421 }
2422 return Ok( result );
2423 }
2424
2425 /// Lookup unicode "pronunciation" of char.
2426 /// Note: TTS is not supported here (not needed and a little less efficient)

Callers 1

replace_nodesMethod · 0.80

Calls 3

lenMethod · 0.80
replace_charsMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected