本文整理汇总了C++中CGUIString::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ CGUIString::clear方法的具体用法?C++ CGUIString::clear怎么用?C++ CGUIString::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGUIString
的用法示例。
在下文中一共展示了CGUIString::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CGUIException
//------------------------------------------------------------------------------
int IGUIStringConv_iconv::WCharToUtf8( const CGUIStringW& rSrc, CGUIString& rDst )
{
if( rSrc.empty())
{
rDst.clear();
return 0;
}
//open iconv
iconv_t cd = iconv_open ("UTF-8", "UTF-16LE");
if( cd == (iconv_t)-1 )
{
throw CGUIException(
"[WCharToUtf8]: failed to open iconv, errno is %d",
errno);
return -1;
}
//convert
size_t buf_size = rSrc.size()*4+1;
size_t inbytesleft = rSrc.size()*2;
size_t outbytesleft = buf_size;
char* dst = (char*)(new char[buf_size]);
char* pOutBuf = NULL;
char* pInBuf = (char*)rSrc.c_str();
bool bError = false;
while(inbytesleft > 0)
{
pOutBuf = dst;
outbytesleft = buf_size;
size_t retbytes = iconv(cd, &pInBuf, &inbytesleft, &pOutBuf, &outbytesleft);
//int errno_save = errno;
if (dst != pOutBuf)
{
// we have something to write
rDst.append(dst, (pOutBuf-dst));
}
//check ret
if( retbytes == size_t(-1) )
{
if( errno == E2BIG )
{
continue;
}
else
{
bError = true;
break;
}
}
else
{
//success
break;
}
}
delete[] dst;
if( bError)
{
switch(errno)
{
case EILSEQ:
throw CGUIException(
"[WCharToUtf8]: failed to iconv, errno is EILSEQ");
return -1;
case EINVAL:
throw CGUIException(
"[WCharToUtf8]: failed to iconv, errno is EINVAL");
return -1;
default:
throw CGUIException(
"[WCharToUtf8]: failed to iconv, errno is %d",
errno);
return -1;
}
}
//close iconv
int ret = iconv_close(cd);
if( ret == -1 )
{
throw CGUIException(
"[WCharToUtf8]: failed to close iconv, errno is %d",
errno);
return -1;
}
return 0;
}