comparison libpurple/protocols/myspace/message.c @ 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 b69623379f9a
children 00499df91ffe
comparison
equal deleted inserted replaced
18888:72b0f29a08c4 18889:a3a5b2e9079a
27 static void msim_msg_debug_string_element(gpointer data, gpointer user_data); 27 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
28 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end); 28 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end);
29 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name); 29 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name);
30 static MsimMessage *msim_msg_new_v(va_list argp); 30 static MsimMessage *msim_msg_new_v(va_list argp);
31 31
32 /* Replacement codes to be replaced with associated replacement text, 32 /* Escape codes and associated replacement text, used for protocol message
33 * used for protocol message escaping / unescaping. */ 33 * escaping and unescaping. */
34 static gchar* msim_replacement_code[] = { "/1", "/2", /* "/3", */ NULL }; 34 static struct MSIM_ESCAPE_REPLACEMENT
35 static gchar* msim_replacement_text[] = { "/", "\\", /* "|", */ NULL }; 35 {
36 gchar *code;
37 gchar *text;
38 } msim_escape_replacements[] = {
39 { "/1", "/" },
40 { "/2", "\\" },
41 /* { "/3", "|" }, */ /* Not used here -- only for within arrays */
42 { NULL, NULL }
43 };
36 44
37 /** 45 /**
38 * Unescape or escape a protocol message. 46 * Unescape or escape a protocol message.
39 * 47 *
40 * @param msg The message to be unescaped or escaped. WILL BE FREED. 48 * @param msg The message to be unescaped or escaped. WILL BE FREED.
43 * @return The unescaped or escaped message. Caller must g_free(). 51 * @return The unescaped or escaped message. Caller must g_free().
44 */ 52 */
45 static gchar * 53 static gchar *
46 msim_unescape_or_escape(gchar *msg, gboolean escape) 54 msim_unescape_or_escape(gchar *msg, gboolean escape)
47 { 55 {
48 gchar *tmp, *code, *text; 56 gchar *tmp;
49 guint i; 57 guint i;
58 struct MSIM_ESCAPE_REPLACEMENT* replacement;
50 59
51 /* Replace each code in msim_replacement_code with 60 /* Replace each code in msim_replacement_code with
52 * corresponding entry in msim_replacement_text. */ 61 * corresponding entry in msim_replacement_text. */
53 for (i = 0; (code = msim_replacement_code[i]) 62 for (i = 0; (replacement = &msim_escape_replacements[i]); ++i)
54 && (text = msim_replacement_text[i]); ++i) 63 {
55 { 64 gchar *code, *text;
65
66 code = replacement->code;
67 text = replacement->text;
68
69 if (!code || !text)
70 break;
71
56 if (escape) 72 if (escape)
57 { 73 {
58 tmp = str_replace(msg, text, code); 74 tmp = str_replace(msg, text, code);
59 } 75 }
60 else 76 else