|
a/unac/unac.c |
|
b/unac/unac.c |
|
... |
|
... |
10446 |
int out_size;
|
10446 |
int out_size;
|
10447 |
int out_length;
|
10447 |
int out_length;
|
10448 |
int i;
|
10448 |
int i;
|
10449 |
|
10449 |
|
10450 |
out_size = in_length > 0 ? in_length : 1024;
|
10450 |
out_size = in_length > 0 ? in_length : 1024;
|
10451 |
if (*outp) {
|
10451 |
|
10452 |
out = *outp;
|
10452 |
out = *outp;
|
10453 |
/* +1 for null */
|
|
|
10454 |
out = realloc(out, out_size + 1);
|
10453 |
out = realloc(out, out_size + 1);
|
10455 |
if(out == 0) {
|
10454 |
if(out == 0) {
|
10456 |
if(debug_level >= UNAC_DEBUG_LOW)
|
10455 |
if(debug_level >= UNAC_DEBUG_LOW)
|
10457 |
DEBUG("realloc %d bytes failed\n", out_size+1);
|
10456 |
DEBUG("realloc %d bytes failed\n", out_size+1);
|
10458 |
/* *outp is still valid. Let the caller free it */
|
10457 |
/* *outp is still valid. Let the caller free it */
|
10459 |
return -1;
|
10458 |
return -1;
|
10460 |
}
|
|
|
10461 |
} else {
|
|
|
10462 |
/* +1 for null */
|
|
|
10463 |
out = malloc(out_size + 1);
|
|
|
10464 |
if (out == 0) {
|
|
|
10465 |
if(debug_level >= UNAC_DEBUG_LOW)
|
|
|
10466 |
DEBUG("malloc %d bytes failed\n", out_size+1);
|
|
|
10467 |
return -1;
|
|
|
10468 |
}
|
|
|
10469 |
}
|
10459 |
}
|
|
|
10460 |
|
10470 |
out_length = 0;
|
10461 |
out_length = 0;
|
10471 |
|
10462 |
|
10472 |
for(i = 0; i < in_length; i += 2) {
|
10463 |
for(i = 0; i < in_length; i += 2) {
|
10473 |
unsigned short c;
|
10464 |
unsigned short c;
|
10474 |
unsigned short* p;
|
10465 |
unsigned short* p;
|
|
... |
|
... |
10621 |
}
|
10612 |
}
|
10622 |
u16tou8 = from_utf16 && to_utf8;
|
10613 |
u16tou8 = from_utf16 && to_utf8;
|
10623 |
u8tou16 = from_utf8 && to_utf16;
|
10614 |
u8tou16 = from_utf8 && to_utf16;
|
10624 |
|
10615 |
|
10625 |
out_size = in_length > 0 ? in_length : 1024;
|
10616 |
out_size = in_length > 0 ? in_length : 1024;
|
10626 |
if(*outp) {
|
10617 |
|
10627 |
out = *outp;
|
10618 |
out = *outp;
|
10628 |
/* +1 for null */
|
|
|
10629 |
out = realloc(out, out_size + 1);
|
10619 |
out = realloc(out, out_size + 1);
|
10630 |
if(out == 0) {
|
10620 |
if(out == 0) {
|
10631 |
/* *outp still valid, no freeing */
|
10621 |
/* *outp still valid, no freeing */
|
10632 |
if(debug_level >= UNAC_DEBUG_LOW)
|
10622 |
if(debug_level >= UNAC_DEBUG_LOW)
|
10633 |
DEBUG("realloc %d bytes failed\n", out_size+1);
|
10623 |
DEBUG("realloc %d bytes failed\n", out_size+1);
|
10634 |
goto out;
|
10624 |
goto out;
|
10635 |
}
|
|
|
10636 |
} else {
|
|
|
10637 |
/* +1 for null */
|
|
|
10638 |
out = malloc(out_size + 1);
|
|
|
10639 |
if(out == 0) {
|
|
|
10640 |
if(debug_level >= UNAC_DEBUG_LOW)
|
|
|
10641 |
DEBUG("malloc %d bytes failed\n", out_size+1);
|
|
|
10642 |
goto out;
|
|
|
10643 |
}
|
|
|
10644 |
}
|
10625 |
}
|
|
|
10626 |
|
10645 |
out_remain = out_size;
|
10627 |
out_remain = out_size;
|
10646 |
out_base = out;
|
10628 |
out_base = out;
|
10647 |
|
10629 |
|
10648 |
if (u8tou16) {
|
10630 |
if (u8tou16) {
|
10649 |
if (u8tou16_cd == (iconv_t)-1) {
|
10631 |
if (u8tou16_cd == (iconv_t)-1) {
|
|
... |
|
... |
10754 |
pthread_mutex_unlock(&o_unac_mutex);
|
10736 |
pthread_mutex_unlock(&o_unac_mutex);
|
10755 |
return ret;
|
10737 |
return ret;
|
10756 |
}
|
10738 |
}
|
10757 |
|
10739 |
|
10758 |
int unacmaybefold_string(const char* charset,
|
10740 |
int unacmaybefold_string(const char* charset,
|
10759 |
const char* in, size_t in_length,
|
10741 |
const char* in, size_t in_length,
|
10760 |
char** outp, size_t* out_lengthp, int dofold)
|
10742 |
char** outp, size_t* out_lengthp, int dofold)
|
10761 |
{
|
10743 |
{
|
10762 |
/*
|
10744 |
/*
|
10763 |
* When converting an empty string, skip everything but alloc the
|
10745 |
* When converting an empty string, skip everything but alloc the
|
10764 |
* buffer if NULL pointer.
|
10746 |
* buffer if NULL pointer.
|