本文整理汇总了C++中string_t::length方法的典型用法代码示例。如果您正苦于以下问题:C++ string_t::length方法的具体用法?C++ string_t::length怎么用?C++ string_t::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_t
的用法示例。
在下文中一共展示了string_t::length方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WBUFB
CServerMessagePacket::CServerMessagePacket(const string_t message, int8 language, int32 timestamp, int32 message_offset)
{
this->type = 0x4D;
this->size = 0x0E;
WBUFB(data, (0x04) ) = message_offset == 0 ? 1 : 2;
WBUFB(data, (0x05) ) = 1;
WBUFB(data, (0x06) ) = 1;
WBUFB(data, (0x07) ) = language;
WBUFL(data, (0x08) ) = timestamp == 0 ? time(0) : timestamp;
WBUFL(data, (0x0C) ) = 0; // Message Length.. (Total)
WBUFL(data, (0x10) ) = 0; // Message Offset..
WBUFL(data, (0x14) ) = 0; // Message Length..
// Ensure we have a message and the requested offset is not outside of the bounds..
if (message.length() > 0 && message.length() > message_offset)
{
int32 msgLength = message.length();
int32 sndLength = (msgLength - message_offset) > 236 ? 236 : (msgLength - message_offset);
WBUFL(data, (0x0C) ) = message.length(); // Message Length.. (Total)
WBUFL(data, (0x10) ) = message_offset; // Message Offset..
WBUFL(data, (0x14) ) = sndLength; // Message Length..
memcpy((data + (0x18)) , message.c_str() + message_offset, sndLength);
int32 textSize = sndLength + sndLength % 2;
this->size = ((((0x14 + textSize) + 4) >> 1) & 0xFE);
}
示例2: RemoveExtensionFromFilename
bool Anitomy::RemoveExtensionFromFilename(string_t& filename,
string_t& extension) {
const size_t position = filename.find_last_of(L'.');
if (position == string_t::npos)
return false;
extension = filename.substr(position + 1);
const size_t max_length = 4;
if (extension.length() > max_length)
return false;
if (!IsAlphanumericString(extension))
return false;
// TODO: Add an option for this
auto keyword = StringToUpperCopy(extension);
if (!keyword_manager.Find(kElementFileExtension, keyword))
return false;
filename.resize(position);
return true;
}
示例3: match
bool RegexSearch::match(State * beginState,const string_t &str, int pos)
{
beginPos=pos;
//empty string
if((flag&MatchFlag::MATCH_NOT_NULL)!=0&&str.length()==0)
{
return false;
}
//match way choose
if((flag&MatchFlag::MATCH_BFS)==0)
{
return matchDfs(beginState,str,pos-1,pos);
}
else
{
return matchBfs(beginState,str,pos);
}
}
示例4: ToGrid
string_t Square::ToGrid(const string_t & str)
{
#ifdef PUZ_CHECK_STRINGS
if (str.length() > REBUS_ENTRY_LENGTH)
throw LongString();
#endif
string_t ret;
string_t::const_iterator it;
for (it = str.begin(); it != str.end(); ++it)
{
char_t ch = ToGrid(*it);
if (ch != 0)
ret.append(1, ch);
#ifdef PUZ_CHECK_STRINGS
else
throw InvalidString();
#endif
}
return ret;
}
示例5: Serialize
void SaveFile::Serialize(string_t &str)
{
string_t::size_type len = str.length();
Serialize(len);
if( len )
{
if( loading() )
{
std::vector<string_t::value_type> buffer(len);
SerializeArray(&*buffer.begin(), len);
str.resize(0);
str.reserve(len);
str.insert(str.begin(), buffer.begin(), buffer.end());
}
else
{
SerializeArray(const_cast<string_t::value_type*>(str.data()), len);
}
}
}
示例6: replace
string_t RegexSearch::replace(const RegexResult &result, const string_t &str, int pos, const string_t &replaceStr)
{
string_t ans;
unsigned int curSubMatch=0;
for(unsigned int i=pos;i<str.length();)
{
if(curSubMatch!=result.subMatch.size()&&
result.subMatch[curSubMatch].begin==(int)i)
{
ans.insert(ans.length(),replaceStr);
i+=result.subMatch[curSubMatch].end-result.subMatch[curSubMatch].begin+1;
++curSubMatch;
}
else
{
ans.push_back(str[i]);
++i;
}
}
return ans;
}
示例7: RemoveExtensionFromFilename
bool Anitomy::RemoveExtensionFromFilename(string_t& filename,
string_t& extension) const {
const size_t position = filename.find_last_of(L'.');
if (position == string_t::npos)
return false;
extension = filename.substr(position + 1);
const size_t max_length = 4;
if (extension.length() > max_length)
return false;
if (!IsAlphanumericString(extension))
return false;
string_t keyword = keyword_manager.Normalize(extension);
if (!keyword_manager.Find(kElementFileExtension, keyword))
return false;
filename.resize(position);
return true;
}
示例8: is_path_rooted
bool pal::is_path_rooted(const string_t& path)
{
return path.length() >= 2 && path[1] == L':';
}
示例9: matchDfs
bool RegexSearch::matchDfs(State * beginState,const string_t &str, int acpos, int pos)
{
bool result(false);
if((unsigned int)pos==str.length())
{
if(beginState->isEndState==true)
{
return true;
}
}
if((unsigned int)pos>str.length())
{
return false;
}
for(unsigned int i=0;i<beginState->out.size();++i)
{
Transition &curTransition=*(beginState->out[i]);
switch(curTransition.type)
{
case TransitionType::CHARS:
if(curTransition.range.isSubSet(str[pos]))
{
if(matchDfs(curTransition.target,str,acpos+1,pos+1))
{
result = true;
}
}
break;
case TransitionType::EMPTY:
if(matchDfs(curTransition.target,str,acpos,pos))
{
result = true;
}
break;
case TransitionType::BEGINLINE:
if(pos>=1)
{
if(str[pos-1]==T('\n')||str[pos-1]==T('\r'))
{
if(matchDfs(curTransition.target,str,acpos,pos))
{
result = true;
}
}
}
//attention no break
case TransitionType::BEGINSTRING:
if((flag&MATCH_NOT_BOL)==0)
{
if(pos==0)
{
if(matchDfs(curTransition.target,str,acpos,pos))
{
result = true;
}
}
}
break;
case TransitionType::ENDLINE:
if(str[pos]==T('\n')||str[pos]==T('\r'))
{
if(matchDfs(curTransition.target,str,acpos,pos))
{
result = true;
}
}
//attention no break
case TransitionType::ENDSTRING:
if((flag&MATCH_NOT_EOL)==0)
{
if((unsigned int)pos==str.length())
{
if(matchDfs(curTransition.target,str,acpos,pos))
{
result = true;
}
}
}
break;
case TransitionType::BEGINCAPTURE:
smatch.captureResult.push_back(RegexPosition(acpos+1,acpos+1));
if(matchDfs(curTransition.target,str,acpos,pos))
{
result = true;
}
else
{
smatch.captureResult.pop_back();
}
break;
case TransitionType::ENDCAPTURE:
{
std::vector<RegexPosition>::iterator topCapture;
int back_saver=0;
if(!smatch.captureResult.empty())
{
topCapture=smatch.captureResult.end()-1;
back_saver=topCapture->end;
//no greedy
if(topCapture->end<acpos)
//.........这里部分代码省略.........
示例10: searchDfs
bool RegexSearch::searchDfs(State * beginState,const string_t &str, int acpos, int pos, bool isLazy)
{
bool result(false);
if(pos-beginPos>10000)//replace by macro later
{
throw RegexError(ErrorCode::error_stack);
}
if((unsigned int)pos>str.length())
{
return false;
}
if(beginState->isEndState==true&&acpos>=0)
{
if(isLazy==true)
{
smatch.end=acpos;
return true;
}
else
{
if(smatch.end<acpos)
smatch.end=acpos;
result=true;
}
}
for(unsigned int i=0;i<beginState->out.size();++i)
{
Transition &curTransition=*(beginState->out[i]);
switch(curTransition.type)
{
case TransitionType::CHARS:
if(curTransition.range.isSubSet(str[pos]))
{
if(searchDfs(curTransition.target,str,acpos+1,pos+1,isLazy))
{
result = true;
}
}
break;
case TransitionType::EMPTY:
if(searchDfs(curTransition.target,str,acpos,pos,isLazy))
{
result = true;
}
break;
case TransitionType::BEGINLINE:
if(pos>=1)
{
if(str[pos-1]==T('\n')||str[pos-1]==T('\r'))
{
if(searchDfs(curTransition.target,str,acpos,pos,isLazy))
{
result = true;
}
}
}
//attention no break
case TransitionType::BEGINSTRING:
if((flag&MATCH_NOT_BOL)==0)
{
if(pos==0)
{
if(searchDfs(curTransition.target,str,acpos,pos,isLazy))
{
result = true;
}
}
}
break;
case TransitionType::ENDLINE:
if(str[pos]==T('\n')||str[pos]==T('\r'))
{
if(searchDfs(curTransition.target,str,acpos,pos,isLazy))
{
result = true;
}
}
//attention no break
case TransitionType::ENDSTRING:
if((flag&MATCH_NOT_EOL)==0)
{
if((unsigned int)pos==str.length())
{
if(searchDfs(curTransition.target,str,acpos,pos,isLazy))
{
result = true;
}
}
}
break;
case TransitionType::LAZY:
if(searchDfs(curTransition.target,str,acpos,pos,true))
{
result = true;
}
break;
case TransitionType::BEGINCAPTURE:
smatch.captureResult.push_back(RegexPosition(acpos+1,acpos+1));
if(searchDfs(curTransition.target,str,acpos,pos,isLazy))
{
//.........这里部分代码省略.........
示例11: word_prefix
string_t word_prefix(const string_t &word)
{
return word.length() > DEPTH ? word.substr(0, DEPTH) : word;
}
示例12: has_end
bool has_end(const string_t &a, const string_t &b)
{
if (a.length() < b.length())
return false;
return a.compare(a.length() - b.length(), b.length(), b) == 0;
}