本文整理汇总了C++中wstring::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::replace方法的具体用法?C++ wstring::replace怎么用?C++ wstring::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wstring
的用法示例。
在下文中一共展示了wstring::replace方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Replace
void Replace(wstring& input, wstring find, wstring replace_with,
bool replace_all, bool case_insensitive) {
if (find.empty() || find == replace_with || input.length() < find.length())
return;
if (!case_insensitive) {
for (size_t pos = input.find(find); pos != wstring::npos;
pos = input.find(find, pos)) {
input.replace(pos, find.length(), replace_with);
if (!replace_all)
pos += replace_with.length();
}
} else {
for (size_t i = 0; i < input.length() - find.length() + 1; i++) {
for (size_t j = 0; j < find.length(); j++) {
if (input.length() < find.length())
return;
if (tolower(input[i + j]) == tolower(find[j])) {
if (j == find.length() - 1) {
input.replace(i--, find.length(), replace_with);
if (!replace_all)
i += replace_with.length();
break;
}
} else {
i += j;
break;
}
}
}
}
}
示例2: Parse
/// <summary>Parses all the keywords/macros in a string and replaces them recursively</summary>
/// <param name="text">Source text to parse</param>
/// <param name="depth">Debugging output depth</param>
/// <returns>Fully parsed text</returns>
/// <exception cref="Logic::FileFormatException">Macro contains wrong number of parameters</exception>
/// <exception cref="Logic::Language::RegularExpressionException">RegEx error</exception>
wstring DescriptionParser::Parse(wstring text, int depth) const
{
UINT Position;
wsmatch match;
wstring r;
try
{
#ifdef PRINT_CONSOLE
Console << Cons::Cyan << Indent(depth) << "Parsing: " << Cons::White << text << ENDL;
#endif
// Find/Replace all macros: {AAAA:bbb}, {AAAA:bbb,ccc}, {AAAA:bbb,ccc,ddd} ...
for (Position = 0; regex_search(text.cbegin()+Position, text.cend(), match, MatchMacro); ) // Manually track position for in-place replacement + avoid infinite loop
{
// Recursively generate replacement text
r = onMatchMacro(match, depth);
#ifdef PRINT_CONSOLE
Console << Indent(depth) << "Replacing text: " << Cons::Yellow << match[0].str() << Cons::White << " with " << Cons::Green << r << ENDL;
#endif
// Advance position to beyond inserted text, and insert text
Position = (match[0].first - text.cbegin()) + r.length();
text.replace(match[0].first, match[0].second, r);
}
// Find/Replace all keywords: {AAAAA}, AAAAA
for (Position = 0; regex_search(text.cbegin()+Position, text.cend(), match, MatchKeyword); )
{
// Recursively generate replacement text
r = onMatchKeyword(match, depth);
#ifdef PRINT_CONSOLE
Console << Indent(depth) << "Replacing text: " << Cons::Yellow << match[0].str() << Cons::White << " with " << Cons::Green << r << ENDL;
#endif
// Advance position to beyond inserted text, and insert text
Position = (match[0].first - text.cbegin()) + r.length();
text.replace(match[0].first, match[0].second, r);
}
return text;
}
catch (regex_error& e) {
throw RegularExpressionException(HERE, e);
}
}
示例3: FixPath
bool FixPath(wstring& path) {
// Fix unix paths
std::replace( path.begin(), path.end(), L'/', L'\\' );
// Remove double slashes
while(true) {
size_t p = path.find(L"\\\\");
if (p == string::npos) break;
path.replace(p, 2, L"\\");
}
// Are we pointing at a real destination?
if (DirectoryExists(path)) {
if (path[path.length()-1] != L'\\')
path += L'\\';
return true;
} else if (path.at(path.length() - 1) == L'\\') {
// It says its a directory but it's not, must be a file
path = path.substr(0, path.length() - 1);
}
return FileExists(path);
}
示例4: doReplace
wstring NBTools::doReplace(wstring text, wstring find, wstring replace)
{
while (true)
{
size_t pos = text.find(find);
if (0 > pos || pos > text.length()) return text;
text = text.replace(pos, find.length(), replace);
}
}
示例5: string_replace
void string_replace( wstring& strBig, const wstring& strSrc, const wstring& strDst )
{
wstring::size_type pos=0;
wstring::size_type srclen = strSrc.size();
wstring::size_type dstlen = strDst.size();
while( (pos=strBig.find(strSrc, pos)) != wstring::npos)
{
strBig.replace(pos, srclen, strDst);
pos += dstlen;
}
}
示例6:
/* -----------------------------------------------------------------------
* 関数名 : ws_replace
* 機能概要: str内のbeforeをすべてafterに置換します
* -----------------------------------------------------------------------
*/
void ws_replace(wstring &str, const wstring &before, const wstring &after)
{
int sz_bef = before.size();
int sz_aft = after.size();
for(int rp_pos = 0; ; rp_pos += sz_aft) {
rp_pos = str.find(before, rp_pos);
if (rp_pos == -1)
break;
str.replace(rp_pos, sz_bef, after);
}
}
示例7:
// & の削除
static wstring RemoveAmpersand( wstring sLavel)
{
size_t nPos =0;
while ((nPos = sLavel.find( L"&", nPos)) != wstring::npos) {
if (sLavel[nPos+1] == L'&') {
// &&
sLavel.replace( nPos, 1, L"");
}
nPos ++;
}
return sLavel;
}
示例8: ReplaceChars
void ReplaceChars(wstring& str, const wchar_t chars[],
const wstring replace_with) {
if (chars == replace_with)
return;
size_t pos = 0;
do {
pos = str.find_first_of(chars, pos);
if (pos != wstring::npos)
str.replace(pos, 1, replace_with);
} while (pos != wstring::npos);
}
示例9: Replace
void GraphicsInterface::Replace(wstring & wstrText, wstring wstrFind, wstring wstrReplace)
{
size_t pos = 0;
pos = wstrText.find(wstrFind);
while (pos != wstring::npos)
{
wstrText.replace(pos, wstrFind.length(), wstrReplace);
pos = wstrText.find(wstrFind);
}
return;
}
示例10:
wstring
RegistryMonitor::convertRegistryObjectNameToHiveName(wstring registryObjectName)
{
/* Convert /Registry/Machine etc to the actual hive name like HKLM */
std::list<ObjectPair>::iterator it;
for(it = objectNameMap.begin(); it != objectNameMap.end(); it++)
{
size_t position = registryObjectName.rfind(it->first,0);
if(position != wstring::npos)
{
return registryObjectName.replace(position, it->first.length(), it->second, 0, it->second.length());
}
}
return registryObjectName;
}
示例11:
wstring
FileMonitor::convertFileObjectNameToDosName(wstring fileObjectName)
{
stdext::hash_map<wstring, wstring>::iterator it;
for(it = dosNameMap.begin(); it != dosNameMap.end(); it++)
{
size_t position = fileObjectName.rfind(it->first,0);
if(position != wstring::npos)
{
fileObjectName.replace(position, it->first.length(), it->second, 0, it->second.length());
break;
}
}
//transform(fileObjectName.begin(), fileObjectName.end(), fileObjectName.begin(), tolower);
return fileObjectName;
}
示例12: Populate
/// <summary>Populates the parameters markers within the description source text.</summary>
/// <param name="src">source text.</param>
/// <param name="cmd">command syntax.</param>
/// <returns></returns>
wstring DescriptionParser::Populate(wstring src, CommandSyntaxRef cmd)
{
wsmatch match;
wstring r;
// Replace all {aaa,bbb} markers. Manually track position for in-place replacement + avoid infinite loop
for (int Position = 0; regex_search(src.cbegin()+Position, src.cend(), match, MartchParameterMarker); )
{
r = onParameterMarker(match, cmd);
#ifdef PRINT_CONSOLE
Console << " Replace: " << Cons::Yellow << match[0].str() << Cons::White << " with " << Cons::Green << r << ENDL;
#endif
// Advance position + perform replacement
Position = (match[0].first - src.cbegin()) + r.length();
src.replace(match[0].first, match[0].second, r);
}
return src;
}