-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from kivikakk/shortcodes-again
shortcodes: capture all known aliases.
- Loading branch information
Showing
9 changed files
with
59 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,22 @@ | ||
use std::{convert::TryFrom, str}; | ||
|
||
/// The details of an inline emoji. | ||
/// The details of an inline "shortcode" emoji/gemoji. | ||
/// | ||
/// ("gemoji" name context: https://github.com/github/gemoji) | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct NodeShortCode( | ||
/// A short code that is translated into an emoji | ||
String, | ||
); | ||
|
||
impl NodeShortCode { | ||
/// Checks whether the input is a valid short code. | ||
pub fn is_valid(value: &str) -> bool { | ||
emojis::get_by_shortcode(value).is_some() | ||
} | ||
pub struct NodeShortCode { | ||
/// The shortcode that was resolved, e.g. "rabbit". | ||
pub code: String, | ||
|
||
/// Get the underlying shortcode. | ||
pub fn shortcode(&self) -> &str { | ||
&self.0 | ||
} | ||
|
||
/// Get the emoji for this short code. | ||
pub fn emoji(&self) -> &'static str { | ||
emojis::get_by_shortcode(&self.0).unwrap().as_str() | ||
} | ||
/// The emoji `code` resolved to, e.g. "🐰". | ||
pub emoji: String, | ||
} | ||
|
||
impl TryFrom<&str> for NodeShortCode { | ||
type Error = (); | ||
|
||
fn try_from(value: &str) -> Result<Self, ()> { | ||
if Self::is_valid(value) { | ||
Ok(Self(value.into())) | ||
} else { | ||
Err(()) | ||
} | ||
impl NodeShortCode { | ||
/// Checks whether the input is a valid short code. | ||
pub fn resolve(code: &str) -> Option<Self> { | ||
let emoji = emojis::get_by_shortcode(code)?; | ||
Some(NodeShortCode { | ||
code: code.to_string(), | ||
emoji: emoji.to_string(), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters