本文整理汇总了C++中UT_UTF8String::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ UT_UTF8String::substr方法的具体用法?C++ UT_UTF8String::substr怎么用?C++ UT_UTF8String::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UT_UTF8String
的用法示例。
在下文中一共展示了UT_UTF8String::substr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sWork
/*!
* Assuming a string of standard abiword properties eg. "fred:nerk; table-width:1.0in; table-height:10.in"
* Return the value of the property sProp or NULL if it is not present.
* This UT_UTF8String * should be deleted by the calling programming after it is finished with it.
*/
UT_UTF8String UT_UTF8String_getPropVal(const UT_UTF8String & sPropertyString, const UT_UTF8String & sProp)
{
UT_UTF8String sWork(sProp);
sWork += ":";
const char * szWork = sWork.utf8_str();
const char * szProps = sPropertyString.utf8_str();
const char * szLoc = strstr(szProps,szWork);
if(szLoc == NULL)
{
return UT_UTF8String();
}
//
// Look if this is the last property in the string.
//
const char * szDelim = strchr(szLoc,';');
if(szDelim == NULL)
{
//
// Remove trailing spaces
//
UT_sint32 iSLen = strlen(szProps);
while(iSLen > 0 && szProps[iSLen-1] == ' ')
{
iSLen--;
}
//
// Calculate the location of the substring
//
UT_sint32 offset = static_cast<UT_sint32>(reinterpret_cast<size_t>(szLoc) - reinterpret_cast<size_t>(szProps));
offset += strlen(szWork);
return UT_UTF8String(sPropertyString.substr(offset,(iSLen - offset)));
}
else
{
szDelim = strchr(szLoc,';');
if(szDelim == NULL)
{
//
// bad property string
//
UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
return UT_UTF8String();
}
//
// Remove trailing spaces.
//
while(*szDelim == ';' || *szDelim == ' ')
{
szDelim--;
}
//
// Calculate the location of the substring
//
UT_sint32 offset = static_cast<UT_sint32>(reinterpret_cast<size_t>(szLoc) - reinterpret_cast<size_t>(szProps));
offset += strlen(szWork);
UT_sint32 iLen = static_cast<UT_sint32>(reinterpret_cast<size_t>(szDelim) - reinterpret_cast<size_t>(szProps)) + 1;
return UT_UTF8String(sPropertyString.substr(offset,(iLen - offset)));
}
}
示例2: UT_UTF8String_addPropertyString
/*!
* Assuming a string of standard abiword properties eg. "fred:nerk; table-width:1.0in; table-height:10.in"
* Add aother propety string, updating previously defined properties with
* values in the new string.
*/
void UT_UTF8String_addPropertyString(UT_UTF8String & sPropertyString, const UT_UTF8String & sNewProp)
{
UT_sint32 iSize = static_cast<UT_sint32>(sNewProp.size());
UT_sint32 iBase =0;
UT_UTF8String sProp;
UT_UTF8String sVal;
UT_UTF8String sSubStr;
const char * szWork = NULL;
const char * szLoc = NULL;
while(iBase < iSize)
{
bool bBreakAtEnd = false;
sSubStr = sNewProp.substr(iBase, iSize-iBase);
szWork = sSubStr.utf8_str();
szLoc = strstr(szWork,":");
UT_sint32 iextra = 0;
if(szLoc)
{
UT_sint32 k = iBase;
while(*sNewProp.substr(k,k).utf8_str() == ' ')
{
k++;
iextra++;
}
sProp = sNewProp.substr(k,szLoc - szWork-iextra);
}
else
{
break;
}
iBase += szLoc-szWork+1;
sSubStr = sNewProp.substr(iBase, iSize-iBase);
szWork = sSubStr.utf8_str();
szLoc = strstr(szWork,";");
if(szLoc)
{
sVal = sNewProp.substr(iBase,szLoc - szWork);
iBase += szLoc-szWork+1;
}
else
{
sVal = sNewProp.substr(iBase,iSize-iBase);
bBreakAtEnd = true;
}
if((sProp.size()>0) && (sVal.size() >0))
{
UT_UTF8String_setProperty(sPropertyString,sProp,sVal);
}
else
{
break;
}
if(bBreakAtEnd)
{
break;
}
}
}