comparison libpurple/util.c @ 25488:bb8ad59ae9c4

propagate from branch 'im.pidgin.pidgin' (head 62e9d17cd37551991c5040ce6ca48e6d7578dde3) to branch 'im.pidgin.pidgin.yaz' (head f809703c53ba0d2fc5eece06d368a3fcfec6748f)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 20 May 2007 04:16:11 +0000
parents e4ee1c5bd51e
children ddd3c6e238fe
comparison
equal deleted inserted replaced
17174:e5cc13b1e0ca 25488:bb8ad59ae9c4
1151 1151
1152 if (check_value != '\0' && *p == check_value) 1152 if (check_value != '\0' && *p == check_value)
1153 return FALSE; 1153 return FALSE;
1154 1154
1155 q = strstr(p, end_token); 1155 q = strstr(p, end_token);
1156 if(q == NULL) //yaz
1157 return FALSE;
1156 1158
1157 /* Trim leading blanks */ 1159 /* Trim leading blanks */
1158 while (*p != '\n' && g_ascii_isspace(*p)) { 1160 while (*p != '\n' && g_ascii_isspace(*p)) {
1159 p += 1; 1161 p += 1;
1160 } 1162 }
1163 while (q > p && g_ascii_isspace(*(q - 1))) { 1165 while (q > p && g_ascii_isspace(*(q - 1))) {
1164 q -= 1; 1166 q -= 1;
1165 } 1167 }
1166 1168
1167 /* Don't bother with null strings */ 1169 /* Don't bother with null strings */
1168 if (p == q) 1170 if (p >= q)
1169 return FALSE; 1171 return FALSE;
1170 1172
1171 if (q != NULL && (!no_value_token || 1173 if (q != NULL && (!no_value_token ||
1172 (no_value_token && strncmp(p, no_value_token, 1174 (no_value_token && strncmp(p, no_value_token,
1173 strlen(no_value_token))))) 1175 strlen(no_value_token)))))
4215 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */ 4217 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */
4216 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */ 4218 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */
4217 #endif /* HAVE_SIGNAL_H */ 4219 #endif /* HAVE_SIGNAL_H */
4218 #endif /* !_WIN32 */ 4220 #endif /* !_WIN32 */
4219 } 4221 }
4222
4223
4224 void botch_ucs(gchar *ucs, gssize len)
4225 {
4226 gint i;
4227
4228 for(i=0;i<len;i+=2){
4229 switch(*(ucs+i)){
4230 case 0x00:
4231 switch(*(ucs+i+1)){
4232 case 0xa2: // ¢
4233 *(ucs+i) = 0xff;
4234 *(ucs+i+1) = 0xe0;
4235 break;
4236 case 0xa3: // £
4237 *(ucs+i) = 0xff;
4238 *(ucs+i+1) = 0xe1;
4239 break;
4240 case 0xac: // ¬
4241 *(ucs+i) = 0xff;
4242 *(ucs+i+1) = 0xe2;
4243 break;
4244 }
4245 break;
4246 case 0x20: // ‖
4247 if(*(ucs+i+1) == 0x16){
4248 *(ucs+i) = 0x22;
4249 *(ucs+i+1) = 0x25;
4250 }
4251 break;
4252 case 0x22: // −
4253 if(*(ucs+i+1) == 0x12){
4254 *(ucs+i) = 0xff;
4255 *(ucs+i+1) = 0x0d;
4256 }
4257 break;
4258 case 0x30: // 〜
4259 if(*(ucs+i+1) == 0x1c){
4260 *(ucs+i) = 0xff;
4261 *(ucs+i+1) = 0x5e;
4262 }
4263 break;
4264 }
4265 }
4266
4267 }
4268
4269 void sanitize_ucs(gchar *ucs, gssize len)
4270 {
4271 gint i;
4272
4273 for(i=0;i<len;i+=2){
4274 switch(*(ucs+i)){
4275 case 0x22:
4276 switch(*(ucs+i+1)){
4277 case 0x25: // ‖
4278 *(ucs+i) = 0x20;
4279 *(ucs+i+1) = 0x16;
4280 break;
4281 }
4282 break;
4283 case 0xff:
4284 switch(*(ucs+i+1)){
4285 case 0x0d: // −
4286 *(ucs+i) = 0x22;
4287 *(ucs+i+1) = 0x12;
4288 break;
4289 case 0x5e: // 〜
4290 *(ucs+i) = 0x30;
4291 *(ucs+i+1) = 0x1c;
4292 break;
4293 case 0xe0: // ¢
4294 *(ucs+i) = 0x00;
4295 *(ucs+i+1) = 0xa2;
4296 break;
4297 case 0xe1: // £
4298 *(ucs+i) = 0x00;
4299 *(ucs+i+1) = 0xa3;
4300 break;
4301 case 0xe2: // ¬
4302 *(ucs+i) = 0x00;
4303 *(ucs+i+1) = 0xac;
4304 break;
4305 }
4306 break;
4307 }
4308 }
4309 }
4310
4311 guchar *sanitize_utf(unsigned char *msg, size_t len, size_t *newlen)
4312 {
4313 gint i;
4314 size_t bytes;
4315 unsigned char *utf;
4316
4317 utf = g_strndup(msg, len);
4318
4319 bytes = len;
4320
4321 for(i=0;i<len;i++){
4322 switch(*(utf+i)){
4323 case 0xe2:
4324 if(*(utf+i+1) == 0x88) {
4325 if(*(utf+i+2) == 0xa5) { // ‖
4326 *(utf+i) = 0xe2;
4327 *(utf+i+1) = 0x80;
4328 *(utf+i+2) = 0x96;
4329 }
4330 }
4331 break;
4332 case 0xef:
4333 switch(*(utf+i+1)){
4334 case 0xbc:
4335 if(*(utf+i+2) == 0x8d) { // −
4336 *(utf+i) = 0xe2;
4337 *(utf+i+1) = 0x88;
4338 *(utf+i+2) = 0x92;
4339 }
4340 break;
4341 case 0xbd:
4342 if(*(utf+i+2) == 0x9e) { // 〜
4343 *(utf+i) = 0xe3;
4344 *(utf+i+1) = 0x80;
4345 *(utf+i+2) = 0x9c;
4346 }
4347 break;
4348 case 0xbf:
4349 switch(*(utf+i+2)){
4350 case 0xa0:// ¢
4351 *(utf+i) = 0xc2;
4352 *(utf+i+1) = 0xa2;
4353 memmove(utf+i+2, utf+i+3,
4354 len-i-3); //1byte詰める
4355 bytes--;
4356 break;
4357 case 0xa1: // £
4358 *(utf+i) = 0xc2;
4359 *(utf+i+1) = 0xa3;
4360 memmove(utf+i+2, utf+i+3,
4361 len-i-3); //1byte詰める
4362 bytes--;
4363 break;
4364 case 0xa2: // ¬
4365 *(utf+i) = 0xc2;
4366 *(utf+i+1) = 0xac;
4367 memmove(utf+i+2, utf+i+3,
4368 len-i-3); //1byte詰める
4369 bytes--;
4370 break;
4371 }
4372 break;
4373 }
4374 break;
4375 }
4376 }
4377 *(utf+bytes)= 0x00; //terminate
4378 *newlen = bytes;
4379 return utf;
4380 }
4381
4382
4383 guchar *botch_utf(const void *msg, size_t len, size_t *newlen)
4384 {
4385 int i,bytes;
4386 unsigned char *utf;
4387
4388 bytes = len;
4389
4390 utf = g_malloc0(bytes*3/2+1); /* new length might be 3/2 in the worst case */
4391 memcpy(utf, msg, bytes);
4392
4393 for(i=0;i<bytes;i++){
4394 switch(*(utf+i)){
4395 case 0xc2:
4396 switch(*(utf+i+1)){
4397 case 0xa2: // ¢
4398 *(utf+i) = 0xef;
4399 *(utf+i+1) = 0xbf;
4400 memmove(utf+i+3, utf+i+2, bytes-i-2);
4401 *(utf+i+2) = 0xa0;
4402 bytes++;
4403 break;
4404 case 0xa3: // £
4405 *(utf+i) = 0xef;
4406 *(utf+i+1) = 0xbf;
4407 memmove(utf+i+3, utf+i+2, bytes-i-2);
4408 *(utf+i+2) = 0xa1;
4409 bytes++;
4410 break;
4411 case 0xac: // ¬
4412 *(utf+i) = 0xef;
4413 *(utf+i+1) = 0xbf;
4414 memmove(utf+i+3, utf+i+2, bytes-i-2);
4415 *(utf+i+2) = 0xa2;
4416 bytes++;
4417 break;
4418 }
4419 break;
4420 case 0xe2:
4421 switch(*(utf+i+1)){
4422 case 0x80: // ‖
4423 if(*(utf+i+2) == 0x96){
4424 *(utf+i) = 0xe2;
4425 *(utf+i+1) = 0x88;
4426 *(utf+i+2) = 0xa5;
4427 }
4428 break;
4429 case 0x88: // −
4430 if(*(utf+i+1) == 0x92){
4431 *(utf+i) = 0xef;
4432 *(utf+i+1) = 0xbc;
4433 *(utf+i+2) = 0x8d;
4434 }
4435 break;
4436 }
4437 break;
4438 case 0xe3: // 〜
4439 if(*(utf+i+1) == 0x80){
4440 if(*(utf+i+2) == 0x9c){
4441 *(utf+i) = 0xef;
4442 *(utf+i+1) = 0xbd;
4443 *(utf+i+2) = 0x9e;
4444 }
4445 }
4446 break;
4447 } //switch
4448 }
4449 *(utf+bytes) = 0x00; //terminate
4450 *newlen = bytes;
4451 return utf;
4452 }