| 279 g_strfreev(encodings); |
279 g_strfreev(encodings); |
| 280 |
280 |
| 281 return purple_utf8_salvage(string); |
281 return purple_utf8_salvage(string); |
| 282 } |
282 } |
| 283 |
283 |
| |
284 /* This function is shamelessly stolen from glib--it is an old version of the |
| |
285 * private function append_escaped_text, used by g_markup_escape_text, whose |
| |
286 * behavior changed in glib 2.12. */ |
| |
287 static void irc_append_escaped_text(GString *str, const char *text, gssize length) |
| |
288 { |
| |
289 const char *p = text; |
| |
290 const char *end = text + length; |
| |
291 const char *next = NULL; |
| |
292 |
| |
293 while(p != end) { |
| |
294 next = g_utf8_next_char(p); |
| |
295 |
| |
296 switch(*p) { |
| |
297 case '&': |
| |
298 g_string_append(str, "&"); |
| |
299 break; |
| |
300 case '<': |
| |
301 g_string_append(str, "<"); |
| |
302 break; |
| |
303 case '>': |
| |
304 g_string_append(str, ">"); |
| |
305 break; |
| |
306 case '\'': |
| |
307 g_string_append(str, "'"); |
| |
308 break; |
| |
309 case '"': |
| |
310 g_string_append(str, """); |
| |
311 break; |
| |
312 default: |
| |
313 g_string_append_len(str, p, next - p); |
| |
314 break; |
| |
315 } |
| |
316 |
| |
317 p = next; |
| |
318 } |
| |
319 } |
| |
320 |
| |
321 /* This function is shamelessly stolen from glib--it is an old version of the |
| |
322 * function g_markup_escape_text, whose behavior changed in glib 2.12. */ |
| |
323 char *irc_escape_privmsg(const char *text, gssize length) |
| |
324 { |
| |
325 GString *str; |
| |
326 |
| |
327 g_return_val_if_fail(text != NULL, NULL); |
| |
328 |
| |
329 if(length < 0) |
| |
330 length = strlen(text); |
| |
331 |
| |
332 str = g_string_sized_new(length); |
| |
333 |
| |
334 irc_append_escaped_text(str, text, length); |
| |
335 |
| |
336 return g_string_free(str, FALSE); |
| |
337 } |
| |
338 |
| 284 /* XXX tag closings are not necessarily correctly nested here! If we |
339 /* XXX tag closings are not necessarily correctly nested here! If we |
| 285 * get a ^O or reach the end of the string and there are open |
340 * get a ^O or reach the end of the string and there are open |
| 286 * tags, they are closed in a fixed order ... this means, for |
341 * tags, they are closed in a fixed order ... this means, for |
| 287 * example, you might see <FONT COLOR="blue">some text <B>with |
342 * example, you might see <FONT COLOR="blue">some text <B>with |
| 288 * various attributes</FONT></B> (notice that B and FONT overlap |
343 * various attributes</FONT></B> (notice that B and FONT overlap |