Browse code

pdf string UTF-16 conversion no longer solely depends on ICONV reason: no ICONV meant no conversion even though conversion function existed

Kevin Lin authored on 2015/03/03 08:55:02
Showing 1 changed files
... ...
@@ -74,14 +74,17 @@ char *pdf_convert_utf(char *begin, size_t sz);
74 74
 char *pdf_convert_utf(char *begin, size_t sz)
75 75
 {
76 76
     char *res=NULL;
77
+    char *buf, *outbuf;
78
+    size_t sz2, i;
77 79
 #if HAVE_ICONV
78
-    char *buf, *outbuf, *p1, *p2;
79
-    size_t sz2, inlen, outlen, i;
80
+    char *p1, *p2;
81
+    size_t inlen, outlen;
80 82
     char *encodings[] = {
81 83
         "UTF-16",
82 84
         NULL
83 85
     };
84 86
     iconv_t cd;
87
+#endif
85 88
 
86 89
     buf = cli_calloc(1, sz);
87 90
     if (!(buf))
... ...
@@ -139,7 +142,9 @@ char *pdf_convert_utf(char *begin, size_t sz)
139 139
             }
140 140
         } else
141 141
             buf[sz2++] = begin[i]; 
142
+        cli_dbgmsg("%c\n", buf[sz2-1]);
142 143
     }
144
+#if HAVE_ICONV
143 145
     //memcpy(buf, begin, sz);
144 146
     p1 = buf;
145 147
 
... ...
@@ -174,19 +179,16 @@ char *pdf_convert_utf(char *begin, size_t sz)
174 174
         iconv_close(cd);
175 175
         break;
176 176
     }
177
+#else
178
+    outbuf = cli_utf16_to_utf8(buf, sz2, UTF16_BOM);
179
+    if (!outbuf)
180
+        return NULL;
177 181
 
182
+    res = strdup(outbuf);
183
+#endif
178 184
     free(buf);
179 185
     free(outbuf);
180 186
     return res;
181
-#else
182
-    res = cli_calloc(sz+1, 1);
183
-    if ((res)) {
184
-        memcpy(res, begin, sz);
185
-        res[sz] = '\0';
186
-    }
187
-
188
-    return res;
189
-#endif
190 187
 }
191 188
 
192 189
 int is_object_reference(char *begin, char **endchar, uint32_t *id)