本文整理汇总了C++中STRING::size方法的典型用法代码示例。如果您正苦于以下问题:C++ STRING::size方法的具体用法?C++ STRING::size怎么用?C++ STRING::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STRING
的用法示例。
在下文中一共展示了STRING::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makePartName
bool DIR_LIB_SOURCE::makePartName( STRING* aPartName, const char* aEntry,
const STRING& aCategory )
{
const char* cp = strrstr( aEntry, SWEET_EXT );
// if base name is not empty, contains SWEET_EXT, && cp is not NULL
if( cp > aEntry )
{
const char* limit = cp + strlen( cp );
// If versioning, then must find a trailing "revN.." type of string.
if( useVersioning )
{
const char* rev = endsWithRev( cp + SWEET_EXTZ, limit, '.' );
if( rev )
{
if( aCategory.size() )
*aPartName = aCategory + "/";
else
aPartName->clear();
aPartName->append( aEntry, cp - aEntry );
aPartName->append( "/" );
aPartName->append( rev );
return true;
}
}
// If using versioning, then all valid partnames must have a rev string,
// so we don't even bother to try and load any other partfile down here.
else
{
// if file extension is exactly SWEET_EXT, and no rev
if( cp==limit-5 )
{
if( aCategory.size() )
*aPartName = aCategory + "/";
else
aPartName->clear();
aPartName->append( aEntry, cp - aEntry );
return true;
}
}
}
return false;
}
示例2: StrReplace
/**
* string replace function
* @param string str need op string
* @param string old_str need replace old string
* @param string new_str need replace to new string
*/
STRING CCUtil::StrReplace( STRING str, STRING search_str, STRING replace_str )
{
STRING::size_type pos = 0 ;
while( ( pos = str.find( search_str, pos ) ) != STRING::npos )
{
str.replace( pos, search_str.size(), replace_str ) ;
pos++ ;
}
return str ;
}
示例3: compareText
void compareText(const FMINDEX& f, const STRING& text, const STRING *keyTbl, size_t keySize)
{
for (size_t i = 0; i < keySize; i++) {
const STRING& key = keyTbl[i];
Set a = searchPos1(f, key);
Set b = searchPos2(text, key);
CYBOZU_TEST_EQUAL(a.size(), b.size());
if (a.size() == b.size()) {
size_t pos = 0;
for (Set::const_iterator ia = a.begin(), ib = b.begin(); pos < a.size(); ++ia, ++ib, ++pos) {
CYBOZU_TEST_EQUAL(*ia, *ib);
}
}
}
// recover string
STRING org;
f.getPrevString(org, 0, f.wm.size() - 1);
CYBOZU_TEST_EQUAL(org.size(), text.size());
CYBOZU_TEST_ASSERT(org == text);
}
示例4: GetCategoricalPartNames
void DIR_LIB_SOURCE::GetCategoricalPartNames( STRINGS* aResults, const STRING& aCategory )
throw( IO_ERROR )
{
PN_ITER end = aCategory.size() ?
partnames.lower_bound( aCategory + char( '/' + 1 ) ) :
partnames.end();
PN_ITER it = aCategory.size() ?
partnames.upper_bound( aCategory + "/" ) :
partnames.begin();
aResults->clear();
if( useVersioning )
{
STRING partName;
while( it != end )
{
const char* rev = endsWithRev( *it );
// all cached partnames have a rev string in useVersioning mode
assert( rev );
// partName is substring which omits the rev AND the rev separator
partName.assign( *it, 0, rev - it->c_str() - 1 );
aResults->push_back( partName );
// skip over all other versions of the same partName.
it = partnames.lower_bound( partName + char( '/' + 1 ) );
}
}
else
{
while( it != end )
aResults->push_back( *it++ );
}
}
示例5: operator
// see struct BY_REV
bool BY_REV::operator() ( const STRING& s1, const STRING& s2 ) const
{
// avoid instantiating new STRINGs, and thank goodness that c_str() is const.
const char* rev1 = endsWithRev( s1 );
const char* rev2 = endsWithRev( s2 );
int rootLen1 = rev1 ? rev1 - s1.c_str() : s1.size();
int rootLen2 = rev2 ? rev2 - s2.c_str() : s2.size();
int r = memcmp( s1.c_str(), s2.c_str(), min( rootLen1, rootLen2 ) );
if( r )
{
return r < 0;
}
if( rootLen1 != rootLen2 )
{
return rootLen1 < rootLen2;
}
// root strings match at this point, compare the revision number numerically,
// and chose the higher numbered version as "less", according to std::set lingo.
if( bool(rev1) != bool(rev2) )
{
return bool(rev1) < bool(rev2);
}
if( rev1 && rev2 )
{
int rnum1 = atoi( rev1+3 );
int rnum2 = atoi( rev2+3 );
// higher numbered revs are "less" so that they bubble to top.
return rnum1 > rnum2;
}
return false; // strings are equal, and they don't have a rev
}
示例6: okBase
static inline int okBase( const STRING& aField )
{
int offset = int( aField.find_first_of( ":/" ) );
if( offset != -1 )
return offset;
// cannot be empty
if( !aField.size() )
return 0;
return offset; // ie. -1
}
示例7: while
VOID CStringFilter::ReplaceToSign_Normal(const STRING& strIn, STRING& strOut)
{
static STRING strSign = "?";
static BYTE byANSIBegin = 0X20;
static BYTE byANSIEnd = 0X80;
strOut = strIn;
STRING::size_type allsize = m_vIncluce.size();
//包含替换
for(STRING::size_type i = 0; i < m_vIncluce.size(); ++i)
{
STRING::size_type pos = strIn.find(m_vIncluce[i]);
while(STRING::npos != pos)
{
STRING strReplace = "";
STRING::size_type len = m_vIncluce[i].size();
//如果包含替换的是1个字节的ANSI字节,替换前,
//需要确认前一个字节一定不是双字节字符集的前一个字节
BOOL bSkip = FALSE;
if(1 == len && pos > 0)
{
BYTE byChar = strIn[pos-1];
#if 0
char dbgmsg[256];
_snprintf(dbgmsg, 255, "strIn[pos-1]:0x%X(0x%X)\n", strIn[pos-1],byChar);
::OutputDebugString(dbgmsg);
#endif
//不是标准ANSI英文字符
if(!(byChar >= byANSIBegin && byChar <= byANSIEnd || byChar == '\r' || byChar == '\n' || byChar == '\t'))
{
bSkip = TRUE;
}
}
if(!bSkip)
{
for(STRING::size_type k = 0; k < len; ++k, strReplace += strSign);
strOut.replace(pos, len, strReplace);
}
pos = strIn.find(m_vIncluce[i], pos+len);
}
}
//完全匹配替换
if(IsFullCmp(strIn))
{
STRING::size_type len = strIn.size();
strOut.clear();
for(STRING::size_type i = 0; i < len; ++i, strOut += strSign);
}
}
示例8: okRevision
static int okRevision( const STRING& aField )
{
char rev[32]; // C string for speed
if( aField.size() >= 4 )
{
strcpy( rev, "x/" );
strcat( rev, aField.c_str() );
if( EndsWithRev( rev, rev + strlen(rev) ) == rev+2 )
return -1; // success
}
return 0; // first character position "is in error", is best we can do.
}
示例9: Unquote
STRING Unquote(const STRING& str)
{
if (str[0] != L'"')
return str;
STRING Ret;
size_t i = 1;
while (i < str.size())
{
if (str[i] == L'"' || str[i] == UNICODE_NULL)
break;
UnescapeChar(str, i, Ret);
}
return Ret;
}
示例10: Escape
STRING Escape(const STRING& str)
{
STRING Ret;
for (size_t i = 0; i < str.size(); ++i)
{
switch (str[i])
{
case L'"': case L'\\':
Ret += L'\\';
Ret += str[i];
break;
default:
Ret += str[i];
}
}
return Ret;
}
示例11: AddQuotes
/*!
* Add quotes around the string if it contains any whitespace.
*/
void AddQuotes(const T *whitespace)
{
if (_quoted.find_first_of(whitespace) != STRING::npos)
{
_quoted.insert(0, 1, '"');
_quoted.append(1, '"');
// If the last character (prior to adding the quotes) was a backslash,
// it needs to be escaped now because it precedes a quote.
//
size_t quote = _quoted.size() - 1;
if (_quoted[quote-1] == '\\')
{
size_t notSlash = _quoted.find_last_not_of('\\', quote-2);
size_t numSlashes = quote - notSlash - 1;
_quoted.insert(quote, numSlashes, '\\');
}
}
}
示例12: fgets
static void fgets(STRING & s, FILE * f)
{
s.resize(0);
char c;
while (fgetc(c, f))
{
if (c == '\n' || c == '\r')
{
if (c == '\r' && (!fgetc(c, f) || c != '\n'))
RuntimeError("fgets: malformed text file, CR without LF");
break;
}
s.push_back(c);
// strip Unicode BOM
// We strip it from any string, not just at the start.
// This allows to UNIX-'cat' multiple UTF-8 files with BOMs.
// Since the BOM is otherwise invalid within a file, this is well-defined and upwards compatible.
if (s.size() == 3 && BeginsWithUnicodeBOM(s.c_str()))
s.clear();
}
}
示例13: MG_HTTP_HANDLER_TRY
/// <summary>
/// Executes the specific request.
/// </summary>
/// <returns>
/// MgHttpResponse
/// This contains the response (including MgHttpResult and StatusCode) from the server.
/// </returns>
void MgHttpWfsDescribeFeatureType::Execute(MgHttpResponse& hResponse)
{
Ptr<MgHttpResult> hResult = hResponse.GetResult();
MG_HTTP_HANDLER_TRY()
// We have to wrap the request parameters, since the outside
// world is case-sensitive (with respect to names,) but
// we need our parameters NOT to be so.
Ptr<MgHttpRequestParam> origReqParams = m_hRequest->GetRequestParam();
MgHttpRequestParameters Parms(origReqParams);
MgHttpResponseStream Out;
MgOgcServer::SetLoader(GetDocument);
MgUserInformation::SetCurrentUserInfo(m_userInfo);
// Instance a server-lette
MgOgcWfsServer Wfs(Parms,Out);
// Determine required feature types
CPSZ pszFeatureTypes = Wfs.RequestParameter(MgHttpResourceStrings::reqWfsTypeName.c_str());
STRING sFeatureTypes = pszFeatureTypes? pszFeatureTypes : _("");
Ptr<MgStringCollection> featureTypeList;
if(sFeatureTypes.empty())
{
featureTypeList = NULL;
}
else
{
featureTypeList = MgStringCollection::ParseCollection(sFeatureTypes, L",");
}
Ptr<MgResourceService> pResourceService = (MgResourceService*)(CreateService(MgServiceType::ResourceService));
Ptr<MgFeatureService> pFeatureService = (MgFeatureService*)(CreateService(MgServiceType::FeatureService));
// Retrieve feature definitions
auto_ptr<MgWfsFeatureDefinitions> pFeatureTypes;
if(NULL == featureTypeList)
{
pFeatureTypes.reset(new MgWfsFeatureDefinitions(pResourceService,pFeatureService));
}
else
{
pFeatureTypes.reset(new MgWfsFeatureDefinitions(pResourceService,pFeatureService,featureTypeList));
}
Wfs.SetFeatureDefinitions(pFeatureTypes.get());
// In order to validate request we have to invoke the ProcessRequest
if(!Wfs.ProcessRequest(this))
{
// Obtain the response byte reader
Ptr<MgByteReader> errorResponse = Out.Stream().GetReader();
// Set the result
hResult->SetResultObject(errorResponse, errorResponse->GetMimeType());
return;
}
// Determine required output format
// This part must behind the Wfs.ProcessRequest, where parameters have been validated.
CPSZ pszOutputFormat = Wfs.RequestParameter(MgHttpResourceStrings::reqWfsOutputFormat.c_str());
STRING sOutputFormat = pszOutputFormat? pszOutputFormat : _("");
if(sOutputFormat.empty())
{
sOutputFormat = Wfs.GetDefaultDescribeFeatureTypeOutputFormat(STRING(Wfs.RequestParameter(MgHttpResourceStrings::reqWfsVersion.c_str())));
}
if(pFeatureTypes->InSameNamespace())
{
STRING sPrefix = L"";
STRING sUrl = L"";
STRING sResource = L""; // TODO: look for this in arg, since POST may put it there to save us trouble.
STRING sSchemaHash = L"";
Ptr<MgResourceIdentifier> idResource;
Ptr<MgStringCollection> pFeatureClasses = new MgStringCollection();
while(pFeatureTypes->ReadNext())
{
STRING sClassFullName = pFeatureTypes->GetClassFullName();
if(!sFeatureTypes.empty() && STRING::npos == sFeatureTypes.find(sClassFullName))
{
continue;
}
STRING::size_type iPos = sClassFullName.find(_(":")); //NOXLATE
if(iPos != STRING::npos)
{
if(sPrefix.empty())
{
sPrefix = sClassFullName.substr(0,iPos);
}
//.........这里部分代码省略.........
示例14: _snprintf
VOID CStringFilter::ReplaceToSign(const STRING& strIn, STRING& strOut)
{
const CHAR KeyStart = '#';
const CHAR ContentsEnd = '}';
std::vector<PICE> vSrcPice; //来源字串分割成多段
STRING strSrc = strIn;
PICE pc;
STRING::size_type sB = 0;
STRING::size_type sC = 0;
STRING::size_type sE = strSrc.find_first_of(KeyStart);
STRING::size_type sLen = strSrc.size();
#if 0
::OutputDebugString("ReplaceToSign Begin=======================\n");
char dbgmsg[256];
_snprintf(dbgmsg, 255, "strSrc:%s", strSrc.c_str());
::OutputDebugString(dbgmsg);
::OutputDebugString("\n------------------------------------------");
#endif
do
{
if(sE == STRING::npos)
{
//push last replace str
pc.bReplace = TRUE;
pc.pice = strSrc.substr(sC);
vSrcPice.push_back(pc);
break;
}
//get op
STRING strOp = strSrc.substr(sE+1, 1);
if(strOp == "{") //ok, check magic #{} string.
{
//item element is valid. ex: #{_INFOID123}
STRING strItemElement = strSrc.substr(sE+2, 7);
//info message is valid. ex: #{_INFOMSGxxxxxx}
STRING strInfoMsg = strSrc.substr(sE+2, 8);
if(strItemElement == "_INFOID")
{
//get itemId
//todo_yangjun 需要仔细检查剩下的字符是否还是一个完整的INFOID信息
STRING::size_type sIDEnd = strSrc.find(ContentsEnd, sE+2+7);
if(sE+2+7 >= sLen) // fix dead loop if str is "xxx#{_INFOID" [9/25/2006]
{
//skip invalid #{
sE += 2;
goto LengthOver2;
}
STRING strId = strSrc.substr(sE+2+7, sIDEnd-sE-2-7);
INT itemId = atoi(strId.c_str());
if(g_pTransferItemSystem->IsElementExist(itemId))
{//ok, valid item element found.
//0. push normal replace str
pc.bReplace = TRUE;
pc.pice = strSrc.substr(sC, sE-sC);
vSrcPice.push_back(pc);
//1. push no replace str
pc.bReplace = FALSE;
pc.pice = strSrc.substr(sE, sIDEnd-sE+1);
vSrcPice.push_back(pc);
}
//step to new point.
sE = sIDEnd + 1;
sC = sE;
}
else if(strInfoMsg == "_INFOMSG")
{
//get info message
INT nContentsLen = atoi(strSrc.substr(sE+2+8,3).c_str());
STRING::size_type sIDEnd = sE+2+8+3+nContentsLen;
if(sE+2+8 >= sLen)
{
//skip invalid #{
sE += 2;
goto LengthOver2;
}
//ok, valid info message found.
//0. push normal replace str
pc.bReplace = TRUE;
pc.pice = strSrc.substr(sC, sE-sC);
vSrcPice.push_back(pc);
//1. push no replace str
pc.bReplace = FALSE;
pc.pice = strSrc.substr(sE, sIDEnd-sE+1);
vSrcPice.push_back(pc);
//step to new point.
sE = sIDEnd + 1;
sC = sE;
//.........这里部分代码省略.........
示例15: Format
STRING LPID::Format( const STRING& aLogicalLib, const STRING& aPartName, const STRING& aRevision )
throw( PARSE_ERROR )
{
STRING ret;
int offset;
if( aLogicalLib.size() )
{
offset = okLogical( aLogicalLib );
if( offset != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in logical lib name" ),
wxString::FromUTF8( aLogicalLib.c_str() ),
aLogicalLib.c_str(),
0,
offset
);
}
ret += aLogicalLib;
ret += ':';
}
{
STRING category;
STRING base;
int separation = int( aPartName.find_first_of( "/" ) );
if( separation != -1 )
{
category = aPartName.substr( 0, separation );
base = aPartName.substr( separation+1 );
}
else
{
// leave category empty
base = aPartName;
}
if( (offset = okCategory( category )) != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in category" ),
wxString::FromUTF8( aRevision.c_str() ),
aRevision.c_str(),
0,
offset
);
}
if( (offset = okBase( base )) != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in base name" ),
wxString::FromUTF8( aRevision.c_str() ),
aRevision.c_str(),
0,
offset + separation + 1
);
}
if( category.size() )
{
ret += category;
ret += '/';
}
ret += base;
}
if( aRevision.size() )
{
offset = okRevision( aRevision );
if( offset != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in revision" ),
wxString::FromUTF8( aRevision.c_str() ),
aRevision.c_str(),
0,
offset
);
}
ret += '/';
ret += aRevision;
}
return ret;
}