diff --git a/src/bottom.rs b/src/bottom.rs index e20610a..49ef2c5 100644 --- a/src/bottom.rs +++ b/src/bottom.rs @@ -32,8 +32,22 @@ pub fn encode_string(input: &dyn AsRef) -> String { input.as_ref().bytes().map(encode_byte).collect::() } -pub fn decode_string(input: &dyn AsRef) -> Result { - let input = input.as_ref(); +pub fn delongate(input: &str) -> String { + return input + .replace(":sparkling_heart:", "💖") + .replace(":pleading_face:", "🥺") + .replace(":point_left:", "👈") + .replace(":point_right:", "👉") + .replace(":sparkles:", "✨"); +} + +pub fn decode_string_long<'a>(input: &dyn AsRef, do_delongate: bool) -> Result { + let mut input = input.as_ref(); + let new_input; + if do_delongate{ + new_input = delongate(input); + input = new_input.as_ref(); + } let result = { // Older versions used a ZWSP as a character separator, instead of `👉👈`. let split_char = input @@ -56,6 +70,10 @@ pub fn decode_string(input: &dyn AsRef) -> Result mod tests { use super::*; + fn decode_string<'a>(input: &dyn AsRef) -> Result { + return decode_string_long(input, false); + } + #[test] fn test_string_encode() { assert_eq!( @@ -119,4 +137,13 @@ mod tests { "がんばれ", ); } + + #[test] + fn test_long_names() { + assert_eq!( + decode_string_long(&":sparkling_heart::sparkles::sparkles::pleading_face:,:point_right::point_left::sparkling_heart::sparkling_heart::sparkles:,:point_right::point_left::sparkling_heart::sparkling_heart::sparkles::point_right::point_left::sparkling_heart::sparkling_heart:,,,:point_right::point_left:", true) + .unwrap(), + "Long", + ); + } } diff --git a/src/main.rs b/src/main.rs index ce2ddda..a87ea11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,9 @@ fn main() -> Result<()> { .arg(Arg::from_usage( "regress -r --regress 'Translate bottom to human-readable text (futile)'", )) + .arg(Arg::from_usage( + "-d --decode-long 'When using regress mode, decode emojis in long-name form (e.g. :sparkling_heart:, useful for pasting from slack)'", + )) .group( ArgGroup::with_name("action") .required(true) @@ -54,7 +57,8 @@ fn main() -> Result<()> { let result = if args.is_present("bottomify") { bottom::encode_string(&input) } else { - bottom::decode_string(&input).context("The input was invalid.")? + let delongate = args.is_present("decode-long"); + bottom::decode_string_long(&input, delongate).context("The input was invalid.")? }; if file_output {