X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=utf8%2Futf8-convert.c;h=264cb9aa015a9cfe54bfa7c0f8aa1e4abda2b03c;hb=7e2a5e6be271d2745e9d7d5b764102c2a213445a;hp=926e14c41305d7e4741caf3fc3eb27331c06544b;hpb=4c5bbb2dff95ecfd854f47af33e3e05d59bae3b5;p=gedcom-parse.git diff --git a/utf8/utf8-convert.c b/utf8/utf8-convert.c index 926e14c..264cb9a 100644 --- a/utf8/utf8-convert.c +++ b/utf8/utf8-convert.c @@ -1,15 +1,26 @@ /* Encoding utility from UTF-8 to another charset and vice versa Copyright (C) 2001, 2002 Peter Verthez - Permission granted to do anything with this file that you want, as long - as the above copyright is retained in all copies. - THERE IS NO WARRANTY - USE AT YOUR OWN RISK + The UTF8 tools library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The Gedcom parser library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the Gedcom parser library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ /* $Id$ */ /* $Name$ */ -#include "utf8.h" +#include "utf8tools.h" #include #include #include @@ -37,7 +48,7 @@ struct convert { char* unknown; }; -void reset_conv_buffer(conv_buffer_t buf) +static void reset_conv_buffer(conv_buffer_t buf) { memset(buf->buffer, 0, buf->size); } @@ -70,7 +81,7 @@ void free_conv_buffer(conv_buffer_t buf) } } -char* grow_conv_buffer(conv_buffer_t buf, char* curr_pos) +static char* grow_conv_buffer(conv_buffer_t buf, char* curr_pos) { size_t outlen, new_size; char* new_buffer; @@ -190,17 +201,18 @@ void cleanup_utf8_conversion(convert_t conv) char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails, size_t* output_len) { - size_t insize = strlen(input); + size_t insize; size_t outsize; ICONV_CONST char* inptr = (ICONV_CONST char*) input; char *outptr; size_t nconv; struct conv_buffer* outbuf; - if (!conv || !conv->outbuf) { - if (conv_fails != NULL) *conv_fails = insize; + if (!conv || !conv->outbuf || !input) { + if (conv_fails != NULL) *conv_fails = (input ? strlen(input) : 0); return NULL; } + insize = strlen(input); /* make sure we start from an empty state */ iconv(conv->from_utf8, NULL, NULL, NULL, NULL); if (conv_fails != NULL) *conv_fails = 0; @@ -259,7 +271,7 @@ char* convert_to_utf8(convert_t conv, const char* input, size_t input_len) size_t nconv; struct conv_buffer* outbuf; - if (!conv || !conv->outbuf) + if (!conv || !conv->outbuf || !input) return NULL; /* make sure we start from an empty state */ iconv(conv->to_utf8, NULL, NULL, NULL, NULL); @@ -306,6 +318,13 @@ char* convert_to_utf8_incremental(convert_t conv, if (!conv || !conv->outbuf) return NULL; + if (!input) { + iconv(conv->to_utf8, NULL, NULL, NULL, NULL); + reset_conv_buffer(inbuf); + conv->insize = 0; + return NULL; + } + /* set up input buffer (concatenate to what was left previous time) */ /* can't use strcpy, because possible null bytes from unicode */ while (conv->insize + input_len > inbuf->size)