#![forbid(unsafe_code)]
pub mod css;
pub mod display;
pub mod go;
pub mod html;
pub mod java;
pub mod javascript;
pub mod json;
pub mod python;
pub mod ruby;
pub mod rust;
pub mod sql;
pub mod uri;
pub mod xml;
mod engine;
pub use css::{for_css_string, for_css_url, write_css_string, write_css_url};
pub use display::{
display_cdata, display_css_string, display_css_url, display_go_byte_string, display_go_char,
display_go_string, display_html, display_html_attribute, display_html_content,
display_html_unquoted_attribute, display_java, display_javascript,
display_javascript_attribute, display_javascript_block, display_javascript_source,
display_js_template, display_json, display_python_bytes, display_python_raw_string,
display_python_string, display_ruby_string, display_rust_byte_string, display_rust_char,
display_rust_string, display_sql, display_sql_backslash, display_uri_component, display_xml,
display_xml11, display_xml11_attribute, display_xml11_content, display_xml_attribute,
display_xml_comment, display_xml_content,
};
pub use go::{
for_go_byte_string, for_go_char, for_go_string, write_go_byte_string, write_go_char,
write_go_string,
};
pub use html::{
for_html, for_html_attribute, for_html_content, for_html_unquoted_attribute, write_html,
write_html_attribute, write_html_content, write_html_unquoted_attribute,
};
pub use java::{for_java, write_java};
pub use javascript::{
for_javascript, for_javascript_attribute, for_javascript_block, for_javascript_source,
for_js_template, write_javascript, write_javascript_attribute, write_javascript_block,
write_javascript_source, write_js_template,
};
pub use json::{for_json, write_json};
pub use python::{
for_python_bytes, for_python_raw_string, for_python_string, write_python_bytes,
write_python_raw_string, write_python_string,
};
pub use ruby::{for_ruby_string, write_ruby_string};
pub use rust::{
for_rust_byte_string, for_rust_char, for_rust_string, write_rust_byte_string, write_rust_char,
write_rust_string,
};
pub use sql::{for_sql, for_sql_backslash, write_sql, write_sql_backslash};
pub use uri::{for_uri_component, write_uri_component};
pub use xml::{
for_cdata, for_xml, for_xml11, for_xml11_attribute, for_xml11_content, for_xml_attribute,
for_xml_comment, for_xml_content, write_cdata, write_xml, write_xml11, write_xml11_attribute,
write_xml11_content, write_xml_attribute, write_xml_comment, write_xml_content,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_string_returns_empty() {
assert_eq!(for_html(""), "");
assert_eq!(for_html_content(""), "");
assert_eq!(for_html_attribute(""), "");
assert_eq!(for_html_unquoted_attribute(""), "");
assert_eq!(for_javascript(""), "");
assert_eq!(for_javascript_attribute(""), "");
assert_eq!(for_javascript_block(""), "");
assert_eq!(for_javascript_source(""), "");
assert_eq!(for_css_string(""), "");
assert_eq!(for_css_url(""), "");
assert_eq!(for_uri_component(""), "");
assert_eq!(for_xml(""), "");
assert_eq!(for_xml_content(""), "");
assert_eq!(for_xml_attribute(""), "");
assert_eq!(for_xml_comment(""), "");
assert_eq!(for_cdata(""), "");
assert_eq!(for_xml11(""), "");
assert_eq!(for_xml11_content(""), "");
assert_eq!(for_xml11_attribute(""), "");
assert_eq!(for_java(""), "");
assert_eq!(for_json(""), "");
assert_eq!(for_go_string(""), "");
assert_eq!(for_go_char(""), "");
assert_eq!(for_go_byte_string(""), "");
assert_eq!(for_rust_string(""), "");
assert_eq!(for_rust_char(""), "");
assert_eq!(for_rust_byte_string(""), "");
assert_eq!(for_ruby_string(""), "");
assert_eq!(for_python_string(""), "");
assert_eq!(for_python_bytes(""), "");
assert_eq!(for_python_raw_string(""), "");
assert_eq!(for_js_template(""), "");
assert_eq!(for_sql(""), "");
assert_eq!(for_sql_backslash(""), "");
}
#[test]
fn empty_string_writer_variants() {
let mut buf = String::new();
write_html(&mut buf, "").unwrap();
assert_eq!(buf, "");
buf.clear();
write_javascript(&mut buf, "").unwrap();
assert_eq!(buf, "");
buf.clear();
write_css_string(&mut buf, "").unwrap();
assert_eq!(buf, "");
buf.clear();
write_uri_component(&mut buf, "").unwrap();
assert_eq!(buf, "");
}
#[test]
fn multibyte_utf8_html() {
assert_eq!(for_html("café"), "café");
assert_eq!(for_html("世界"), "世界");
assert_eq!(for_html("😀"), "😀");
assert_eq!(for_html("é<世>&😀"), "é<世>&😀");
}
#[test]
fn multibyte_utf8_javascript() {
assert_eq!(for_javascript("café"), "café");
assert_eq!(for_javascript("世界"), "世界");
assert_eq!(for_javascript("😀"), "😀");
}
#[test]
fn multibyte_utf8_css_string() {
assert_eq!(for_css_string("café"), "café");
assert_eq!(for_css_string("世界"), "世界");
assert_eq!(for_css_string("😀"), "😀");
}
#[test]
fn multibyte_utf8_uri_component() {
assert_eq!(for_uri_component("é"), "%C3%A9");
assert_eq!(for_uri_component("世"), "%E4%B8%96");
assert_eq!(for_uri_component("😀"), "%F0%9F%98%80");
assert_eq!(for_uri_component("café"), "caf%C3%A9");
}
#[test]
fn multibyte_utf8_go_string_passthrough() {
assert_eq!(for_go_string("caf\u{00e9}"), "caf\u{00e9}");
assert_eq!(for_go_string("\u{4e16}\u{754c}"), "\u{4e16}\u{754c}");
assert_eq!(for_go_string("\u{1F600}"), "\u{1F600}");
}
#[test]
fn multibyte_utf8_go_byte_string() {
assert_eq!(for_go_byte_string("\u{00e9}"), r"\xc3\xa9");
assert_eq!(for_go_byte_string("\u{4e16}"), r"\xe4\xb8\x96");
assert_eq!(for_go_byte_string("\u{1F600}"), r"\xf0\x9f\x98\x80");
}
#[test]
fn multibyte_utf8_rust_byte_string() {
assert_eq!(for_rust_byte_string("é"), r"\xc3\xa9");
assert_eq!(for_rust_byte_string("世"), r"\xe4\xb8\x96");
assert_eq!(for_rust_byte_string("😀"), r"\xf0\x9f\x98\x80");
}
#[test]
fn multibyte_utf8_rust_string_passthrough() {
assert_eq!(for_rust_string("café"), "café");
assert_eq!(for_rust_string("世界"), "世界");
assert_eq!(for_rust_string("😀"), "😀");
}
#[test]
fn multibyte_utf8_ruby_string_passthrough() {
assert_eq!(for_ruby_string("café"), "café");
assert_eq!(for_ruby_string("世界"), "世界");
assert_eq!(for_ruby_string("😀"), "😀");
}
#[test]
fn multibyte_utf8_python_string_passthrough() {
assert_eq!(for_python_string("café"), "café");
assert_eq!(for_python_string("世界"), "世界");
assert_eq!(for_python_string("😀"), "😀");
}
#[test]
fn multibyte_utf8_python_bytes() {
assert_eq!(for_python_bytes("\u{00e9}"), r"\xc3\xa9");
assert_eq!(for_python_bytes("\u{4e16}"), r"\xe4\xb8\x96");
assert_eq!(for_python_bytes("\u{1F600}"), r"\xf0\x9f\x98\x80");
}
#[test]
fn multibyte_utf8_python_raw_string_passthrough() {
assert_eq!(for_python_raw_string("café"), "café");
assert_eq!(for_python_raw_string("世界"), "世界");
assert_eq!(for_python_raw_string("😀"), "😀");
}
#[test]
fn multibyte_utf8_json() {
assert_eq!(for_json("café"), "café");
assert_eq!(for_json("世界"), "世界");
assert_eq!(for_json("😀"), "😀");
}
#[test]
fn multibyte_utf8_java() {
assert_eq!(for_java("café"), "café");
assert_eq!(for_java("世界"), "世界");
assert_eq!(for_java("😀"), "\\ud83d\\ude00");
}
#[test]
fn multibyte_utf8_sql() {
assert_eq!(for_sql("café"), "café");
assert_eq!(for_sql("世界"), "世界");
assert_eq!(for_sql("😀"), "😀");
}
#[test]
fn multibyte_utf8_sql_backslash() {
assert_eq!(for_sql_backslash("café"), "café");
assert_eq!(for_sql_backslash("世界"), "世界");
assert_eq!(for_sql_backslash("😀"), "😀");
}
#[test]
fn multibyte_utf8_xml() {
assert_eq!(for_xml("café"), "café");
assert_eq!(for_xml("世界"), "世界");
assert_eq!(for_xml("😀"), "😀");
}
}