# HG changeset patch # User Jeffrey Connelly # Date 1186805259 0 # Node ID a3a5b2e9079adbe5ccb8e26081adadfe30753da1 # Parent 72b0f29a08c445093cb6d6fbf10ee326c65ad5c5 Change escape code replacement text parallel arrays to an array of structs, for easier maintainence. diff -r 72b0f29a08c4 -r a3a5b2e9079a libpurple/protocols/myspace/message.c --- 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);