本文整理汇总了C++中In::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ In::empty方法的具体用法?C++ In::empty怎么用?C++ In::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类In
的用法示例。
在下文中一共展示了In::empty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: iconvert
Out iconvert(const In& in)
{
if (in.empty())
return Out();
const size_t bufferLen = 128;
typedef typename In::value_type InElem;
typedef typename Out::value_type OutElem;
static iconv_t cd = iconv_open(to, from);
Out result;
OutElem buffer[bufferLen];
char* inbuf = const_cast<char*>(reinterpret_cast<const char*>(&in[0]));
size_t inbytesleft = in.size() * sizeof(InElem);
char* outbuf = reinterpret_cast<char*>(buffer);
size_t outbytesleft = sizeof buffer;
for (;;)
{
size_t ret = ::iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
if (ret == static_cast<size_t>(-1) && errno == EILSEQ)
{
// Skip illegal sequence part, repeat loop.
// TODO: Or retry w/ different encoding?
++inbuf;
--inbytesleft;
}
else if (ret == static_cast<size_t>(-1) && errno == E2BIG)
{
// Append new characters, reset out buffer, then repeat loop.
result.insert(result.end(), buffer, buffer + bufferLen);
outbuf = reinterpret_cast<char*>(buffer);
outbytesleft = sizeof buffer;
}
else
{
// Append what's new in the buffer, then LEAVE loop.
result.insert(result.end(), buffer, buffer + bufferLen - outbytesleft / sizeof(OutElem));
return result;
}
}
}