示例#1
0
void TestParser::removeAnsiMarksTest()
{
    QString ansiString("\033[32mHello world\033[0m");
    QString expected("Hello world");
    ParserUtils::removeAnsiMarksInPlace(ansiString);
    QCOMPARE(ansiString, expected);
}
	void Clipboard::SetTextImpl(std::string& newText)
	{
		if (newText.empty())
		{
			this->ClearText();
			return;
		}

		HWND eventWindow = Win32Host::Win32Instance()->GetEventWindow();
		if (!OpenClipboard(eventWindow))
		{
			std::string error(Win32Utils::QuickFormatMessage(GetLastError()));
			throw ValueException::FromFormat("Could not open Win32 clipbaord: %s",
				error.c_str());
		}

		// Do not empty clipboard here, because we want to preserve existing data of
		// different types.

		// We need to use the default ANSI code page when setting the clipboard
		// data, not the data passed in, which is in Unicode.
		std::wstring wideString(::UTF8ToWide(newText));
		std::string ansiString(::WideToMultiByte(wideString, CP_ACP));

		size_t length = ansiString.size() + 1;
		HGLOBAL clipboardData = ::GlobalAlloc(GMEM_MOVEABLE, length);
		if (!clipboardData)
		{
			CloseClipboard();
			std::string error(Win32Utils::QuickFormatMessage(GetLastError()));
			throw ValueException::FromFormat(
				"Could allocate ASNI clipbaord data: %s", error.c_str());
		}
		LPVOID data = ::GlobalLock(clipboardData);
		CopyMemory(data, ansiString.c_str(), length);
		::GlobalUnlock(clipboardData);
		SetClipboardData(CF_TEXT, clipboardData);

		length = (wideString.size() + 1) * sizeof(wchar_t);
		clipboardData = ::GlobalAlloc(GMEM_MOVEABLE, length);
		if (!clipboardData)
		{
			CloseClipboard();
			std::string error(Win32Utils::QuickFormatMessage(GetLastError()));
			throw ValueException::FromFormat(
				"Could allocate Unicode clipbaord data: %s", error.c_str());
		}
		data = ::GlobalLock(clipboardData);
		CopyMemory(data, wideString.c_str(), length);
		::GlobalUnlock(clipboardData);
		SetClipboardData(CF_UNICODETEXT, clipboardData);
	}