Exemplo n.º 1
0
CString SprEncodeHighAnsi(LPCTSTR lpText)
{
	CStringBuilderEx sb;

	DWORD dwPos = 0;
	while(lpText[dwPos] != 0)
	{
		const TCHAR tch = lpText[dwPos];
		const unsigned char uch = static_cast<unsigned char>(tch);

		if(uch >= 0x7F)
		{
			sb += _T("%({NUMPAD0}");

			CString strConv;
			strConv.Format(_T("%u"), uch);
			ASSERT(strConv.GetLength() == 3);

			for(int i = 0; i < strConv.GetLength(); ++i)
			{
				sb += _T("{NUMPAD");
				sb += strConv.GetAt(i);
				sb += _T("}");
			}

			sb += _T(")");
		}
		else sb += tch;

		++dwPos;
	}

	return CString(sb.ToString().c_str());
}
Exemplo n.º 2
0
CString SprTagSimString(LPCTSTR lpString)
{
	CStringBuilderEx sb;

	ASSERT(lpString != NULL); if(lpString == NULL) return CString();

	DWORD i = 0;
	while(lpString[i] != 0)
	{
		const TCHAR tch = lpString[i];

		switch(tch)
		{
			case _T('+'): sb += _T("{PLUS}"); break;
			case _T('@'): sb += _T("{AT}"); break;
			// case _T('~'): sb += _T("{TILDE}"); break;
			case _T('~'): sb += _T("%({NUMPAD0}{NUMPAD1}{NUMPAD2}{NUMPAD6})"); break;
			case _T('^'): sb += _T("%({NUMPAD0}{NUMPAD9}{NUMPAD4})"); break;
			case _T('\''): sb += _T("%({NUMPAD0}{NUMPAD3}{NUMPAD9})"); break;
			case _T('"'): sb += _T("%({NUMPAD0}{NUMPAD3}{NUMPAD4})"); break;
			case _T('´'): sb += _T("%({NUMPAD0}{NUMPAD1}{NUMPAD8}{NUMPAD0})"); break;
			case _T('`'): sb += _T("%({NUMPAD0}{NUMPAD9}{NUMPAD6})"); break;
			case _T('%'): sb += _T("{PERCENT}"); break;
			case _T('{'): sb += _T("{LEFTBRACE}"); break;
			case _T('}'): sb += _T("{RIGHTBRACE}"); break;
			case _T('('): sb += _T("{LEFTPAREN}"); break;
			case _T(')'): sb += _T("{RIGHTPAREN}"); break;
			default: sb += tch; break;
		}

		++i;
	}

	return CString(sb.ToString().c_str());
}
Exemplo n.º 3
0
std::vector<std::basic_string<TCHAR> > SU_SplitSearchTerms(LPCTSTR lpSearch)
{
	std::vector<std::basic_string<TCHAR> > v;
	if((lpSearch == NULL) || (lpSearch[0] == 0)) return v;

	CStringBuilderEx sbTerm;
	bool bQuoted = false;

	const size_t uLen = _tcslen(lpSearch);
	for(size_t i = 0; i < uLen; ++i)
	{
		TCHAR ch = lpSearch[i];

		if(((ch == _T(' ')) || (ch == _T('\t')) || (ch == _T('\r')) ||
			(ch == _T('\n'))) && !bQuoted)
		{
			if(sbTerm.GetLength() > 0) v.push_back(sbTerm.ToString());

			sbTerm.Clear();
		}
		else if(ch == _T('\"')) bQuoted = !bQuoted;
		else sbTerm.Append(ch);
	}
	if(sbTerm.GetLength() > 0) v.push_back(sbTerm.ToString());

	return v;
}
Exemplo n.º 4
0
std::basic_string<TCHAR> CEntryUtil::CreateSummaryList(CPwManager* pMgr,
	const std::vector<DWORD>& vEntryIndices)
{
	std::basic_string<TCHAR> strEmpty;
	if(pMgr == NULL) { ASSERT(FALSE); return strEmpty; }
	if(vEntryIndices.size() == 0) return strEmpty;

	const size_t uMaxEntries = 10;
	size_t uSummaryShow = min(uMaxEntries, vEntryIndices.size());
	if(uSummaryShow == (vEntryIndices.size() - 1)) --uSummaryShow; // Plural msg

	CStringBuilderEx sb;
	for(size_t i = 0; i < uSummaryShow; ++i)
	{
		PW_ENTRY* pe = pMgr->GetEntry(vEntryIndices[i]);
		if(pe == NULL) { ASSERT(FALSE); continue; }

		if(sb.GetLength() > 0) sb.Append(_T("\r\n"));

		sb.Append(_T("- "));
		std::basic_string<TCHAR> strItem = SU_CompactWith3Dots(pe->pszTitle, 39);
		sb.Append(strItem.c_str());

		if(CPwUtil::IsTANEntry(pe) != FALSE)
		{
			std::basic_string<TCHAR> strTanID = SU_CompactWith3Dots(pe->pszUserName, 39);
			if(strTanID.size() > 0)
			{
				sb.Append(_T(" (#"));
				sb.Append(strTanID.c_str());
				sb.Append(_T(")"));
			}
		}
	}

	if(uSummaryShow != vEntryIndices.size())
	{
		const std::basic_string<TCHAR> strCount =
			boost::lexical_cast<std::basic_string<TCHAR> >(static_cast<int>(
			vEntryIndices.size() - uSummaryShow));

		CString strMore = TRL("{PARAM} more entries");
		VERIFY(strMore.Replace(_T("{PARAM}"), strCount.c_str()) == 1);

		sb.Append(_T("\r\n- "));
		sb.Append(strMore);
	}

	return sb.ToString();
}