PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ utf8()

static int utf8 ( const char *  fromcode,
char *  inputbuf,
char **  outputbuf 
)
static

Definition at line 60 of file shp2pgsql-core.c.

61 {
62  iconv_t cd;
63  char *outputptr;
64  size_t outbytesleft;
65  size_t inbytesleft;
66 
67  inbytesleft = strlen(inputbuf);
68 
69  cd = iconv_open("UTF-8", fromcode);
70  if ( cd == ((iconv_t)(-1)) )
71  return UTF8_NO_RESULT;
72 
73  outbytesleft = inbytesleft * 3 + 1; /* UTF8 string can be 3 times larger */
74  /* then local string */
75  *outputbuf = (char *)malloc(outbytesleft);
76  if (!*outputbuf)
77  return UTF8_NO_RESULT;
78 
79  memset(*outputbuf, 0, outbytesleft);
80  outputptr = *outputbuf;
81 
82  /* Does this string convert cleanly? */
83  if ( iconv(cd, &inputbuf, &inbytesleft, &outputptr, &outbytesleft) == (size_t)-1 )
84  {
85 #ifdef HAVE_ICONVCTL
86  int on = 1;
87  /* No. Try to convert it while transliterating. */
88  iconvctl(cd, ICONV_SET_TRANSLITERATE, &on);
89  if ( iconv(cd, &inputbuf, &inbytesleft, &outputptr, &outbytesleft) == -1 )
90  {
91  /* No. Try to convert it while discarding errors. */
92  iconvctl(cd, ICONV_SET_DISCARD_ILSEQ, &on);
93  if ( iconv(cd, &inputbuf, &inbytesleft, &outputptr, &outbytesleft) == -1 )
94  {
95  /* Still no. Throw away the buffer and return. */
96  free(*outputbuf);
97  iconv_close(cd);
98  return UTF8_NO_RESULT;
99  }
100  }
101  iconv_close(cd);
102  return UTF8_BAD_RESULT;
103 #else
104  free(*outputbuf);
105  iconv_close(cd);
106  return UTF8_NO_RESULT;
107 #endif
108  }
109  /* Return a good result, converted string is in buffer. */
110  iconv_close(cd);
111  return UTF8_GOOD_RESULT;
112 }
void * malloc(YYSIZE_T)
void free(void *)
#define UTF8_GOOD_RESULT
#define UTF8_BAD_RESULT
#define UTF8_NO_RESULT

References free(), malloc(), UTF8_BAD_RESULT, UTF8_GOOD_RESULT, and UTF8_NO_RESULT.

Referenced by ShpLoaderGenerateSQLRowStatement(), and ShpLoaderOpenShape().

Here is the call graph for this function:
Here is the caller graph for this function: