コード例 #1
0
ファイル: process.cpp プロジェクト: BattleNWar/YDWE
bool process::create(const std::wstring& command_line, const boost::filesystem::path& current_directory)
{
    if (statue_ == PROCESS_STATUE_READY)
    {
        if (command_line.empty())
        {
            if (!detail::create_process(
                        nullptr,
                        nullptr,
                        inherit_handle_,
                        NORMAL_PRIORITY_CLASS,
                        boost::filesystem::exists(current_directory) ? current_directory.c_str(): nullptr,
                        &si_, &pi_, inject_dll_
                    ))
            {
                return false;
            }
        }
        else
        {
            std::dynarray<wchar_t> command_line_buffer(command_line.size()+1);
            wcscpy_s(command_line_buffer.data(), command_line_buffer.size(), command_line.c_str());

            if (!detail::create_process(
                        nullptr,
                        command_line_buffer.data(),
                        inherit_handle_,
                        NORMAL_PRIORITY_CLASS,
                        boost::filesystem::exists(current_directory) ? current_directory.c_str(): nullptr,
                        &si_, &pi_, inject_dll_
                    ))
            {
                return false;
            }
        }

        statue_ = PROCESS_STATUE_RUNNING;
        return true;
    }

    return false;
}
コード例 #2
0
ファイル: uri.cpp プロジェクト: Awa128/picotorrent
uri::uri(const std::wstring &url)
    : raw_(url)
{
    URL_COMPONENTS components = { 0 };
    components.dwStructSize = sizeof(URL_COMPONENTS);
    components.dwSchemeLength = (DWORD)-1;
    components.dwHostNameLength = (DWORD)-1;
    components.dwUrlPathLength = (DWORD)-1;
    components.dwExtraInfoLength = (DWORD)-1;

    WinHttpCrackUrl(
        url.c_str(),
        (DWORD)url.size(),
        0,
        &components);

    hostName_ = std::wstring(components.lpszHostName, components.dwHostNameLength);
    port_ = components.nPort;
    urlPath_ = components.lpszUrlPath;
}
コード例 #3
0
void CEquationEditorWindow::DrawString( const std::wstring& text, const CRect& textRect, bool isSelected )
{
	RECT rect;
	rect.bottom = textRect.Bottom();
	rect.top = textRect.Top();
	rect.left = textRect.Left();
	rect.right = textRect.Right();
	HFONT font = getFont( textRect.GetHeight() );
	HGDIOBJ oldObject = ::SelectObject( hdc, font );

	if( isSelected ) {
		::SetTextColor( hdc, symbolSelectedColorref );
		::SetBkColor( hdc, bkSelectedColorref );
	} else {
		::SetTextColor( hdc, symbolUnselectedColorref );
		::SetBkColor( hdc, bkUnselectedColorref );
	}
	::DrawText( hdc, text.c_str(), text.size(), &rect, DT_LEFT );
	::SelectObject( hdc, oldObject );
}
コード例 #4
0
	void WriteString(std::ofstream& fileStream, const std::wstring& str)
	{
		const char* tempPtr = nullptr;
		uint32_t size = 0;
		uint32_t sizeToWrite = 0;

		//size of name
		size		= (uint32_t)str.size();
		tempPtr		= reinterpret_cast<const char*>(&size);
		sizeToWrite = sizeof(uint32_t);
		fileStream.write(tempPtr, sizeToWrite);

		if(size != 0)
		{
			//Name
			tempPtr		= reinterpret_cast<const char*>(str.c_str());
			sizeToWrite	= sizeof(wchar_t) * size;
			fileStream.write(tempPtr, sizeToWrite);
		}
	}
