Exemplo n.º 1
0
//----------------------------------------------------------------------
// Converts a UTF8 encoded string to a unicode string
// See the following document for more information:
// RFC2279: UTF-8, a transformation format of ISO 10646
// Author: pdaehne
//----------------------------------------------------------------------
void TextFace::convertUTF8ToUnicode(const string &utf8Text, wstring &text)
{
    // Clear and prepare the result string
    text.erase();
    text.reserve(utf8Text.length());

    // Transform UTF8 sequences to UTF16 sequences
    const char *pos = utf8Text.c_str();
    while (*pos != '\0')
        text.append(1, utf8Char2Unicode(pos));
}
void RandomStringGenerator::generate(wstring &str) {
	static const wchar_t alphabet[] =
		L"abcdefghijklmnopqrstuvwxyz"
		L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		L"0123456789";

	random_device rd;
	default_random_engine rng(rd());
	uniform_int_distribution<> dist(0,sizeof(alphabet)/sizeof(*alphabet)-2);

	str.clear();
	str.reserve(NAME_LENGTH);
	generate_n(back_inserter(str), NAME_LENGTH,
		[&] { return alphabet[dist(rng)]; });
}
Exemplo n.º 3
0
static void do_log(int log_level, const char *msg, va_list args, void *param)
{
	fstream &logFile = *static_cast<fstream*>(param);
	char str[4096];

#ifndef _WIN32
	va_list args2;
	va_copy(args2, args);
#endif

	vsnprintf(str, 4095, msg, args);

#ifdef _WIN32
	if (IsDebuggerPresent()) {
		int wNum = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
		if (wNum > 1) {
			static wstring wide_buf;
			static mutex wide_mutex;

			lock_guard<mutex> lock(wide_mutex);
			wide_buf.reserve(wNum + 1);
			wide_buf.resize(wNum - 1);
			MultiByteToWideChar(CP_UTF8, 0, str, -1, &wide_buf[0],
					wNum);
			wide_buf.push_back('\n');

			OutputDebugStringW(wide_buf.c_str());
		}
	}
#else
	def_log_handler(log_level, msg, args2, nullptr);
#endif

	if (too_many_repeated_entries(logFile, msg, str))
		return;

	if (log_level <= LOG_INFO || log_verbose)
		LogStringChunk(logFile, str);

#if defined(_WIN32) && defined(OBS_DEBUGBREAK_ON_ERROR)
	if (log_level <= LOG_ERROR && IsDebuggerPresent())
		__debugbreak();
#endif
}
Exemplo n.º 4
0
//FPS Counter
void FPSCounter(HINSTANCE hInstance)
{
	static int frames = 0;
	static double starttime = CTimeManager::GetElapsedTimeD();
	static float fps = 0.0f;

	if (CTimeManager::GetElapsedTimeD() - starttime > 0.25 && frames > 10)
	{
		fps_string.clear();
		fps_string.reserve(MAX_LOADSTRING);
		fps_string = szTitle;
		fps = float((double)frames / double(CTimeManager::GetElapsedTimeD() - starttime));
		starttime = CTimeManager::GetElapsedTimeD();
		frames = 0;
		fps_string += L" FPS: ";
		wchar_t temp[32];
		_snwprintf_s(temp, 32u, L"%f", fps);
		fps_string += temp;
		SendMessage(hWnd, WM_SETTEXT, NULL, (LPARAM)fps_string.data());
	}


	frames++;
}