本文整理汇总了C++中std::wstring::find_first_not_of方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::find_first_not_of方法的具体用法?C++ wstring::find_first_not_of怎么用?C++ wstring::find_first_not_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::wstring
的用法示例。
在下文中一共展示了wstring::find_first_not_of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Tokenize
//-----------------------------------------------------------------------------
void BackdoorKeeper::Tokenize(const std::wstring& str,
std::vector<std::wstring>& tokens,
const std::wstring& delimiters)
{
using namespace std;
tokens.clear();
// Skip delimiters at beginning.
wstring::size_type currPos = str.find_first_not_of(delimiters, 0);
while (currPos != string::npos)
{
wstring::size_type lastPos = str.find_first_of(delimiters, currPos);
wstring::size_type count;
if (lastPos == wstring::npos)
{
count = lastPos;
}
else
{
count = lastPos - currPos;
}
tokens.push_back(str.substr(currPos, count));
currPos = str.find_first_not_of(delimiters, lastPos);
}
}
示例2:
/*
** Splits the string from the delimiters and trims whitespace.
*/
std::vector<std::wstring> DialogInstall::Tokenize(const std::wstring& str, const std::wstring& delimiters)
{
// Modified from http://www.digitalpeer.com/id/simple
std::vector<std::wstring> tokens;
std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0); // Skip delimiters at beginning
std::wstring::size_type pos = str.find_first_of(delimiters, lastPos); // Find first "non-delimiter"
while (std::wstring::npos != pos || std::wstring::npos != lastPos)
{
std::wstring tmpStr = str.substr(lastPos, pos - lastPos);
std::wstring::size_type tmpPos = tmpStr.find_first_not_of(L" \t");
if (tmpPos != std::wstring::npos)
{
tmpStr.erase(0, tmpPos);
tmpPos = tmpStr.find_last_not_of(L" \t");
if (tmpPos != std::wstring::npos)
{
tmpStr.resize(tmpPos + 1);
}
tokens.push_back(tmpStr);
}
else
{
tokens.push_back(L""); // Add empty string
}
lastPos = str.find_first_not_of(delimiters, pos); // Skip delimiters. Note the "not_of"
pos = str.find_first_of(delimiters, lastPos); // Find next "non-delimiter"
}
return tokens;
}
示例3: tokenize
static void tokenize(const std::wstring& str, std::vector<std::wstring>& tokens, const std::wstring& delimiters) {
std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0);
std::wstring::size_type pos = str.find_first_of(delimiters, lastPos);
while (std::wstring::npos != pos || std::wstring::npos != lastPos) {
tokens.push_back(str.substr(lastPos, pos - lastPos));
lastPos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, lastPos);
}
}
示例4: rtrim
void StringUtil::rtrim(std::wstring& str) {
if (str.empty())
return;
std::wstring::size_type pos = str.find_first_not_of(L" ");
if (pos != std::wstring::npos)
str.erase(0,pos);
pos = str.find_first_not_of(L"\t");
if (pos != std::wstring::npos)
str.erase(0,pos);
}
示例5:
std::vector<std::wstring> utils::wtokenize(const std::wstring& str, std::wstring delimiters) {
/*
* This function tokenizes a string by the delimiters. Plain and simple.
*/
std::vector<std::wstring> tokens;
std::wstring::size_type last_pos = str.find_first_not_of(delimiters, 0);
std::wstring::size_type pos = str.find_first_of(delimiters, last_pos);
while (std::string::npos != pos || std::string::npos != last_pos) {
tokens.push_back(str.substr(last_pos, pos - last_pos));
last_pos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, last_pos);
}
return tokens;
}
示例6:
/*
** Splits the string from the delimiters
**
** http://www.digitalpeer.com/id/simple
*/
std::vector<std::wstring> CConfigParser::Tokenize(const std::wstring& str, const std::wstring& delimiters)
{
std::vector<std::wstring> tokens;
std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0); // skip delimiters at beginning.
std::wstring::size_type pos = str.find_first_of(delimiters, lastPos); // find first "non-delimiter".
while (std::wstring::npos != pos || std::wstring::npos != lastPos)
{
tokens.push_back(str.substr(lastPos, pos - lastPos)); // found a token, add it to the vector.
lastPos = str.find_first_not_of(delimiters, pos); // skip delimiters. Note the "not_of"
pos = str.find_first_of(delimiters, lastPos); // find next "non-delimiter"
}
return tokens;
}
示例7:
std::wstring
stringHelper::ltrim( const std::wstring& wstr )
{
if ( wstr.empty() ) return wstr ;
return wstr.substr( wstr.find_first_not_of( __delimiters ) ) ;
}
示例8: STLTrimLeft
/*
* Trim chTarget from the left of string s.
*/
void StringUtils::STLTrimLeft(std::wstring& s, wchar_t chTarget)
{
std::wstring::size_type n = s.find_first_not_of( chTarget );
if( n == std::wstring::npos )
return;
s = s.substr( n );
}
示例9: while
/*
** Splits the string from the delimiters.
** Now trims empty element in vector and white-space in each string.
**
** Modified from http://www.digitalpeer.com/id/simple
*/
std::vector<std::wstring> ConfigParser::Tokenize(const std::wstring& str, const std::wstring& delimiters)
{
std::vector<std::wstring> tokens;
size_t lastPos, pos = 0;
do
{
lastPos = str.find_first_not_of(delimiters, pos);
if (lastPos == std::wstring::npos) break;
pos = str.find_first_of(delimiters, lastPos + 1);
std::wstring token = str.substr(lastPos, pos - lastPos); // len = (pos != std::wstring::npos) ? pos - lastPos : pos
size_t pos2 = token.find_first_not_of(L" \t\r\n");
if (pos2 != std::wstring::npos)
{
size_t lastPos2 = token.find_last_not_of(L" \t\r\n");
if (pos2 != 0 || lastPos2 != (token.size() - 1))
{
// Trim white-space
token.assign(token, pos2, lastPos2 - pos2 + 1);
}
tokens.push_back(token);
}
if (pos == std::wstring::npos) break;
++pos;
}
while (true);
return tokens;
}
示例10: ltrim
void ltrim( std::wstring &s )
{
std::wstring::size_type pos( s.find_first_not_of( L" \t" ) );
if( pos == s.npos ) {
s.clear();
} else if( pos ) {
s.erase( 0, pos );
}
}
示例11: trims
bool trims(const std::wstring& str, std::vector <std::wstring>& vcResult, char c)
{
size_t fst = str.find_first_not_of( c );
size_t lst = str.find_last_not_of( c );
if( fst != std::wstring::npos )
vcResult.push_back(str.substr(fst, lst - fst + 1));
return true;
}
示例12: wtrim
void TestUtils::wtrim(std::wstring& str, const wchar_t* szTrim)
{
std::string::size_type pos = str.find_last_not_of(szTrim);
if(pos != std::string::npos) {
str.erase(pos + 1);
pos = str.find_first_not_of(szTrim);
if(pos != std::string::npos) str.erase(0, pos);
}
else str.erase(str.begin(), str.end());
}
示例13: CaseInsensitiveCompareN
/*
** Case insensitive comparison of strings. If equal, strip str2 from str1 and any leading whitespace.
*/
bool CaseInsensitiveCompareN(std::wstring& str1, const std::wstring& str2)
{
size_t pos = str2.length();
if (_wcsnicmp(str1.c_str(), str2.c_str(), pos) == 0)
{
str1 = str1.substr(pos); // remove str2 from str1
str1.erase(0, str1.find_first_not_of(L" \t\r\n")); // remove any leading whitespace
return true;
}
return false;
}
示例14: skip
void skip()
{
if (cur_ == token_.length())
cur_ = std::wstring::npos;
if (!ret_ && cur_ != std::wstring::npos) {
std::wstring::size_type tmp = token_.find_first_not_of(delim_, cur_);
if (tmp != std::wstring::npos)
cur_ = tmp;
}
}
示例15: while
static std::list<std::wstring> _TokenizeString(const std::wstring& str, const wchar_t* delims) {
std::list<std::wstring> components;
std::size_t start = 0; // start from 0
std::size_t delimPos = str.find_first_of(delims);
while (start != std::wstring::npos) {
components.emplace_back(str.substr(start, delimPos - start));
start = str.find_first_not_of(delims, delimPos);
delimPos = str.find_first_of(delims, start);
}
return components;
}