コード例 #5
0
ファイル: StringUtils.cpp プロジェクト: dbremner/sktoolslib
void SearchReplace(std::wstring& str, const std::wstring& toreplace, const std::wstring& replacewith)
{
    std::wstring result;
    std::wstring::size_type pos = 0;
    for (;;)    // while (true)
    {
        std::wstring::size_type next = str.find(toreplace, pos);
        result.append(str, pos, next-pos);
        if (next != std::string::npos)
        {
            result.append(replacewith);
            pos = next + toreplace.size();
        }
        else
        {
            break;  // exit loop
        }
    }
    str.swap(result);
}
コード例 #6
0
std::wstring Trim(const std::wstring& wstr)
{
	if (wstr.empty())
		return wstr;

	int i = 0, iSize = wstr.size();
	while (i < iSize && (wstr[i] == L' ' || wstr[i] == L'\t' ||
		wstr[i] == L'\n' || wstr[i] == L'\r')) i++;
	if (i >= iSize)
		return L"";

	int iMax = iSize - 1;
	while (iMax >= i && (wstr[iMax] == L' ' || wstr[iMax] == L'\t' ||
		wstr[iMax] == L'\n' || wstr[iMax] == L'\r')) iMax--;

	std::wstring wstrRet;
	for (; i <= iMax; ++i)
		wstrRet.push_back(wstr[i]);
	return wstrRet;
}
コード例 #7
0
ファイル: text_file.cpp プロジェクト: antonte/texteditor
std::wstring TextFile::preInsert(Coord &cursor, const std::wstring &value)
{
  if (value.size() != 1 || value[0] != '\n')
    return value;
  else
  {
    auto &line = (*this)[cursor.y];
    std::wstring spaces;
    int c = 0;
    for (auto ch: line)
      if (ch == L' ')
        ++c;
      else
        break;
    for (size_t x = cursor.x; x < line.size() && line[x] == ' '; ++x, --c);
    for (int i = 0; i < c; ++i)
      spaces += L' ';
    return L'\n' + spaces;
  }
}
コード例 #8
0
ファイル: font.hpp プロジェクト: kalven/arithmetix
 void render(sdl_surface& screen, int x, int y, const std::wstring& text) {
   SDL_Rect dest = {Sint16(x), Sint16(y)};
   for (unsigned i = 0; i != text.size(); ++i) {
     std::map<wchar_t, char_info>::iterator ci = m_chars.find(text[i]);
     if (ci != m_chars.end()) {
       char_info& c = ci->second;
       if (i != 0) {
         // Kerning
         auto ki = m_kern.find(std::make_pair(text[i], text[i - 1]));
         if (ki != m_kern.end()) {
           dest.x += ki->second;
         }
       }
       SDL_Rect glyph_dest = {Sint16(dest.x + c.xoffset),
                              Sint16(dest.y + c.yoffset)};
       SDL_BlitSurface(m_bmp, &c.src, screen, &glyph_dest);
       dest.x += c.xadvance;
     }
   }
 }
