mirror of https://github.com/xvxx/phetch
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
825 B
Rust
31 lines
825 B
Rust
use std::io::Result;
|
|
|
|
/// Encoding of Gopher response. Only UTF8 and CP437 are supported.
|
|
#[derive(Debug, PartialEq, Copy, Clone)]
|
|
pub enum Encoding {
|
|
/// Unicode
|
|
UTF8,
|
|
/// https://en.wikipedia.org/wiki/Code_page_437
|
|
CP437,
|
|
}
|
|
|
|
impl Default for Encoding {
|
|
fn default() -> Self {
|
|
Encoding::UTF8
|
|
}
|
|
}
|
|
|
|
impl Encoding {
|
|
/// Accepts a string like "UTF8" or "CP437" and returns the
|
|
/// appropriate `Encoding`, or an `Err`.
|
|
pub fn from_str(s: &str) -> Result<Self> {
|
|
match s.to_lowercase().as_ref() {
|
|
"utf8" | "utf-8" | "utf 8" => Ok(Encoding::UTF8),
|
|
"cp437" | "cp-437" | "cp 437" | "pc8" | "pc-8" | "oem us" | "oem-us" => {
|
|
Ok(Encoding::CP437)
|
|
}
|
|
_ => Err(error!("Expected CP437 or UTF8 encoding")),
|
|
}
|
|
}
|
|
}
|