本文整理汇总了C++中STRING::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ STRING::insert方法的具体用法?C++ STRING::insert怎么用?C++ STRING::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STRING
的用法示例。
在下文中一共展示了STRING::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EscapeQuotes
/*!
* Add escaping to each quote character (") by preceding it with a backslash (\).
*/
void EscapeQuotes()
{
size_t quote = _quoted.find_first_of('"');
while (quote != STRING::npos)
{
_quoted.insert(quote, 1, '\\');
quote = _quoted.find_first_of('"', quote + 2);
}
}
示例2: 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, '\\');
}
}
}
示例3: 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);
}
}