コード例 #9
0
ファイル: Assembler.cpp プロジェクト: kabochi/armips
std::wstring checkLabel(std::wstring& str, bool AllLocal)
{
	int pos = 0;

	while (pos < (int)str.size() && str[pos] != ' ' && str[pos] != 0)
	{
		if (str[pos] == ':')
		{
			std::wstring name = str.substr(0,pos);
			if (AllLocal == true && Global.symbolTable.isGlobalSymbol(name))
				name = L"@@" + name;
			
			addAssemblerLabel(name);
			return str.substr(pos+1);
		}
		pos++;
	}

	return str;
}
コード例 #10
0
/*------ マルチバイト文字列 --> ワイド文字文字列 ------*/
void igs::resource::mbs_to_wcs(const std::string &mbs, std::wstring &wcs,
                               const UINT code_page) {
  /* 第4引数で -1 指定により終端文字を含む大きさを返す */
  /*	int MultiByteToWideChar(
                  UINT CodePage
                  ,DWORD dwFlags
                  ,LPCSTR lpMultiByteStr
                  ,int cbMultiByte
                  ,LPWSTR lpWideCharStr
                  ,int cchWideChar
          );
  */
  int length = ::MultiByteToWideChar(code_page, 0, mbs.c_str(), -1, 0, 0);
  if (length <= 1) {
    return;
  } /* 終端以外の文字がないなら何もしない */

  /***	std::vector<wchar_t> buf(length);
  length = ::MultiByteToWideChar(
          code_page ,0 ,mbs.c_str() ,-1
          ,&buf.at(0) ,static_cast<int>(buf.size())
  );***/
  wcs.resize(length);
  length = ::MultiByteToWideChar(code_page, 0, mbs.c_str(), -1,
                                 const_cast<LPWSTR>(wcs.data()),
                                 static_cast<int>(wcs.size()));
  if (0 == length) {
    switch (::GetLastError()) {
    case ERROR_INSUFFICIENT_BUFFER:
      throw std::domain_error("MultiByteToWideChar():insufficient buffer");
    case ERROR_INVALID_FLAGS:
      throw std::domain_error("MultiByteToWideChar():invalid flags");
    case ERROR_INVALID_PARAMETER:
      throw std::domain_error("MultiByteToWideChar():invalid parameter");
    case ERROR_NO_UNICODE_TRANSLATION:
      throw std::domain_error("MultiByteToWideChar():no unicode translation");
    }
  }
  // wcs = std::wstring(buf.begin() ,buf.end()-1); /* 終端以外を */
  wcs.erase(wcs.end() - 1); /* 終端文字を消す。end()は終端より先位置 */
}
コード例 #11
0
ファイル: StdString.cpp プロジェクト: charlessoft/extlib
std::string ws2s( const std::wstring& ws )
{
#ifdef WIN_PLATFORM
	std::string curLocale = setlocale(LC_ALL, NULL);        // curLocale = "C";
	setlocale(LC_ALL, "chs");
	const wchar_t* _Source = ws.c_str();
	size_t _Dsize = 2 * ws.size() + 1;
	char *_Dest = new char[_Dsize];
	memset(_Dest,0,_Dsize);
	wcstombs(_Dest,_Source,_Dsize);
	std::string result = _Dest;
	delete []_Dest;
	setlocale(LC_ALL, curLocale.c_str());
	return result;
#else


	std::string val = "";  
	if(!ws.c_str())  
	{  
		return val;  
	}  
	//size_t size= wcslen(pw)*sizeof(wchar_t);  
	size_t size= ws.length() * sizeof(wchar_t);  
	char *pc = NULL;  
	if ( !(pc = (char*)malloc(size)) )  
	{  
		return val;  
	}  
	size_t destlen = wcstombs(pc,ws.c_str(),size);  
	/*转换不为空时,返回值为-1。如果为空,返回值0*/  
	if ( destlen == (size_t)(0) )  
	{  
		return val;  
	}  
	val = pc;  
	free(pc);  
	return val; 
#endif
 
}
コード例 #12
0
ファイル: Path.cpp プロジェクト: BillyONeal/pevFind
    bool ResolveFromCommandLine(std::wstring &path)
    {
        if (path.empty())
        {
            return false;
        }
        path = Path::ExpandEnvStrings(path);

        if (path[0] == L'\"')
        {
            std::wstring unescaped;
            unescaped.reserve(path.size());
            std::wstring::iterator endOfUnescape = CmdLineToArgvWUnescape(path.begin(), path.end(), std::back_inserter(unescaped));
            if (boost::istarts_with(unescaped, GetRundll32Path()))
            {
                std::wstring::iterator startOfArgument = std::find(endOfUnescape, path.end(), L'\"');
                if (startOfArgument != path.end())
                {
                    unescaped.push_back(L' ');
                    CmdLineToArgvWUnescape(startOfArgument, path.end(), std::back_inserter(unescaped)); // Unescape the argument
                    RundllCheck(unescaped);
                }
            }

            path = unescaped;
            ExpandShortPath(path);
            Prettify(path.begin(), path.end());
            return SystemFacades::File::IsExclusiveFile(path);
        }
        else
        {
            NativePathToWin32Path(path);
            bool status = StripArgumentsFromPath(path);
            if (status)
            {
                ExpandShortPath(path);
                Prettify(path.begin(), path.end());
            }
            return status;
        }
    }
