Mercurial > pidgin.yaz
changeset 18889:a3a5b2e9079a
Change escape code replacement text parallel arrays to an array of structs,
for easier maintainence.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Sat, 11 Aug 2007 04:07:39 +0000 |
parents | 72b0f29a08c4 |
children | 00499df91ffe |
files | libpurple/protocols/myspace/message.c |
diffstat | 1 files changed, 24 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c Wed Aug 08 04:50:32 2007 +0000 +++ b/libpurple/protocols/myspace/message.c Sat Aug 11 04:07:39 2007 +0000 @@ -29,10 +29,18 @@ static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name); static MsimMessage *msim_msg_new_v(va_list argp); -/* Replacement codes to be replaced with associated replacement text, - * used for protocol message escaping / unescaping. */ -static gchar* msim_replacement_code[] = { "/1", "/2", /* "/3", */ NULL }; -static gchar* msim_replacement_text[] = { "/", "\\", /* "|", */ NULL }; +/* Escape codes and associated replacement text, used for protocol message + * escaping and unescaping. */ +static struct MSIM_ESCAPE_REPLACEMENT +{ + gchar *code; + gchar *text; +} msim_escape_replacements[] = { + { "/1", "/" }, + { "/2", "\\" }, + /* { "/3", "|" }, */ /* Not used here -- only for within arrays */ + { NULL, NULL } +}; /** * Unescape or escape a protocol message. @@ -45,14 +53,22 @@ static gchar * msim_unescape_or_escape(gchar *msg, gboolean escape) { - gchar *tmp, *code, *text; + gchar *tmp; guint i; + struct MSIM_ESCAPE_REPLACEMENT* replacement; /* Replace each code in msim_replacement_code with * corresponding entry in msim_replacement_text. */ - for (i = 0; (code = msim_replacement_code[i]) - && (text = msim_replacement_text[i]); ++i) - { + for (i = 0; (replacement = &msim_escape_replacements[i]); ++i) + { + gchar *code, *text; + + code = replacement->code; + text = replacement->text; + + if (!code || !text) + break; + if (escape) { tmp = str_replace(msg, text, code);