本文整理汇总了C++中tstring::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ tstring::erase方法的具体用法?C++ tstring::erase怎么用?C++ tstring::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tstring
的用法示例。
在下文中一共展示了tstring::erase方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PostProcessSummary
void XmlTreeView::PostProcessSummary(tstring& str)
{
// Replace empty strings.
if (str.empty())
{
str = TXT("(empty)");
return;
}
bool bWhitespaceOnly = true;
// Find if only whitespace characters.
for (tstring::const_iterator it = str.begin(); ((it != str.end()) && bWhitespaceOnly); ++it)
{
if (!tisspace(static_cast<utchar>(*it)))
bWhitespaceOnly = false;
}
// Replace "invisible" strings.
if (bWhitespaceOnly)
{
str = TXT("(whitespace)");
return;
}
// Trim string.
if (str.length() > App.m_nDefMaxItemLen)
{
str.erase(App.m_nDefMaxItemLen, str.length()-App.m_nDefMaxItemLen);
str += TXT("...");
}
}
示例2: remove_single_dirs
/*
* remove any /./
*/
static void remove_single_dirs(tstring &fn)
{
tstring search;
search.push_back(DIR_SEPARATOR);
search.push_back('.');
search.push_back(DIR_SEPARATOR);
while(true){
size_t loc = fn.find(search);
if(loc==tstring::npos) break; // no more to find
fn.erase(fn.begin()+loc,fn.begin()+loc+2); // erase
}
}
示例3:
void litehtml::css::parse_css_url( const tstring& str, tstring& url )
{
url = _t("");
size_t pos1 = str.find(_t('('));
size_t pos2 = str.find(_t(')'));
if(pos1 != tstring::npos && pos2 != tstring::npos)
{
url = str.substr(pos1 + 1, pos2 - pos1 - 1);
if(url.length())
{
if(url[0] == _t('\'') || url[0] == _t('"'))
{
url.erase(0, 1);
}
}
if(url.length())
{
if(url[url.length() - 1] == _t('\'') || url[url.length() - 1] == _t('"'))
{
url.erase(url.length() - 1, 1);
}
}
}
}
示例4: Register
// HKEY_CLASSES_ROOT
// FileMarker.AVI - AVI - Windows 기본 비디오 파일
// shell
// Mark - Daum 팟플레이어의 재생목록(&I)에 추가하기
// command - "C:\Program Files (x86)\DAUM\PotPlayer\PotPlayer.exe" "%1" /ADD
bool CRegisterMenu::Register(const tstring& strAppName, tstring strExt,
tstring strMenu, tstring strMenuDisplay,
tstring strCommand, tstring strDesc)
{
if (strAppName.empty() || strExt.empty() || strDesc.empty() ||
strMenu.empty() || strMenuDisplay.empty() || strCommand.empty())
return false;
if (!RegisterExtKey(strExt, strMenu, strMenuDisplay, strCommand))
return false;
// remove '.'
strExt.erase(std::remove(strExt.begin(), strExt.end(), _T('.')), strExt.end());
// Uppercase extension
CStringUtil::MakeUpper(strExt);
tstring strAppExt = strAppName + _T(".") + strExt;
LPCTSTR strSubKeys[] = { strAppExt.c_str(),
_T("shell"),
strMenu.c_str(),
_T("command") };
LPCTSTR strValues[] = { strDesc.c_str(),
_T(""),
strMenuDisplay.c_str(),
strCommand.c_str() };
tstring strSubKey;
tstring strValue;
for (int i = 0; i < _countof(strSubKeys); ++i)
{
strSubKey += strSubKeys[i];
strSubKey += _T("\\");
strValue = strValues[i];
if (!RegisterMenu(strSubKey, strValue))
return false;
}
// SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, NULL, NULL);
return true;
}
示例5: remove_double_slash
/* POSIX version of clean_name */
static void remove_double_slash(tstring &fn)
{
tstring search;
search.push_back(DIR_SEPARATOR);
search.push_back(DIR_SEPARATOR);
#ifdef _WIN32
// On Windows, we have to allow the first two characters to be slashes
// to account for UNC paths. e.g. \\SERVER\dir\path
// So on windows we ignore the first character
size_t start = 1;
#else
size_t start = 0;
#endif
while(true){
size_t loc = fn.find(search,start);
if(loc==tstring::npos) break; // no more to find
fn.erase(loc,1); // erase one of the two slashes
}
}
示例6: UnRegister
bool CRegisterMenu::UnRegister(tstring strAppName, tstring strExt, tstring strMenu)
{
if ( strAppName.empty()
|| strExt.empty()
|| strMenu.empty())
return false;
if (!UnRegisterExtKey(strExt, strMenu))
{
return false;
}
// remove '.'
strExt.erase(std::remove(strExt.begin(), strExt.end(), _T('.')), strExt.end());
// Uppercase extension
CStringUtil::MakeUpper(strExt);
tstring strAppExt = strAppName + _T(".") + strExt;
return UnRegisterMenu(strAppExt);
}
示例7: remove_double_dirs
/// Removes all "../" references from the absolute path fn
/// If string contains f/d/e/../a replace it with f/d/a/
static void remove_double_dirs(tstring &fn) {
tstring search;
search.push_back(DIR_SEPARATOR);
search.push_back('.');
search.push_back('.');
search.push_back(DIR_SEPARATOR);
while (true) {
size_t loc = fn.find(search);
if (loc == tstring::npos)
break;
// See if there is another dir separator before the /../ we just
// found.
size_t before = fn.rfind(DIR_SEPARATOR, loc-1);
if (before == tstring::npos)
break;
// Now delete all between before+1 and loc+3
fn.erase(fn.begin()+before+1, fn.begin()+loc+4);
}
}
示例8: AppendText
void ChatCtrl::AppendText(const Identity& i, const tstring& sMyNick, const tstring& sTime, tstring sMsg, CHARFORMAT2& cf, bool bUseEmo/* = true*/) {
SetRedraw(FALSE);
SCROLLINFO si = { 0 };
POINT pt = { 0 };
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
GetScrollInfo(SB_VERT, &si);
GetScrollPos(&pt);
LONG lSelBegin = 0, lSelEnd = 0, lTextLimit = 0, lNewTextLen = 0;
LONG lSelBeginSaved, lSelEndSaved;
// Unify line endings
tstring::size_type j = 0;
while((j = sMsg.find(_T("\r"), j)) != tstring::npos)
sMsg.erase(j, 1);
GetSel(lSelBeginSaved, lSelEndSaved);
lSelEnd = lSelBegin = GetTextLengthEx(GTL_NUMCHARS);
bool isMyMessage = i.getUser() == ClientManager::getInstance()->getMe();
tstring sLine = sTime + sMsg;
// Remove old chat if size exceeds
lNewTextLen = sLine.size();
lTextLimit = GetLimitText();
if(lSelEnd + lNewTextLen > lTextLimit) {
LONG lRemoveChars = 0;
int multiplier = 1;
if(lNewTextLen >= lTextLimit) {
lRemoveChars = lSelEnd;
magnets.clear();
} else {
while(lRemoveChars < lNewTextLen)
lRemoveChars = LineIndex(LineFromChar(multiplier++ * lTextLimit / 10));
}
if(magnets.size()) {
tstring buf;
buf.resize(lRemoveChars);
GetTextRange(0, lRemoveChars, &buf[0]);
CHARFORMAT2 cfSel;
cfSel.cbSize = sizeof(CHARFORMAT2);
for(TStringMap::iterator i = magnets.begin(); i != magnets.end();) {
tstring::size_type j = 0;
while((j = buf.find(i->first, j)) != tstring::npos) {
SetSel(j, j + i->first.size());
GetSelectionCharFormat(cfSel);
if(cfSel.dwEffects & CFE_LINK) {
magnets.erase(i++);
break;
}
j += i->first.size();
} if(j == tstring::npos) {
++i;
}
}
}
// Update selection ranges
lSelEnd = lSelBegin -= lRemoveChars;
lSelEndSaved -= lRemoveChars;
lSelBeginSaved -= lRemoveChars;
// ...and the scroll position
pt.y -= PosFromChar(lRemoveChars).y;
SetSel(0, lRemoveChars);
ReplaceSel(_T(""));
}
// Add to the end
SetSel(lSelBegin, lSelEnd);
setText(sLine);
CHARFORMAT2 enc;
enc.bCharSet = RUSSIAN_CHARSET;
enc.dwMask = CFM_CHARSET;
SetSel(0, sLine.length());
SetSelectionCharFormat(enc);
// Format TimeStamp
if(!sTime.empty()) {
lSelEnd += sTime.size();
SetSel(lSelBegin, lSelEnd - 1);
SetSelectionCharFormat(WinUtil::m_TextStyleTimestamp);
PARAFORMAT2 pf;
memzero(&pf, sizeof(PARAFORMAT2));
pf.dwMask = PFM_STARTINDENT;
pf.dxStartIndent = 0;
SetParaFormat(pf);
//.........这里部分代码省略.........
示例9: RetrieveText
//.........这里部分代码省略.........
//如果是字符,则可以确定所取文本应该是token
int ch = IDToChar(CurrentRoomValue);
if(isascii(ch)){
TCHAR buf[100]; //暂存token,一个单词99字符应该足够了
int p = 0;
buf[p++] = ch;
//继续向上漫游,应该全部都是字符
for(;;){
//根据本空间的ID和逻辑明文,找到父空间空间的ID和逻辑明文,
CppSQLite3Query Result = LBrainQuery("*",CurrentRoomValue,LB_CHILD_ID,CurrentID);
if(Result.eof())return 0;
CurrentID = Result.getInt64Field(0);
//如果得到的空间ID为根空间,则表示找到顶了。
if(CurrentID == ROOT_SPACE){
buf[p]='\0';
_tcsrev(buf);
Text = buf;
//如果是形容词则加上引号
if(RoomType == MEMORY_REFERENCE){
Text.insert(Text.begin(),1,_T('\"'));
Text+=_T('\"');
}
return 1; //表示得到一个token
}
CurrentRoomValue = Result.getInt64Field(1);
if(p<100) buf[p++] = IDToChar(CurrentRoomValue);
}
}
//不是字符,则需要嵌套处理,然后根据返回值添加标点符号
int32 n = 0;
vector<tstring> StrList;
for(;;){
tstring s;
n = RetrieveText(CurrentRoomValue,s,false);
StrList.push_back(s);
//继续向上漫游,根据本空间的ID和逻辑明文,找到父空间空间的ID和逻辑明文,
CppSQLite3Query Result = LBrainQuery("*",CurrentRoomValue,LB_CHILD_ID,CurrentID);
if(Result.eof())return 0;
CurrentID = Result.getInt64Field(0);
//如果得到的空间ID为根空间,则表示找到顶了。
if(CurrentID == ROOT_SPACE)break;
CurrentRoomValue = Result.getInt64Field(1);
}
TCHAR flag=_T(' ');
if(n==1){ //子句,token之间应该有空格
flag = _T(' ');
}
else if(n==2){ //句子,子句之间有逗号
flag = _T(',');
}
else if(n ==3){ //段落,句子之间有句号
flag = _T('.');
}
else if(n== 4){//文本,段落之间要分行
flag = _T('\n');
}
assert(n<5);
vector<tstring>::reverse_iterator It = StrList.rbegin();
while(It != StrList.rend()){
Text += *It;
if(Text.size()){
TCHAR& ch = Text[Text.size()-1];
if(!ispunct(ch)){
Text += flag;
}else if(Text.size()>2) {
ch = Text[Text.size()-2];
if (isspace(ch))
{
Text.erase(Text.size()-2,1);
}
}
}
It++;
}
if(RoomType == MEMORY_REFERENCE)
{
Text.insert(Text.begin(),1,_T('\"'));
Text+='\"';
assert(n==1 || n==0); //引用被看作是一个token,应该只出现在子句里
return 1;
}
return ++n;
}