コード例 #13
0
ファイル: UtilOs.cpp プロジェクト: harmy/Desurium
std::wstring getAppInstallPath(std::wstring extra)
{
#ifdef NIX
	#if defined(USE_XDG_DIRS)
		std::string installPath = getenv("XDG_DATA_HOME");
		installPath.append("/desura");
	#elif defined(USE_SINGLE_HOME_DIR)
		std::string installPath = getenv("HOME");
		installPath.append("/.desura/games");
	#elif defined(USE_PORTABLE_DIR)
		std::string installPath = UTIL::STRING::toStr(getCurrentDir(L"games"));
	#endif
	
	if (extra.size() > 0)
		extra.insert(0, DIRS_WSTR);
	
	return UTIL::STRING::toWStr(installPath) + extra;
#else
	#error NOT IMPLEMENTED
#endif
}
コード例 #14
0
ファイル: Util.cpp プロジェクト: lduguid/mangos-tbc
bool WStrToUtf8(const std::wstring& wstr, std::string& utf8str)
{
    try
    {
        std::string utf8str2;
        utf8str2.resize(wstr.size() * 4);                   // allocate for most long case

        auto end = utf8::utf16to8(wstr.cbegin(), wstr.cend(), utf8str2.begin());
        if (end != utf8str2.end())
            utf8str2.erase(end, utf8str2.end());

        utf8str = utf8str2;
    }
    catch (const std::exception&)
    {
        utf8str = "";
        return false;
    }

    return true;
}
コード例 #15
0
ファイル: font.hpp プロジェクト: kalven/arithmetix
  int get_width(const std::wstring& text, unsigned chars = unsigned(-1)) {
    chars = std::min(static_cast<unsigned>(text.size()), chars);

    int width = 0;

    for (unsigned i = 0; i != chars; ++i) {
      std::map<wchar_t, char_info>::iterator ci = m_chars.find(text[i]);
      if (ci != m_chars.end()) {
        char_info& c = ci->second;
        if (i != 0) {
          std::map<kern_pair, int>::iterator ki =
              m_kern.find(std::make_pair(text[i], text[i - 1]));
          if (ki != m_kern.end()) width += ki->second;
        }

        width += c.xadvance;
      }
    }

    return width;
  }
コード例 #16
0
const std::string CNESCsvResult::getStr(const std::wstring & str)
{
    std::vector<wchar_t> buf;
    buf.reserve(str.size() + 2);
    buf.push_back(L'\"');
    for (auto c : str)
    {
        if (c == L'\"')
        {
            buf.push_back(L'\\');
            buf.push_back(L'\"');
        }
        else
        {
            buf.push_back(c);
        }
    }
    buf.push_back(L'\"');

    return scilab::UTF8::toUTF8(std::wstring(buf.begin(), buf.end()));
}
コード例 #17
0
ファイル: utils.cpp プロジェクト: KDE/snoretoast
bool writePipe(const std::filesystem::path &pipe, const std::wstring &data, bool wait)
{
    HANDLE hPipe = CreateFile(pipe.wstring().c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0,
                              nullptr);
    if (hPipe != INVALID_HANDLE_VALUE) {
        DWORD written;
        const DWORD toWrite = static_cast<DWORD>(data.size() * sizeof(wchar_t));
        WriteFile(hPipe, data.c_str(), toWrite, &written, nullptr);
        const bool success = written == toWrite;
        tLog << (success ? L"Wrote: " : L"Failed to write: ") << data << " to " << pipe;
        WriteFile(hPipe, nullptr, sizeof(wchar_t), &written, nullptr);
        CloseHandle(hPipe);
        return success;
    } else if (wait) {
        // wait and retry
        Sleep(20000);
        return writePipe(pipe, data);
    }
    tLog << L"Failed to open pipe: " << pipe << L" data: " << data;
    return false;
}
コード例 #18
0
ファイル: UtilOs.cpp プロジェクト: Alasaad/Desurium
std::wstring getCommonProgramFilesPath(std::wstring extra)
{
#ifdef WIN32
	wchar_t path[MAX_PATH];
	getSystemPath(CSIDL_PROGRAM_FILES_COMMON, path);
	
	std::wstring out(path);

	out += L"\\Desura";

	if (extra.size() > 0)
	{
		out += L"\\";
		out += extra;
	}

	return out;
#else //TODO LINUX
	return L"";
#endif
}
コード例 #19
0
ファイル: process.cpp プロジェクト: benny5609/YDWE
	bool process::create(const std::wstring& command_line)	
	{
		if (statue_ == PROCESS_STATUE_READY)
		{
			if (command_line.empty())
			{
				if (!detail::create_process(
					nullptr, 
					nullptr, 
					NORMAL_PRIORITY_CLASS, 
					nullptr, 
					&si_, &pi_, inject_dll_
					))
				{
					return false;
				}
			}
			else
			{
				std::dynarray<wchar_t> command_line_buffer(command_line.size()+1);
				wcscpy_s(command_line_buffer.data(), command_line_buffer.size(), command_line.c_str());

				if (!detail::create_process(
					nullptr, 
					command_line_buffer.data(), 
					NORMAL_PRIORITY_CLASS, 
					nullptr, 
					&si_, &pi_, inject_dll_
					))
				{
					return false;
				}
			}

			statue_ = PROCESS_STATUE_RUNNING;
			return true;
		}

		return false;
	}
