PostGIS  2.1.10dev-r@@SVN_REVISION@@
int utf8 ( const char *  fromcode,
char *  inputbuf,
char **  outputbuf 
)

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

References UTF8_BAD_RESULT, UTF8_GOOD_RESULT, and UTF8_NO_RESULT.

Referenced by ShpLoaderGenerateSQLRowStatement(), and ShpLoaderOpenShape().

81 {
82  iconv_t cd;
83  char *outputptr;
84  size_t outbytesleft;
85  size_t inbytesleft;
86 
87  inbytesleft = strlen(inputbuf);
88 
89  cd = iconv_open("UTF-8", fromcode);
90  if ( cd == ((iconv_t)(-1)) )
91  return UTF8_NO_RESULT;
92 
93  outbytesleft = inbytesleft * 3 + 1; /* UTF8 string can be 3 times larger */
94  /* then local string */
95  *outputbuf = (char *)malloc(outbytesleft);
96  if (!*outputbuf)
97  return UTF8_NO_RESULT;
98 
99  memset(*outputbuf, 0, outbytesleft);
100  outputptr = *outputbuf;
101 
102  /* Does this string convert cleanly? */
103  if ( iconv(cd, &inputbuf, &inbytesleft, &outputptr, &outbytesleft) == -1 )
104  {
105 #ifdef HAVE_ICONVCTL
106  int on = 1;
107  /* No. Try to convert it while transliterating. */
108  iconvctl(cd, ICONV_SET_TRANSLITERATE, &on);
109  if ( iconv(cd, &inputbuf, &inbytesleft, &outputptr, &outbytesleft) == -1 )
110  {
111  /* No. Try to convert it while discarding errors. */
112  iconvctl(cd, ICONV_SET_DISCARD_ILSEQ, &on);
113  if ( iconv(cd, &inputbuf, &inbytesleft, &outputptr, &outbytesleft) == -1 )
114  {
115  /* Still no. Throw away the buffer and return. */
116  free(*outputbuf);
117  iconv_close(cd);
118  return UTF8_NO_RESULT;
119  }
120  }
121  iconv_close(cd);
122  return UTF8_BAD_RESULT;
123 #else
124  free(*outputbuf);
125  iconv_close(cd);
126  return UTF8_NO_RESULT;
127 #endif
128  }
129  /* Return a good result, converted string is in buffer. */
130  iconv_close(cd);
131  return UTF8_GOOD_RESULT;
132 }
#define UTF8_BAD_RESULT
#define UTF8_GOOD_RESULT
#define UTF8_NO_RESULT

Here is the caller graph for this function: