PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ utf8()

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

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

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