コード例 #20
0
    void VerifyParse(const std::wstring& refToParse, const vector<wstring>& expectedResults)
    {
        const wchar_t *pStart = refToParse.c_str();
        const wchar_t *pEnd = pStart + refToParse.size();

        vector<wstring> actualResults;
        bool parseSucceeded = lex::tokenize_and_phrase_parse(pStart, pEnd, g_lexer, g_parser, g_skipper, actualResults);
        if(!parseSucceeded)
        {
            wcout << L"Parsing failed with '" << refToParse << L"'." << endl;
        }
        BOOST_CHECK( parseSucceeded );

        const bool resultCountMatchesExpectedCount = (expectedResults.size() == actualResults.size());
        if(!resultCountMatchesExpectedCount)
        {
            wcout << L"Different number of results than expected." << endl << endl << L"Expected:" << endl;
            copy(expectedResults.begin(), expectedResults.end(), ostream_iterator<wstring, wchar_t>(wcout, L"\n"));

            wcout << endl << endl << L"Actual:" << endl;
            copy(actualResults.begin(), actualResults.end(), ostream_iterator<wstring, wchar_t>(wcout, L"\n"));
        }
        BOOST_CHECK( resultCountMatchesExpectedCount );

        //avoid annoying signed/unsigned mismatch or relying on the fact that ::size_type is == size_t
        typedef decltype(actualResults.size()) IndexType;

        for(IndexType i = 0 ; i < actualResults.size() ; ++i)
        {
            auto actual = actualResults[i];
            auto expected = expectedResults[i];

            const bool areEqual = (actual == expected);
            if(!areEqual)
            {
                wcout << L"Expected '" << expected << L"', but got '" << actual << L"'." << endl;
            }
            BOOST_CHECK( areEqual );
        }
    }
コード例 #21
0
ファイル: TTSEvents.cpp プロジェクト: itsyash/MS-SAPI-demo
void OnSpeechEvent() {

	SPEVENT event;
	while (S_OK == cpVoice->GetEvents(1, &event, NULL)) {
		if (event.ulStreamNum != stream_number_)
			continue;

		switch (event.eEventId) {
		case SPEI_START_INPUT_STREAM:
			std::cout << "SPEI_START_INPUT_STREAM" << endl;
			break;
		case SPEI_END_INPUT_STREAM:
			char_position_ = utterance_.size();
			std::cout << "SPEI_END_INPUT_STREAM " << char_position_ << endl;
			break;
		case SPEI_TTS_BOOKMARK:

			break;
		case SPEI_WORD_BOUNDARY:
			char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
			std::cout << "SPEI_WORD_BOUNDARY" << endl;
			SPVOICESTATUS eventStatus;
			cpVoice->GetStatus(&eventStatus, NULL);
			ULONG start, end;
			start = eventStatus.ulInputWordPos;
			end = eventStatus.ulInputWordLen;
			std::cout << "start " << start << "  end " << start + end - 1 << "  status " << eventStatus.dwRunningState << endl;
			break;
		case SPEI_SENTENCE_BOUNDARY:
			char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
			std::cout << "SPEI_SENTENCE_BOUNDARY" << endl;
			cpVoice->GetStatus(&eventStatus, NULL);
			start = eventStatus.ulInputSentPos;
			end = eventStatus.ulInputSentLen;
			std::cout << "start " << start << "  end " << start + end - 1 << "  status " << eventStatus.dwRunningState << endl;
			break;
		}
	}
}
コード例 #22
0
	void GetPublicDocuments(std::wstring& out_PublicDocumentsPath)
			throw (isis::application_exception)
	{
		//need a wchar_t* because that's what SHGetKnownFolderPath takes
		wchar_t* path = 0;
		SHGetKnownFolderPath(FOLDERID_PublicDocuments, 0, NULL, &path);
		//need wstringstream to convert to wstring
		std::wstringstream stream;
		stream << path;
		//need this to clean up memory for wchar_t*
		::CoTaskMemFree(static_cast<void*>(path));
		//populate output parameter
		out_PublicDocumentsPath = stream.str();

		if ( out_PublicDocumentsPath.size() == 0 )
		{
			std::stringstream errorString;
			errorString <<
				"Function - GetPublicDocuments, did not find the public document folder.";
			throw isis::application_exception(errorString.str());		
		}
	}
