comparison src/util.c @ 11153:8e600ee6ec61

[gaim-migrate @ 13235] sf patch #1243998, from Evan Schoenberg, also some changes by me Basically novell needed a prpl->normalize function that didn't remove spaces. But I didn't like having the default normalize code make the string lowercase and remove spaces, so I changed the default to basically do nothing. Anyhoo, if you think of yourself as the primary contact for one of the PRPLs, you may want to make sure your PRPL has a normalize function, if it needs one. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 24 Jul 2005 19:36:22 +0000
parents ee059fe9b362
children 6932df31225f
comparison
equal deleted inserted replaced
11152:c25b3815d781 11153:8e600ee6ec61
2241 2241
2242 /************************************************************************** 2242 /**************************************************************************
2243 * String Functions 2243 * String Functions
2244 **************************************************************************/ 2244 **************************************************************************/
2245 const char * 2245 const char *
2246 gaim_normalize(const GaimAccount *account, const char *s) 2246 gaim_normalize(const GaimAccount *account, const char *str)
2247 { 2247 {
2248 GaimPlugin *prpl = NULL; 2248 GaimPlugin *prpl = NULL;
2249 GaimPluginProtocolInfo *prpl_info = NULL; 2249 GaimPluginProtocolInfo *prpl_info = NULL;
2250 const char *ret = NULL; 2250 const char *ret = NULL;
2251 2251
2254 2254
2255 if(prpl) 2255 if(prpl)
2256 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); 2256 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
2257 2257
2258 if(prpl_info && prpl_info->normalize) 2258 if(prpl_info && prpl_info->normalize)
2259 ret = prpl_info->normalize(account, s); 2259 ret = prpl_info->normalize(account, str);
2260 2260
2261 if(!ret) { 2261 if(!ret)
2262 {
2262 static char buf[BUF_LEN]; 2263 static char buf[BUF_LEN];
2263 char *tmp; 2264 char *tmp;
2264 int i, j; 2265
2265 2266 tmp = g_utf8_normalize(str, -1, G_NORMALIZE_DEFAULT);
2266 g_return_val_if_fail(s != NULL, NULL);
2267
2268 strncpy(buf, s, BUF_LEN);
2269 for (i=0, j=0; buf[j]; i++, j++) {
2270 while (buf[j] == ' ')
2271 j++;
2272 buf[i] = buf[j];
2273 }
2274 buf[i] = '\0';
2275
2276 tmp = g_utf8_strdown(buf, -1);
2277 g_snprintf(buf, sizeof(buf), "%s", tmp); 2267 g_snprintf(buf, sizeof(buf), "%s", tmp);
2278 g_free(tmp); 2268 g_free(tmp);
2279 tmp = g_utf8_normalize(buf, -1, G_NORMALIZE_DEFAULT);
2280 g_snprintf(buf, sizeof(buf), "%s", tmp);
2281 g_free(tmp);
2282 2269
2283 ret = buf; 2270 ret = buf;
2284 } 2271 }
2272
2285 return ret; 2273 return ret;
2274 }
2275
2276 /*
2277 * You probably don't want to call this directly, it is
2278 * mainly for use as a PRPL callback function. See the
2279 * comments in util.h.
2280 */
2281 const char *
2282 gaim_normalize_nocase(const GaimAccount *account, const char *str)
2283 {
2284 static char buf[BUF_LEN];
2285 char *tmp1, *tmp2;
2286
2287 g_return_val_if_fail(str != NULL, NULL);
2288
2289 tmp1 = g_utf8_strdown(str, -1);
2290 tmp2 = g_utf8_normalize(tmp1, -1, G_NORMALIZE_DEFAULT);
2291 g_snprintf(buf, sizeof(buf), "%s", tmp2);
2292 g_free(tmp2);
2293 g_free(tmp1);
2294
2295 return buf;
2286 } 2296 }
2287 2297
2288 gchar * 2298 gchar *
2289 gaim_str_sub_away_formatters(const char *str, const char *name) 2299 gaim_str_sub_away_formatters(const char *str, const char *name)
2290 { 2300 {