comparison libpurple/util.c @ 25518:db41905e7cc4

propagate from branch 'im.pidgin.pidgin' (head 9beed54f9b14fec268ec3cecae10261a9d43e1c8) to branch 'im.pidgin.pidgin.yaz' (head e24ce4535ecd0d4d1467b0ee4cdaea370bd507fd)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 24 Jun 2007 16:09:25 +0000
parents c5c265dff90c ff69c2a9ccf2
children 162a767a20d4
comparison
equal deleted inserted replaced
18264:a2c488006756 25518:db41905e7cc4
1186 1186
1187 if (check_value != '\0' && *p == check_value) 1187 if (check_value != '\0' && *p == check_value)
1188 return FALSE; 1188 return FALSE;
1189 1189
1190 q = strstr(p, end_token); 1190 q = strstr(p, end_token);
1191 if(q == NULL) //yaz
1192 return FALSE;
1191 1193
1192 /* Trim leading blanks */ 1194 /* Trim leading blanks */
1193 while (*p != '\n' && g_ascii_isspace(*p)) { 1195 while (*p != '\n' && g_ascii_isspace(*p)) {
1194 p += 1; 1196 p += 1;
1195 } 1197 }
1198 while (q > p && g_ascii_isspace(*(q - 1))) { 1200 while (q > p && g_ascii_isspace(*(q - 1))) {
1199 q -= 1; 1201 q -= 1;
1200 } 1202 }
1201 1203
1202 /* Don't bother with null strings */ 1204 /* Don't bother with null strings */
1203 if (p == q) 1205 if (p >= q)
1204 return FALSE; 1206 return FALSE;
1205 1207
1206 if (q != NULL && (!no_value_token || 1208 if (q != NULL && (!no_value_token ||
1207 (no_value_token && strncmp(p, no_value_token, 1209 (no_value_token && strncmp(p, no_value_token,
1208 strlen(no_value_token))))) 1210 strlen(no_value_token)))))
4420 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */ 4422 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */
4421 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */ 4423 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */
4422 #endif /* HAVE_SIGNAL_H */ 4424 #endif /* HAVE_SIGNAL_H */
4423 #endif /* !_WIN32 */ 4425 #endif /* !_WIN32 */
4424 } 4426 }
4427
4428
4429 void botch_ucs(gchar *ucs, gssize len)
4430 {
4431 gint i;
4432
4433 for(i=0;i<len;i+=2){
4434 switch(*(ucs+i)){
4435 case 0x00:
4436 switch(*(ucs+i+1)){
4437 case 0xa2: // ¢
4438 *(ucs+i) = 0xff;
4439 *(ucs+i+1) = 0xe0;
4440 break;
4441 case 0xa3: // £
4442 *(ucs+i) = 0xff;
4443 *(ucs+i+1) = 0xe1;
4444 break;
4445 case 0xac: // ¬
4446 *(ucs+i) = 0xff;
4447 *(ucs+i+1) = 0xe2;
4448 break;
4449 }
4450 break;
4451 case 0x20: // ‖
4452 if(*(ucs+i+1) == 0x16){
4453 *(ucs+i) = 0x22;
4454 *(ucs+i+1) = 0x25;
4455 }
4456 break;
4457 case 0x22: // −
4458 if(*(ucs+i+1) == 0x12){
4459 *(ucs+i) = 0xff;
4460 *(ucs+i+1) = 0x0d;
4461 }
4462 break;
4463 case 0x30: // 〜
4464 if(*(ucs+i+1) == 0x1c){
4465 *(ucs+i) = 0xff;
4466 *(ucs+i+1) = 0x5e;
4467 }
4468 break;
4469 }
4470 }
4471
4472 }
4473
4474 void sanitize_ucs(gchar *ucs, gssize len)
4475 {
4476 gint i;
4477
4478 for(i=0;i<len;i+=2){
4479 switch(*(ucs+i)){
4480 case 0x22:
4481 switch(*(ucs+i+1)){
4482 case 0x25: // ‖
4483 *(ucs+i) = 0x20;
4484 *(ucs+i+1) = 0x16;
4485 break;
4486 }
4487 break;
4488 case 0xff:
4489 switch(*(ucs+i+1)){
4490 case 0x0d: // −
4491 *(ucs+i) = 0x22;
4492 *(ucs+i+1) = 0x12;
4493 break;
4494 case 0x5e: // 〜
4495 *(ucs+i) = 0x30;
4496 *(ucs+i+1) = 0x1c;
4497 break;
4498 case 0xe0: // ¢
4499 *(ucs+i) = 0x00;
4500 *(ucs+i+1) = 0xa2;
4501 break;
4502 case 0xe1: // £
4503 *(ucs+i) = 0x00;
4504 *(ucs+i+1) = 0xa3;
4505 break;
4506 case 0xe2: // ¬
4507 *(ucs+i) = 0x00;
4508 *(ucs+i+1) = 0xac;
4509 break;
4510 }
4511 break;
4512 }
4513 }
4514 }
4515
4516 guchar *sanitize_utf(unsigned char *msg, size_t len, size_t *newlen)
4517 {
4518 gint i;
4519 size_t bytes;
4520 unsigned char *utf;
4521
4522 utf = g_strndup(msg, len);
4523
4524 bytes = len;
4525
4526 for(i=0;i<len;i++){
4527 switch(*(utf+i)){
4528 case 0xe2:
4529 if(*(utf+i+1) == 0x88) {
4530 if(*(utf+i+2) == 0xa5) { // ‖
4531 *(utf+i) = 0xe2;
4532 *(utf+i+1) = 0x80;
4533 *(utf+i+2) = 0x96;
4534 }
4535 }
4536 break;
4537 case 0xef:
4538 switch(*(utf+i+1)){
4539 case 0xbc:
4540 if(*(utf+i+2) == 0x8d) { // −
4541 *(utf+i) = 0xe2;
4542 *(utf+i+1) = 0x88;
4543 *(utf+i+2) = 0x92;
4544 }
4545 break;
4546 case 0xbd:
4547 if(*(utf+i+2) == 0x9e) { // 〜
4548 *(utf+i) = 0xe3;
4549 *(utf+i+1) = 0x80;
4550 *(utf+i+2) = 0x9c;
4551 }
4552 break;
4553 case 0xbf:
4554 switch(*(utf+i+2)){
4555 case 0xa0:// ¢
4556 *(utf+i) = 0xc2;
4557 *(utf+i+1) = 0xa2;
4558 memmove(utf+i+2, utf+i+3,
4559 len-i-3); //1byte詰める
4560 bytes--;
4561 break;
4562 case 0xa1: // £
4563 *(utf+i) = 0xc2;
4564 *(utf+i+1) = 0xa3;
4565 memmove(utf+i+2, utf+i+3,
4566 len-i-3); //1byte詰める
4567 bytes--;
4568 break;
4569 case 0xa2: // ¬
4570 *(utf+i) = 0xc2;
4571 *(utf+i+1) = 0xac;
4572 memmove(utf+i+2, utf+i+3,
4573 len-i-3); //1byte詰める
4574 bytes--;
4575 break;
4576 }
4577 break;
4578 }
4579 break;
4580 }
4581 }
4582 *(utf+bytes)= 0x00; //terminate
4583 *newlen = bytes;
4584 return utf;
4585 }
4586
4587
4588 guchar *botch_utf(const void *msg, size_t len, size_t *newlen)
4589 {
4590 int i,bytes;
4591 unsigned char *utf;
4592
4593 bytes = len;
4594
4595 utf = g_malloc0(bytes*3/2+1); /* new length might be 3/2 in the worst case */
4596 memcpy(utf, msg, bytes);
4597
4598 for(i=0;i<bytes;i++){
4599 switch(*(utf+i)){
4600 case 0xc2:
4601 switch(*(utf+i+1)){
4602 case 0xa2: // ¢
4603 *(utf+i) = 0xef;
4604 *(utf+i+1) = 0xbf;
4605 memmove(utf+i+3, utf+i+2, bytes-i-2);
4606 *(utf+i+2) = 0xa0;
4607 bytes++;
4608 break;
4609 case 0xa3: // £
4610 *(utf+i) = 0xef;
4611 *(utf+i+1) = 0xbf;
4612 memmove(utf+i+3, utf+i+2, bytes-i-2);
4613 *(utf+i+2) = 0xa1;
4614 bytes++;
4615 break;
4616 case 0xac: // ¬
4617 *(utf+i) = 0xef;
4618 *(utf+i+1) = 0xbf;
4619 memmove(utf+i+3, utf+i+2, bytes-i-2);
4620 *(utf+i+2) = 0xa2;
4621 bytes++;
4622 break;
4623 }
4624 break;
4625 case 0xe2:
4626 switch(*(utf+i+1)){
4627 case 0x80: // ‖
4628 if(*(utf+i+2) == 0x96){
4629 *(utf+i) = 0xe2;
4630 *(utf+i+1) = 0x88;
4631 *(utf+i+2) = 0xa5;
4632 }
4633 break;
4634 case 0x88: // −
4635 if(*(utf+i+1) == 0x92){
4636 *(utf+i) = 0xef;
4637 *(utf+i+1) = 0xbc;
4638 *(utf+i+2) = 0x8d;
4639 }
4640 break;
4641 }
4642 break;
4643 case 0xe3: // 〜
4644 if(*(utf+i+1) == 0x80){
4645 if(*(utf+i+2) == 0x9c){
4646 *(utf+i) = 0xef;
4647 *(utf+i+1) = 0xbd;
4648 *(utf+i+2) = 0x9e;
4649 }
4650 }
4651 break;
4652 } //switch
4653 }
4654 *(utf+bytes) = 0x00; //terminate
4655 *newlen = bytes;
4656 return utf;
4657 }