コード例 #23
0
void CCandidateWindow::_SetText(const std::wstring &text, BOOL fixed, BOOL showcandlist, BOOL showreg)
{
	//CTextService -> CCandidateList -> CCandidateWindow で入力文字列をもらう

	if(_pCandidateWindow != NULL && !_preEnd)
	{
		_pCandidateWindow->_SetText(text, fixed, showcandlist, showreg);
		return;
	}

	if(showreg)
	{
		_CreateNext(TRUE);
	}

	if(showcandlist)
	{
		_CreateNext(FALSE);
	}

	regwordfixed = fixed;

	if(fixed)
	{
		comptext.clear();
		regwordtext.insert(regwordtextpos, text);
		regwordtextpos += text.size();
	}
	else
	{
		comptext = text;
		if(comptext.empty())
		{
			regwordfixed = TRUE;
		}
	}

	_Update();
}
コード例 #24
0
ファイル: ArmParser.cpp プロジェクト: ketlerd/armips
bool ArmParser::decodeAddressingMode(const std::wstring& text, size_t& pos, unsigned char& dest)
{
    if (pos+2 > text.size())
        return false;

    wchar_t c1 = text[pos+0];
    wchar_t c2 = text[pos+1];

    if      (c1 == 'i' && c2 == 'b') dest = ARM_AMODE_IB;
    else if (c1 == 'i' && c2 == 'a') dest = ARM_AMODE_IA;
    else if (c1 == 'd' && c2 == 'b') dest = ARM_AMODE_DB;
    else if (c1 == 'd' && c2 == 'a') dest = ARM_AMODE_DA;
    else if (c1 == 'e' && c2 == 'd') dest = ARM_AMODE_ED;
    else if (c1 == 'f' && c2 == 'd') dest = ARM_AMODE_FD;
    else if (c1 == 'e' && c2 == 'a') dest = ARM_AMODE_EA;
    else if (c1 == 'f' && c2 == 'a') dest = ARM_AMODE_FA;
    else
        return false;

    pos += 2;
    return true;
}
コード例 #25
0
ファイル: UtilOs.cpp プロジェクト: Alasaad/Desurium
std::wstring getTempInternetPath(std::wstring extra)
{
#ifdef WIN32
	wchar_t path[MAX_PATH];
	getSystemPath(CSIDL_INTERNET_CACHE, path);
	
	std::wstring out(path);

	out += L"\\";
	out += COMMONAPP_PATH_W;

	if (extra.size() > 0)
	{
		out += L"\\";
		out += extra;
	}

	return out;
#else //TODO LINUX
	return L"";
#endif
}
コード例 #26
0
ファイル: UtilOs.cpp プロジェクト: Alasaad/Desurium
std::wstring getLocalAppDataPath(std::wstring extra)
{
#ifdef WIN32
	wchar_t path[MAX_PATH];
	getSystemPath(CSIDL_LOCAL_APPDATA, path);
	
	std::wstring out(path);

	out += L"\\";
	out += COMMONAPP_PATH_W;

	if (extra.size() > 0)
	{
		out += L"\\";
		out += extra;
	}

	return out;
#else //TODO LINUX
	return L"";
#endif
}
コード例 #27
0
ファイル: UtilOs.cpp プロジェクト: Alasaad/Desurium
std::wstring getCachePath(std::wstring extra)
{
#ifdef NIX
	#if defined(USE_XDG_DIRS)
		std::string cachePath = getenv("XDG_CACHE_HOME");
		cachePath.append("/desura");
	#elif defined(USE_SINGLE_HOME_DIR)
		std::string cachePath = getenv("HOME");
		cachePath.append("/.desura/cache");
	#elif defined(USE_PORTABLE_DIR)
		std::string cachePath = UTIL::STRING::toStr(getCurrentDir(L"cache"));
	#endif
	
	if (extra.size() > 0)
		extra.insert(0, DIRS_WSTR);
	
	return UTIL::STRING::toWStr(cachePath) + extra;
#else
	return L"";
//	#error NOT IMPLEMENTED
#endif
}
コード例 #28
0
ファイル: Cx_TextUtil.cpp プロジェクト: thinkhy/x3c_extension
bool Cx_TextUtil::GetFileContent(std::wstring& content, BYTE* buf, long size, UINT codepage)
{
	bool bRet = true;

	if (0xFF == buf[0] && 0xFE == buf[1])	// UTF-16 (little-endian)
	{
		content.resize((size - 2) / 2);
		memcpy((LPVOID)content.c_str(), buf + 2, content.size() * sizeof(WCHAR));
	}
	else			// ANSI/ASCII
	{
		bRet = (buf[0] != 0xFE || buf[0] != 0xFF);

		if (size > 3 && (0xEF == buf[0] && 0xBB == buf[1] && 0xBF == buf[2]))
		{
			codepage = CP_UTF8;
		}
		content = std::a2w((LPCSTR)buf, codepage);
	}

	return bRet;
}
コード例 #29
0
// サブテキストの初期化(テキストフォーマット、テキストレイアウト、テキストメトリックス)
HRESULT ui::UIListBoxItem::__InitializeSubText(graphics::D3DInteropHelper *pD3DInteropHelper, const std::wstring &text,
                                               const graphics::FontAttribute &fontAttribute,
                                               CComPtr<IDWriteTextFormat> &textFormat,
                                               CComPtr<IDWriteTextLayout> &textLayout, DWRITE_TEXT_METRICS &textMetrics,
                                               UIRectangle &textRect) {
#ifdef DEBUG_UILISTBOXITEM
  LOG_ENTER(SEVERITY_LEVEL_DEBUG);
#endif

  // text format
  textFormat = nullptr;
  CHK_FATAL_HRESULT(pD3DInteropHelper->GetDWriteFactory()->CreateTextFormat(
      fontAttribute.fontFamilyName.c_str(), nullptr, fontAttribute.GetFontWeight(), fontAttribute.GetFontStyle(),
      fontAttribute.GetFontStretch(), fontAttribute.fontSize, L"", &textFormat));

  textRect.width = m_textLayoutRect.width;

  // text layout
  textLayout = nullptr;
  CHK_FATAL_HRESULT(pD3DInteropHelper->GetDWriteFactory()->CreateTextLayout(
      text.c_str(), static_cast<UINT>(text.size()), textFormat, m_preferredTextAreaSize.width,
      std::numeric_limits<FLOAT>::max(), &textLayout));

  // trimming sign
  CComPtr<IDWriteInlineObject> inlineObject;
  CHK_FATAL_HRESULT(pD3DInteropHelper->GetDWriteFactory()->CreateEllipsisTrimmingSign(textLayout, &inlineObject));
  DWRITE_TRIMMING trimming = {DWRITE_TRIMMING_GRANULARITY_CHARACTER, 0, 0};
  textLayout->SetTrimming(&trimming, inlineObject);
  textLayout->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);

  // text metrics
  CHK_FATAL_HRESULT(textLayout->GetMetrics(&textMetrics));

