filecount 0.1.0

A modern high-performance open source file analysis library for automating localization tasks.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::error::Error;
use crate::{extract::Extract, xml_extensions::extract_text_from_node};
use std::str::from_utf8;

pub struct Xml;

impl Extract for Xml {
    fn can_extract(&self, buf: &[u8], _extension: Option<&str>) -> bool {
        infer::text::is_xml(buf)
    }

    fn extract(&self, buf: &[u8]) -> Result<Vec<String>, Box<dyn Error>> {
        let str = from_utf8(buf)?;        
        let doc = roxmltree::Document::parse(str)?;    
        Ok(extract_text_from_node(doc.root()))
    }
}