本文整理汇总了C++中STRING::find_last_not_of方法的典型用法代码示例。如果您正苦于以下问题:C++ STRING::find_last_not_of方法的具体用法?C++ STRING::find_last_not_of怎么用?C++ STRING::find_last_not_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STRING
的用法示例。
在下文中一共展示了STRING::find_last_not_of方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trim
static void trim(STRING& str)
{
static const WCHAR Spaces[] = L" \t\r\n";
size_t i = str.find_first_not_of(Spaces);
size_t j = str.find_last_not_of(Spaces);
if (i == STRING::npos || j == STRING::npos)
{
str.clear();
}
else
{
str = str.substr(i, j - i + 1);
}
}
示例2: EscapeBackSlashes
/*!
* Add escaping to each sequence of backslashes that immediately precedes
* a quote character. Each backslash in such a sequence must be escaped
* with another backslash. Note that backslashes that are not part of a
* sequence that immediately precedes a quote are NOT escaped. E.g.:
*
* \a" -> \a"
* foo\bar"baz\\"fum -> foo\bar"baz\\\\"fum
*/
void EscapeBackSlashes()
{
size_t quote = _quoted.find_first_of('"', 1);
while (quote != STRING::npos)
{
size_t numSlashes = 0;
size_t notSlash = _quoted.find_last_not_of('\\', quote-1);
if (notSlash != quote-1)
{
if (notSlash == STRING::npos)
numSlashes = quote;
else
numSlashes = quote - notSlash - 1;
_quoted.insert(quote, numSlashes, '\\');
}
quote = _quoted.find_first_of('"', quote + numSlashes + 1);
}
}
示例3: 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, '\\');
}
}
}