Function xhtmlchardet::detect [] [src]

pub fn detect<R: Read>(reader: &mut R, hint: Option<String>) -> Result<Vec<String>, Error>

Attempt to detect the character set of the supplied byte stream.

reader is expected to be positioned at the start of the stream. detect will read up to 512 bytes in order to determine the encoding.

The optional hint is a possible encoding name for the text that may have been received externally to the text itself, such as from HTTP header.

Example

use std::io::Cursor;
extern crate xhtmlchardet;

let text = b"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><channel><title>Example</title></channel>";
let mut text_cursor = Cursor::new(text.to_vec());
let detected_charsets = xhtmlchardet::detect(&mut text_cursor, None);
assert_eq!(detected_charsets.unwrap_or(vec![]), vec!["iso-8859-1".to_string()]);