diff options
| author | Jokler <jokler@protonmail.com> | 2020-02-22 18:57:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-22 18:57:12 +0100 |
| commit | 2792ba9c8a7120a91b3bd2c6075e737690e73405 (patch) | |
| tree | 5bc007e03ef7782bbfeeb81ca936c97c992be1a2 /src/teamspeak/bbcode.rs | |
| parent | 00b60b8f210b93a5d6cbdde2bc98feff2f2ec1ca (diff) | |
| parent | dbaaeb68bdf4143b9dca55b2baa86a2656a3249e (diff) | |
| download | pokebot-2792ba9c8a7120a91b3bd2c6075e737690e73405.tar.gz pokebot-2792ba9c8a7120a91b3bd2c6075e737690e73405.zip | |
Merge pull request #37 from Mavulp/branches/fkaa/BBCode
Add functions for BBCode formatting
Diffstat (limited to 'src/teamspeak/bbcode.rs')
| -rw-r--r-- | src/teamspeak/bbcode.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/teamspeak/bbcode.rs b/src/teamspeak/bbcode.rs new file mode 100644 index 0000000..28be08a --- /dev/null +++ b/src/teamspeak/bbcode.rs @@ -0,0 +1,42 @@ +use std::fmt::{Formatter, Display, Error}; + +#[allow(dead_code)] +pub enum BbCode<'a> { + Bold(&'a dyn Display), + Italic(&'a dyn Display), + Underline(&'a dyn Display), + Link(&'a dyn Display, &'a str), +} + +impl<'a> Display for BbCode<'a> { + fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { + match self { + BbCode::Bold(text) => fmt.write_fmt(format_args!("[B]{}[/B]", text))?, + BbCode::Italic(text) => fmt.write_fmt(format_args!("[I]{}[/I]", text))?, + BbCode::Underline(text) => fmt.write_fmt(format_args!("[U]{}[/U]", text))?, + BbCode::Link(text, url) => fmt.write_fmt(format_args!("[URL={}]{}[/URL]", url, text))?, + }; + + Ok(()) + } +} + +#[allow(dead_code)] +pub fn bold(text: &dyn Display) -> BbCode { + BbCode::Bold(text) +} + +#[allow(dead_code)] +pub fn italic(text: &dyn Display) -> BbCode { + BbCode::Italic(text) +} + +#[allow(dead_code)] +pub fn underline(text: &dyn Display) -> BbCode { + BbCode::Underline(text) +} + +#[allow(dead_code)] +pub fn link<'a>(text: &'a dyn Display, url: &'a str) -> BbCode<'a> { + BbCode::Link(text, url) +} |
