1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 //! Utilities for strings.
14 /// A string that displays only printable characters, replacing control characters with
15 /// [`core::char::REPLACEMENT_CHARACTER`].
16 #[derive(Debug, PartialEq)]
17 pub struct PrintableString<'a>(pub &'a str);
19 impl<'a> fmt::Display for PrintableString<'a> {
20 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
22 for c in self.0.chars() {
23 let c = if c.is_control() { core::char::REPLACEMENT_CHARACTER } else { c };
33 use super::PrintableString;
36 fn displays_printable_string() {
38 format!("{}", PrintableString("I \u{1F496} LDK!\t\u{26A1}")),
39 "I \u{1F496} LDK!\u{FFFD}\u{26A1}",