Ticket #2237 (closed defect: fixed)
msGetEncodedString does not work with wide strings
| Reported by: | hobu | Owned by: | sdlime |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.0 release |
| Component: | MapServer C Library | Version: | svn-trunk (development) |
| Severity: | normal | Keywords: | |
| Cc: | dmorissette, warmerdam |
Description
I have been unable to get msGetEncodedString to work when for drawing UTF-16 data out of ArcSDE. I went digging in the FDO code and found a macro called convert_wide_to_utf8 which seems to do the trick.
http://trac.osgeo.org/fdo/browser/trunk/Utilities/Common/Inc/FdoCommonStringUtil.h#L210
I'm not sure if the problem is really msGetEncodedString or that I shouldn't be passing it wide strings.
Have we tested msGetEncodedString very much since the changes in r6246 and r6244 were made?
case SE_NSTRING_TYPE:
shape->values[i] = (char *)malloc(itemdefs[i].size*sizeof(char)+1);
memset(shape->values[i], 0, itemdefs[i].size*sizeof(char)+1);
wide = (SE_WCHAR *)malloc(itemdefs[i].size*2*sizeof(SE_WCHAR)+1);
memset(wide, 0, itemdefs[i].size*2*sizeof(SE_WCHAR)+1);
status = SE_stream_get_nstring( sde->connPoolInfo->stream,
(short) (i+1),
wide);
int convFailed = MS_TRUE;
if (NULL != wide)
{
printf("Wide was not null!!n");
size_t szStr = wcslen (wide)+1;
printf("Size was %d\n", szStr);
wide_string = (char*)alloca (szStr * 6);
iconv_t rOpen = iconv_open("UTF-8", "UTF-16");
if ((iconv_t)-1 != rOpen)
{
size_t iSize_Out = szStr * 6;
size_t iSize_In = sizeof (wchar_t)*szStr;
printf("Size in: %d Size out: %d", iSize_In, iSize_Out);
char* p_utf8 = wide_string;
const wchar_t* p_w = wide;
size_t rConv = iconv(rOpen, (char**)&p_w, &iSize_In, &p_utf8,&iSize_Out);
if ((size_t)-1 != rConv && iSize_Out != (szStr * 6))
convFailed = MS_FALSE;
iconv_close(rOpen);
}
}
if (convFailed)
wide_string = NULL;
if (NULL==wide_string) printf("utf8 string was null!!!");
strcpy(shape->values[i], wide_string);
Change History
Note: See
TracTickets for help on using
tickets.