#ifdef DEBUG_UILISTBOXITEM
  graphics::DirectWriteUtil::DumpMetrics(SEVERITY_LEVEL_DEBUG, L"m_subTextLayout", textLayout);
  LOG_LEAVE(SEVERITY_LEVEL_DEBUG);
#endif
  return S_OK;
}
コード例 #30
0
ファイル: custom_hud.cpp プロジェクト: killbug2004/Frozlunky
void CustomHudPatch::set_text(const std::wstring& text) 
{
	if(!is_valid)
		return;

	size_t text_len = text.size()*sizeof(wchar_t);
	if(text_len > allocated_size) 
	{
		bool reinitiate = false;
		if(this->is_active()) {
			this->_undo();
			reinitiate = true;
		}
		
		size_t target = (size_t)std::pow(2, 1 + (int)(std::log(text_len)/std::log(2)));
		
		spel->release(allocated);
		allocated = NULL; allocated_size = 0;
		
		allocated = spel->allocate(target);
		if(allocated == NULL) {
			is_valid = false;
			return;
		}
		allocated_size = target;

#ifdef DEBUG_MODE
		std::cout << "Reallocated string space at " << allocated << std::endl;
#endif

		if(reinitiate) {
			this->_perform();
		}
	}

	wchar_t end_bytes = 0;
	spel->write_mem(allocated, text.c_str(), text_len);
	spel->write_mem(allocated+text_len, &end_bytes, sizeof(wchar_t));
}