aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-11 15:45:50 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-11 15:45:50 +0200
commit73d8609565b808ac73df5ac34e6d4f7f23c25ad6 (patch)
tree8b13c61bcd55380b36338473a74e172b63fb16d7 /src/util
parent070b3efeeebf34fbc435ffc7fea2bad95689664a (diff)
downloadmarkdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.tar.gz
markdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.tar.bz2
markdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.zip
Refactor to use a bunch of `into`
Diffstat (limited to 'src/util')
-rw-r--r--src/util/char.rs13
-rw-r--r--src/util/character_reference.rs6
-rw-r--r--src/util/sanitize_uri.rs8
3 files changed, 10 insertions, 17 deletions
diff --git a/src/util/char.rs b/src/util/char.rs
index b902fbe..70367f3 100644
--- a/src/util/char.rs
+++ b/src/util/char.rs
@@ -1,10 +1,7 @@
//! Deal with bytes, chars, and kinds.
use crate::util::unicode::PUNCTUATION;
-use alloc::{
- format,
- string::{String, ToString},
-};
+use alloc::{format, string::String};
use core::str;
/// Character kinds.
@@ -119,7 +116,7 @@ pub fn classify_opt(char_opt: Option<char>) -> Kind {
/// Format an optional `char` (`none` means eof).
pub fn format_opt(char: Option<char>) -> String {
match char {
- None => "end of file".to_string(),
+ None => "end of file".into(),
Some(char) => format!("character {}", format(char)),
}
}
@@ -127,7 +124,7 @@ pub fn format_opt(char: Option<char>) -> String {
/// Format an optional `byte` (`none` means eof).
pub fn format_byte_opt(byte: Option<u8>) -> String {
match byte {
- None => "end of file".to_string(),
+ None => "end of file".into(),
Some(byte) => format!("byte {}", format_byte(byte)),
}
}
@@ -136,7 +133,7 @@ pub fn format_byte_opt(byte: Option<u8>) -> String {
pub fn format(char: char) -> String {
let representation = format!("U+{:>04X}", char as u32);
let printable = match char {
- '`' => Some("`` ` ``".to_string()),
+ '`' => Some("`` ` ``".into()),
'!'..='~' => Some(format!("`{}`", char)),
_ => None,
};
@@ -152,7 +149,7 @@ pub fn format(char: char) -> String {
pub fn format_byte(byte: u8) -> String {
let representation = format!("U+{:>04X}", byte);
let printable = match byte {
- b'`' => Some("`` ` ``".to_string()),
+ b'`' => Some("`` ` ``".into()),
b'!'..=b'~' => Some(format!("`{}`", str::from_utf8(&[byte]).unwrap())),
_ => None,
};
diff --git a/src/util/character_reference.rs b/src/util/character_reference.rs
index ee2a65c..330293c 100644
--- a/src/util/character_reference.rs
+++ b/src/util/character_reference.rs
@@ -4,7 +4,7 @@ use crate::util::constant::{
CHARACTER_REFERENCES, CHARACTER_REFERENCES_HTML_4, CHARACTER_REFERENCE_DECIMAL_SIZE_MAX,
CHARACTER_REFERENCE_HEXADECIMAL_SIZE_MAX, CHARACTER_REFERENCE_NAMED_SIZE_MAX,
};
-use alloc::string::{String, ToString};
+use alloc::string::String;
use core::str;
/// Decode named character references.
@@ -89,11 +89,11 @@ pub fn decode_numeric(value: &str, radix: u32) -> String {
// Lone surrogates, noncharacters, and out of range are handled by
// Rust.
) {
- return char.to_string();
+ return char.into();
}
}
- char::REPLACEMENT_CHARACTER.to_string()
+ char::REPLACEMENT_CHARACTER.into()
}
/// Decode a character reference.
diff --git a/src/util/sanitize_uri.rs b/src/util/sanitize_uri.rs
index 7006ace..cd0600d 100644
--- a/src/util/sanitize_uri.rs
+++ b/src/util/sanitize_uri.rs
@@ -1,11 +1,7 @@
//! Make urls safe.
use crate::util::encode::encode;
-use alloc::{
- format,
- string::{String, ToString},
- vec::Vec,
-};
+use alloc::{format, string::String, vec::Vec};
/// Make a value safe for injection as a URL.
///
@@ -75,7 +71,7 @@ pub fn sanitize_with_protocols(value: &str, protocols: &[&str]) -> String {
// If it is a protocol, it should be allowed.
let protocol = value[0..colon].to_lowercase();
if !protocols.contains(&protocol.as_str()) {
- return "".to_string();
+ return "".into();
}
}