本文整理汇总了C++中stlw::string::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ string::substr方法的具体用法?C++ string::substr怎么用?C++ string::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stlw::string
的用法示例。
在下文中一共展示了string::substr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Handler
//
// Handler
//
INT_32 FnMBSubstring::Handler(CDT * aArguments,
const UINT_32 iArgNum,
CDT & oCDTRetVal,
Logger & oLogger)
{
// Check number of parameters
if (iArgNum == 0) { oCDTRetVal = ""; return 0; }
// substr('foobar', 2) -> 'obar'
if (iArgNum == 2)
{
const UINT_32 iOffset = UINT_32(aArguments[0].GetInt());
const STLW::string sResult = aArguments[1].GetString();
CCHAR_P szStart = sResult.data();
CCHAR_P szEnd = sResult.data() + sResult.size();
INT_32 iPos = 0;
UINT_32 iCharPos = 0;
for(;;)
{
INT_32 iCharLen = utf_charlen(szStart + iPos, szEnd);
if (iCharLen == -3) { break; }
// Check character length
if (iCharLen < 0) { iCharLen = 1; }
// Skip errors
else { ++iCharPos; }
iPos += iCharLen;
if (iCharPos >= iOffset) { break; }
}
if (iCharPos < iOffset) { oCDTRetVal = ""; }
else { oCDTRetVal = sResult.substr(iPos); }
return 0;
}
// substr('foobar', 2, 3) -> 'oba'
if (iArgNum == 3)
{
const UINT_32 iBytes = UINT_32(aArguments[0].GetInt());
const UINT_32 iOffset = UINT_32(aArguments[1].GetInt());
const STLW::string sResult = aArguments[2].GetString();
CCHAR_P szStart = sResult.data();
CCHAR_P szEnd = sResult.data() + sResult.size();
INT_32 iPos = 0;
UINT_32 iCharOffset = 0;
UINT_32 iCharPos = 0;
for(;;)
{
INT_32 iCharLen = utf_charlen(szStart + iPos, szEnd);
if (iCharLen == -3) { break; }
// Check character length
if (iCharLen < 0) { iCharLen = 1; }
// Skip errors
else { ++iCharPos; }
iPos += iCharLen;
if (iCharPos == iOffset) { iCharOffset = iPos; }
if (iCharPos == iOffset + iBytes) { break; }
}
if (sResult.size() < iCharOffset) { oCDTRetVal = ""; }
else { oCDTRetVal = sResult.substr(iCharOffset, iPos - iCharOffset); }
return 0;
}
// substr('foobar', 2, 3, '1234567') -> 'fo1234567r'
if (iArgNum == 4)
{
STLW::string sReplacement = aArguments[0].GetString();
const UINT_32 iBytes = UINT_32(aArguments[1].GetInt());
const UINT_32 iOffset = UINT_32(aArguments[2].GetInt());
const STLW::string sTMP = aArguments[3].GetString();
CCHAR_P szStart = sTMP.data();
CCHAR_P szEnd = sTMP.data() + sTMP.size();
UINT_32 iPos = 0;
UINT_32 iCharOffset = 0;
UINT_32 iCharPos = 0;
for(;;)
{
INT_32 iCharLen = utf_charlen(szStart + iPos, szEnd);
if (iCharLen == -3) { break; }
// Check character length
if (iCharLen < 0) { iCharLen = 1; }
// Skip errors
else { ++iCharPos; }
iPos += iCharLen;
//.........这里部分代码省略.........