|
a/src/utils/transcode.cpp |
|
b/src/utils/transcode.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: transcode.cpp,v 1.4 2005-11-24 07:16:16 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: transcode.cpp,v 1.5 2005-11-30 17:58:42 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
|
4 |
|
5 |
#ifndef TEST_TRANSCODE
|
5 |
#ifndef TEST_TRANSCODE
|
6 |
|
6 |
|
7 |
#include <errno.h>
|
7 |
#include <errno.h>
|
|
... |
|
... |
13 |
#endif /* NO_NAMESPACES */
|
13 |
#endif /* NO_NAMESPACES */
|
14 |
|
14 |
|
15 |
#include <iconv.h>
|
15 |
#include <iconv.h>
|
16 |
|
16 |
|
17 |
#include "transcode.h"
|
17 |
#include "transcode.h"
|
|
|
18 |
#include "debuglog.h"
|
18 |
|
19 |
|
|
|
20 |
#if !defined(_LIBICONV_VERSION)
|
|
|
21 |
#define CHARPP (char **)
|
|
|
22 |
#else
|
|
|
23 |
#define CHARPP
|
|
|
24 |
#endif
|
19 |
|
25 |
|
20 |
bool transcode(const string &in, string &out, const string &icode,
|
26 |
bool transcode(const string &in, string &out, const string &icode,
|
21 |
const string &ocode)
|
27 |
const string &ocode)
|
22 |
{
|
28 |
{
|
23 |
iconv_t ic;
|
29 |
iconv_t ic;
|
|
... |
|
... |
40 |
|
46 |
|
41 |
while (isiz > 0) {
|
47 |
while (isiz > 0) {
|
42 |
size_t osiz;
|
48 |
size_t osiz;
|
43 |
op = obuf;
|
49 |
op = obuf;
|
44 |
osiz = OBSIZ;
|
50 |
osiz = OBSIZ;
|
45 |
if(iconv(ic,
|
51 |
int isiz0=isiz;
|
46 |
#if defined(_LIBICONV_VERSION)
|
52 |
|
47 |
&ip,
|
53 |
if(iconv(ic, CHARPP&ip, &isiz, &op, &osiz) == (size_t)-1 &&
|
48 |
#else
|
54 |
errno != E2BIG) {
|
49 |
(char **)&ip,
|
55 |
#if 0
|
50 |
#endif
|
|
|
51 |
&isiz, &op, &osiz) == (size_t)-1 && errno != E2BIG){
|
|
|
52 |
out.erase();
|
56 |
out.erase();
|
53 |
out = string("iconv failed for ") + icode + " -> " + ocode +
|
57 |
out = string("iconv failed for ") + icode + " -> " + ocode +
|
54 |
" : " + strerror(errno);
|
58 |
" : " + strerror(errno);
|
|
|
59 |
#endif
|
|
|
60 |
if (errno == EILSEQ) {
|
|
|
61 |
LOGDEB(("transcode:iconv: bad input seq.: shift, retry\n"));
|
|
|
62 |
LOGDEB1((" Input consumed %d output produced %d\n",
|
|
|
63 |
ip - in.c_str(), out.length() + OBSIZ - osiz));
|
|
|
64 |
out.append(obuf, OBSIZ - osiz);
|
|
|
65 |
out += "?";
|
|
|
66 |
ip++;isiz--;
|
|
|
67 |
continue;
|
|
|
68 |
}
|
55 |
goto error;
|
69 |
goto error;
|
56 |
}
|
70 |
}
|
|
|
71 |
|
57 |
out.append(obuf, OBSIZ - osiz);
|
72 |
out.append(obuf, OBSIZ - osiz);
|
58 |
}
|
73 |
}
|
59 |
|
74 |
|
60 |
if(iconv_close(ic) == -1) {
|
75 |
if(iconv_close(ic) == -1) {
|
61 |
out.erase();
|
76 |
out.erase();
|
|
... |
|
... |
66 |
icopen = false;
|
81 |
icopen = false;
|
67 |
ret = true;
|
82 |
ret = true;
|
68 |
error:
|
83 |
error:
|
69 |
if (icopen)
|
84 |
if (icopen)
|
70 |
iconv_close(ic);
|
85 |
iconv_close(ic);
|
|
|
86 |
//fprintf(stderr, "TRANSCODE OUT:\n%s\n", out.c_str());
|
71 |
return ret;
|
87 |
return ret;
|
72 |
}
|
88 |
}
|
73 |
|
89 |
|
74 |
|
90 |
|
75 |
#else
|
91 |
#else
|