本文整理汇总了C++中tstring::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ tstring::replace方法的具体用法?C++ tstring::replace怎么用?C++ tstring::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tstring
的用法示例。
在下文中一共展示了tstring::replace方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replaceVariables
void VariableHandler::replaceVariables(tstring &source)
{
tstring::size_type startPos, endPos;
startPos = 0;
endPos = tstring::npos;
do
{
startPos = source.find(_T('$'), startPos);
if (startPos != tstring::npos)
{
endPos = source.find(_T('$'), startPos + 1);
if (endPos == tstring::npos)
break;
}
if (endPos != tstring::npos)
{
tstring varValue = (*_variables)[source.substr(startPos + 1, endPos - startPos - 1)];
source.replace(startPos, endPos - startPos + 1, varValue);
startPos = startPos + varValue.size();
endPos = tstring::npos;
}
} while(startPos != tstring::npos);
}
示例2: rtfEscape
tstring ChatCtrl::rtfEscape(tstring str) {
tstring::size_type i = 0;
while((i = str.find_first_of(_T("{}\\\n"), i)) != tstring::npos) {
switch(str[i]) {
// no need to process \r handled elsewhere
case '\n': str.replace(i, 1, _T("\\line\n")); i+=6; break;
default: str.insert(i, _T("\\")); i+=2;
}
}
return str;
}
示例3: escapeUnicode
string ChatCtrl::escapeUnicode(tstring str) {
TCHAR buf[8];
memzero(buf, sizeof(buf));
int dist = 0;
tstring::iterator i;
while((i = std::find_if(str.begin() + dist, str.end(), std::bind2nd(std::greater<TCHAR>(), 0x7f))) != str.end()) {
dist = (i+1) - str.begin(); // Random Acess iterators FTW
snwprintf(buf, sizeof(buf), _T("%hd"), int(*i));
str.replace(i, i+1, _T("\\ud\\u") + tstring(buf) + _T("?"));
memzero(buf, sizeof(buf));
}
return Text::fromT(str);
}
示例4: ReadLevelInfo
void CGameServer::ReadLevelInfo(tstring sFile)
{
std::basic_ifstream<tchar> f(sFile.c_str());
CData* pData = new CData();
CDataSerializer::Read(f, pData);
CResource<CLevel> pLevel = CreateLevel();
pLevel->SetFile(sFile.replace("\\", "/"));
pLevel->ReadInfoFromData(pData);
m_apLevels.push_back(pLevel);
delete pData;
}
示例5: prettify
void CmdDlg::prettify(tstring &text)
{
try {
const tstring search(_T("\n")), replace(_T("\r\n"));
// http://stackoverflow.com/a/14678800/98528
tstring::size_type pos = 0;
while ((pos = text.find(search, pos)) != tstring::npos) {
text.replace(pos, search.length(), replace);
pos += replace.length();
}
text += replace;
} catch (...) {
text.clear();
}
}
示例6:
CHandle<CLevel> CGameServer::GetLevel(tstring sFile)
{
sFile = sFile.replace("\\", "/");
sFile.trim();
for (size_t i = 0; i < m_apLevels.size(); i++)
{
CResource<CLevel>& pLevel = m_apLevels[i];
tstring sLevelFile = pLevel->GetFile();
if (sLevelFile == sFile)
return pLevel;
if (sLevelFile == sFile + ".txt")
return pLevel;
if (sLevelFile == tstring("levels/") + sFile)
return pLevel;
if (sLevelFile == tstring("levels/") + sFile + ".txt")
return pLevel;
}
return CHandle<CLevel>();
}
示例7: FormatEmoticonsAndLinks
void ChatCtrl::FormatEmoticonsAndLinks(tstring& sMsg, tstring& sMsgLower, LONG lSelBegin, bool bUseEmo) {
if(!sMsg.size())
return;
LONG lSelEnd = lSelBegin + sMsg.size();
// hightlight all URLs and make them clickable
for(size_t i = 0; i < (sizeof(protocols) / sizeof(protocols[0])); ++i) {
size_t linkStart = sMsgLower.find(protocols[i]);
bool isMagnet = (protocols[i] == _T("magnet:?"));
while(linkStart != tstring::npos) {
size_t linkEnd = linkStart + protocols[i].size();
try {
// TODO: complete regexp for URLs
std::tr1::wregex reg;
//[+]PPA Исправил регулярное выражение для коррктного поиска урлов в VC++ 2010 (пример урла - magnet:?xt=urn:tree:tiger:V3LVT4CSASPLNHRG6DOORAD2SDSBBANIKEI7XHI&xl=260524251&dn=cstrike_full_v.35_(4156).exe )
if(isMagnet) // magnet links have totally indifferent structure than classic URL // -/?%&=~#'\\w\\.\\+\\*\\(\\)
reg.assign(_T("^(\\w)+=[:\\w]+(&(\\w)+=[\\S]*)*[^\\s<>{}\"']+"), std::tr1::regex_constants::icase);
else
reg.assign(_T("^([@\\w-]+(\\.)*)+(:[\\d]+)?(/[\\S]*)*[^\\s<>{}\"']+"), std::tr1::regex_constants::icase);
tstring::const_iterator start = sMsg.begin();
tstring::const_iterator end = sMsg.end();
std::tr1::match_results<tstring::const_iterator> result;
if(std::tr1::regex_search(start + linkEnd, end, result, reg, std::tr1::regex_constants::match_default)) {
dcassert(!result.empty());
linkEnd += result.length(0);
SetSel(lSelBegin + linkStart, lSelBegin + linkEnd);
if(isMagnet) {
tstring cURL = ((tstring)(result[0]));
tstring::size_type dn = cURL.find(_T("dn="));
if(dn != tstring::npos) {
string sFileName = Util::encodeURI(Text::fromT(cURL).substr(dn + 3), true);
int64_t filesize = Util::toInt64(Text::fromT(cURL.substr(cURL.find(_T("xl=")) + 3, cURL.find(_T("&")) - cURL.find(_T("xl=")))));
tstring shortLink = Text::toT(sFileName) + _T(" (") + Util::formatBytesW(filesize) + _T(")");
sMsg.replace(linkStart, linkEnd - linkStart, shortLink.c_str());
std::transform(&sMsgLower.replace(linkStart, linkEnd - linkStart, shortLink.c_str())[linkStart], &sMsgLower[linkEnd], &sMsgLower[linkStart], _totlower);
setText(shortLink);
linkEnd = linkStart + shortLink.size();
SetSel(lSelBegin + linkStart, lSelBegin + linkEnd);
magnets[shortLink] = _T("magnet:?") + cURL;
}
}
SetSelectionCharFormat(WinUtil::m_TextStyleURL);
}
} catch(...) {
}
linkStart = sMsgLower.find(protocols[i], linkEnd);
}
}
// insert emoticons
if(bUseEmo && emoticonsManager->getUseEmoticons()) {
const Emoticon::List& emoticonsList = emoticonsManager->getEmoticonsList();
tstring::size_type lastReplace = 0;
uint8_t smiles = 0;
while(true) {
tstring::size_type curReplace = tstring::npos;
Emoticon* foundEmoticon = NULL;
for(Emoticon::Iter emoticon = emoticonsList.begin(); emoticon != emoticonsList.end(); ++emoticon) {
tstring::size_type idxFound = sMsg.find((*emoticon)->getEmoticonText(), lastReplace);
if(idxFound < curReplace || curReplace == tstring::npos) {
curReplace = idxFound;
foundEmoticon = (*emoticon);
}
}
if(curReplace != tstring::npos && smiles < MAX_EMOTICONS) {
CHARFORMAT2 cfSel;
cfSel.cbSize = sizeof(cfSel);
lSelBegin += (curReplace - lastReplace);
lSelEnd = lSelBegin + foundEmoticon->getEmoticonText().size();
SetSel(lSelBegin, lSelEnd);
GetSelectionCharFormat(cfSel);
if(!(cfSel.dwEffects & CFE_LINK)) {
CImageDataObject::InsertBitmap(GetOleInterface(), foundEmoticon->getEmoticonBmp(cfSel.crBackColor));
++smiles;
++lSelBegin;
} else lSelBegin = lSelEnd;
lastReplace = curReplace + foundEmoticon->getEmoticonText().size();
} else break;
}
}
}