本文整理汇总了C++中StdBuf::Shrink方法的典型用法代码示例。如果您正苦于以下问题:C++ StdBuf::Shrink方法的具体用法?C++ StdBuf::Shrink怎么用?C++ StdBuf::Shrink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StdBuf
的用法示例。
在下文中一共展示了StdBuf::Shrink方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadString
StdBuf StdCompilerINIRead::ReadString(size_t iLength, RawCompileType eRawType, bool fAppendNull)
{
// Excpect valid position
if (!pPos)
{ notFound("String"); return StdBuf(); }
// Skip whitespace
SkipWhitespace();
// Escaped? Go over '"'
if (eRawType == RCT_Escaped && *pPos++ != '"')
{ notFound("Escaped string"); return StdBuf(); }
// Create buffer
StdBuf OutBuf; OutBuf.New(iLength + (fAppendNull ? sizeof('\0') : 0));
// Read
char *pOut = getMBufPtr<char>(OutBuf);
while (iLength && !TestStringEnd(eRawType))
{
// Read a character
if (eRawType == RCT_Escaped)
*pOut++ = ReadEscapedChar();
else
*pOut++ = *pPos++;
// Count it
iLength--;
}
// Escaped: Go over '"'
if (eRawType == RCT_Escaped)
{
while (*pPos != '"')
{
if (!*pPos || *pPos == '\n' || *pPos == '\r')
{
Warn("string not terminated!");
pPos--;
break;
}
pPos++;
}
pPos++;
}
// Nothing read? Identifiers need to be non-empty
if (pOut == OutBuf.getData() && (eRawType == RCT_Idtf || eRawType == RCT_ID))
{ notFound("String"); return StdBuf(); }
// Append null
if (fAppendNull)
*pOut = '\0';
// Shrink, if less characters were read
OutBuf.Shrink(iLength);
// Done
return OutBuf;
}