gbf_core/utils.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#![deny(missing_docs)]
use std::ascii::escape_default;
/// A type representing a bytecode address.
pub type Gs2BytecodeAddress = usize;
/// At what length text should be truncated for operands.
pub const OPERAND_TRUNCATE_LENGTH: usize = 100;
/// A constant representing the current version of the software, in semver format.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// A constant representing the name of the software.
pub const NAME: &str = env!("CARGO_PKG_NAME");
/// A constant representing GBF green
pub const GBF_GREEN: &str = "#99ff66";
/// A constant representing GBF red
pub const GBF_RED: &str = "#ff6666";
/// A constant representing GBF blue
pub const GBF_BLUE: &str = "#66b3ff";
/// A constant representing GBF yellow
pub const GBF_YELLOW: &str = "#ffd966";
/// A constant representing GBF light gray
pub const GBF_DARK_GRAY: &str = "#666666";
/// A constant representing GBF dark gray
pub const GBF_LIGHT_GRAY: &str = "#1a1a1a";
/// Escapes a string using `std::ascii::escape_default`.
///
/// # Arguments
/// * `input` - A value that can be converted into a `String`.
///
/// # Returns
/// A new `String` where each character is escaped according to `escape_default`.
pub fn escape_string<S>(input: S) -> String
where
S: Into<String>,
{
input
.into()
.bytes()
.flat_map(escape_default)
.map(char::from)
.collect()
}