- Timestamp:
- 2006-06-03T20:20:43Z (18 years ago)
- Branches:
- master
- Children:
- 5973412
- Parents:
- a15c097 (diff), fb62f81f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
util.c
ra15c097 r9779c18 445 445 } 446 446 #endif 447 448 /* Convert from one charset to another. 449 450 from_cs, to_cs: Source and destination charsets 451 src, dst: Source and destination strings 452 size: Size if src. 0 == use strlen(). strlen() is not reliable for UNICODE/UTF16 strings though. 453 maxbuf: Maximum number of bytes to write to dst 454 455 Returns the number of bytes written to maxbuf or -1 on an error. 456 */ 457 signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf ) 458 { 459 GIConv cd; 460 size_t res; 461 size_t inbytesleft, outbytesleft; 462 char *inbuf = src; 463 char *outbuf = dst; 464 465 cd = g_iconv_open( to_cs, from_cs ); 466 if( cd == (GIConv) -1 ) 467 return( -1 ); 468 469 inbytesleft = size ? size : strlen( src ); 470 outbytesleft = maxbuf - 1; 471 res = g_iconv( cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft ); 472 *outbuf = '\0'; 473 g_iconv_close( cd ); 474 475 if( res == (size_t) -1 ) 476 return( -1 ); 477 else 478 return( outbuf - dst ); 479 } 480 481 char *set_eval_charset( irc_t *irc, set_t *set, char *value ) 482 { 483 GIConv cd; 484 485 if ( g_strncasecmp( value, "none", 4 ) == 0 ) 486 return( value ); 487 488 cd = g_iconv_open( "UTF-8", value ); 489 if( cd == (GIConv) -1 ) 490 return( NULL ); 491 492 g_iconv_close( cd ); 493 return( value ); 494 }
Note: See TracChangeset
for help on using the changeset viewer.