diff options
author | Florent Le Coz <louiz@louiz.org> | 2013-11-22 21:00:32 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2013-11-28 01:18:26 +0100 |
commit | e6f20d3c0fd4ba8696a4410a366741c9b9f3562d (patch) | |
tree | 0b34e42163fcb2b869e74fa11c4fb18cf5226b89 /src/bridge/colors.hpp | |
parent | 31e18e49b699f606a8aeb1f529642a004781e704 (diff) | |
download | biboumi-e6f20d3c0fd4ba8696a4410a366741c9b9f3562d.tar.gz biboumi-e6f20d3c0fd4ba8696a4410a366741c9b9f3562d.tar.bz2 biboumi-e6f20d3c0fd4ba8696a4410a366741c9b9f3562d.tar.xz biboumi-e6f20d3c0fd4ba8696a4410a366741c9b9f3562d.zip |
Implement IRC format to xhtml-im conversion
The generated XML is very verbose because each IRC formatting tag makes us
close a <span/> element and reopen it with the new style applied. However,
this works quite well and is easy to implement.
Diffstat (limited to 'src/bridge/colors.hpp')
-rw-r--r-- | src/bridge/colors.hpp | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/src/bridge/colors.hpp b/src/bridge/colors.hpp index da4498c..82e6faf 100644 --- a/src/bridge/colors.hpp +++ b/src/bridge/colors.hpp @@ -1,20 +1,54 @@ #ifndef COLORS_INCLUDED # define COLORS_INCLUDED -#include <string> - /** - * A module handling the conversion between IRC colors and XHTML-IM, and vice versa. + * A module handling the conversion between IRC colors and XHTML-IM, and + * vice versa. */ -#define IRC_COLOR_BOLD_CHAR '\x02' -#define IRC_COLOR_COLOR_CHAR '\x03' -#define IRC_COLOR_RESET_CHAR '\x0F' -#define IRC_COLOR_FIXED_CHAR '\x11' -#define IRC_COLOR_REVERSE_CHAR '\x12' -#define IRC_COLOR_REVERSE2_CHAR '\x16' -#define IRC_COLOR_ITALIC_CHAR '\x1D' -#define IRC_COLOR_UNDERLINE_CHAR '\x1F' +#include <string> +#include <memory> +#include <tuple> + +class XmlNode; + +namespace Xmpp +{ +// Contains: +// - an XMPP-valid UTF-8 body +// - an XML node representing the XHTML-IM body, or null + typedef std::tuple<const std::string, std::unique_ptr<XmlNode>> body; +} +#define IRC_FORMAT_BOLD_CHAR '\x02' // done +#define IRC_FORMAT_COLOR_CHAR '\x03' // done +#define IRC_FORMAT_RESET_CHAR '\x0F' // done +#define IRC_FORMAT_FIXED_CHAR '\x11' // ?? +#define IRC_FORMAT_REVERSE_CHAR '\x12' // maybe one day +#define IRC_FORMAT_REVERSE2_CHAR '\x16' // wat +#define IRC_FORMAT_ITALIC_CHAR '\x1D' // done +#define IRC_FORMAT_UNDERLINE_CHAR '\x1F' // done + +static const char irc_format_char[] = { + IRC_FORMAT_BOLD_CHAR, + IRC_FORMAT_COLOR_CHAR, + IRC_FORMAT_RESET_CHAR, + IRC_FORMAT_FIXED_CHAR, + IRC_FORMAT_REVERSE_CHAR, + IRC_FORMAT_REVERSE2_CHAR, + IRC_FORMAT_ITALIC_CHAR, + IRC_FORMAT_UNDERLINE_CHAR, + '\x00' +}; + +/** + * Convert the passed string into an XML tree representing the XHTML version + * of the message, converting the IRC colors symbols into xhtml-im + * formatting. + * + * Returns the body cleaned from any IRC formatting (but without any xhtml), + * and the body as XHTML-IM + */ +Xmpp::body irc_format_to_xhtmlim(const std::string& str); #endif // COLORS_INCLUDED |