コード例 #1
0
ファイル: XmlTreeView.cpp プロジェクト: chrisoldwood/XMLEdit
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
0
ファイル: dig.cpp プロジェクト: henry-bennett/hashdeep
/*
 * 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
0
ファイル: stylesheet.cpp プロジェクト: crazyjul/litehtml
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
0
ファイル: registermenu.cpp プロジェクト: envi/imagepitcher
// 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
0
ファイル: dig.cpp プロジェクト: henry-bennett/hashdeep
/* 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
0
ファイル: registermenu.cpp プロジェクト: envi/imagepitcher
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
0
ファイル: dig.cpp プロジェクト: henry-bennett/hashdeep
/// 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
0
ファイル: ChatCtrl.cpp プロジェクト: Dimetro83/DC_DDD
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);
	}

	// Authors nick
	tstring sAuthor = Text::toT(i.getNick());
	if(!sAuthor.empty()) {
		LONG iLen = (sMsg[0] == _T('*')) ? 1 : 0;
		LONG iAuthorLen = sAuthor.size() + 1;
		sMsg.erase(0, iAuthorLen + iLen);
   		
		lSelBegin = lSelEnd;
		lSelEnd += iAuthorLen + iLen;
		
		if(isMyMessage) {
			SetSel(lSelBegin, lSelBegin + iLen + 1);
			SetSelectionCharFormat(WinUtil::m_ChatTextMyOwn);
			SetSel(lSelBegin + iLen + 1, lSelBegin + iLen + iAuthorLen);
			SetSelectionCharFormat(WinUtil::m_TextStyleMyNick);
		} else {
			bool isFavorite = FavoriteManager::getInstance()->isFavoriteUser(i.getUser());

			if(BOOLSETTING(BOLD_AUTHOR_MESS) || isFavorite || i.isOp()) {
				SetSel(lSelBegin, lSelBegin + iLen + 1);
				SetSelectionCharFormat(cf);
				SetSel(lSelBegin + iLen + 1, lSelEnd);
				if(isFavorite){
					SetSelectionCharFormat(WinUtil::m_TextStyleFavUsers);
				} else if(i.isOp()) {
					SetSelectionCharFormat(WinUtil::m_TextStyleOPs);
				} else {
					SetSelectionCharFormat(WinUtil::m_TextStyleBold);
				}
			} else {
				SetSel(lSelBegin, lSelEnd);
				SetSelectionCharFormat(cf);
            }
		}
	} else {
		bool thirdPerson = false;
        switch(sMsg[0]) {
			case _T('*'):
				if(sMsg[1] != _T(' ')) break;
				thirdPerson = true;
            case _T('<'):
				tstring::size_type iAuthorLen = sMsg.find(thirdPerson ? _T(' ') : _T('>'), thirdPerson ? 2 : 1);
				if(iAuthorLen != tstring::npos) {
                    bool isOp = false, isFavorite = false;

                    if(client != NULL) {
						tstring nick(sMsg.c_str() + 1);
						nick.erase(iAuthorLen - 1);
						
						const OnlineUserPtr ou = client->findUser(Text::fromT(nick));
						if(ou != NULL) {
							isFavorite = FavoriteManager::getInstance()->isFavoriteUser(ou->getUser());
							isOp = ou->getIdentity().isOp();
						}
                    }
                    
					lSelBegin = lSelEnd;
					lSelEnd += iAuthorLen;
					sMsg.erase(0, iAuthorLen);

        			if(BOOLSETTING(BOLD_AUTHOR_MESS) || isFavorite || isOp) {
        				SetSel(lSelBegin, lSelBegin + 1);
        				SetSelectionCharFormat(cf);
						SetSel(lSelBegin + 1, lSelEnd);
						if(isFavorite){
							SetSelectionCharFormat(WinUtil::m_TextStyleFavUsers);
						} else if(isOp) {
							SetSelectionCharFormat(WinUtil::m_TextStyleOPs);
						} else {
							SetSelectionCharFormat(WinUtil::m_TextStyleBold);
						}
        			} else {
        				SetSel(lSelBegin, lSelEnd);
        				SetSelectionCharFormat(cf);
                    }
				}
        }
	}
				   			
	// Format the message part
	FormatChatLine(sMyNick, sMsg, cf, isMyMessage, sAuthor, lSelEnd, bUseEmo);

	SetSel(lSelBeginSaved, lSelEndSaved);
	if(	isMyMessage || ((si.nPage == 0 || (size_t)si.nPos >= (size_t)si.nMax - si.nPage - 5) &&
		(lSelBeginSaved == lSelEndSaved || !selectedUser.empty() || !selectedIP.empty() || !selectedURL.empty())))
	{
		PostMessage(EM_SCROLL, SB_BOTTOM, 0);
	} else {
		SetScrollPos(&pt);
	}

	// Force window to redraw
	SetRedraw(TRUE);
	InvalidateRect(NULL);
}
コード例 #9
0
ファイル: BrainMemory.cpp プロジェクト: GMIS/GMIS
int32 CBrainMemory::RetrieveText(int64 MeaningID,tstring& Text,bool Nest){

	int64 CurrentRoomValue,RoomType; 
    int64  CurrentID = MeaningID;

	//首先得到意义空间的信息
	if(!GetRoomInfo(MeaningID,CurrentRoomValue,RoomType))return 0;

	if(!Nest){
		//首次外部调用时检查MeaningID代表记忆是否为可读的文字信息,嵌套调用则忽略
		if(UnReadable(CurrentRoomValue))return 0;
	}

	//向上漫游,找到父空间空间的ID和逻辑明文,得记忆的形ID
    CppSQLite3Query Result = LBrainQuery("*",CurrentRoomValue,LB_CHILD_ID,CurrentID);
	if(Result.eof())return 0;
    
	CurrentID = Result.getInt64Field(0);
  	if(CurrentID == ROOT_SPACE)return 0;
	CurrentRoomValue = Result.getInt64Field(1);  //总是其他空间的空间识别ID
	
    
	//如果是字符,则可以确定所取文本应该是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;
}