Esempio n. 1
0
string
IceUtil::wstringToString(const wstring& v, const StringConverterPtr& converter, const WstringConverterPtr& wConverter)
{
    string target;
    if(!v.empty())
    {
        const WstringConverterPtr& wConverterWithDefault = wConverter ? wConverter : getUnicodeWstringConverter();

        //
        // First convert to UTF-8 narrow string.
        //
        UTF8BufferI buffer;
        Byte* last = wConverterWithDefault->toUTF8(v.data(), v.data() + v.size(), buffer);
        buffer.swap(target, last);

        //
        // If narrow string converter is present convert to the native narrow string encoding, otherwise
        // native narrow string encoding is UTF8 and we are done.
        //
        if(converter)
        {
            string tmp;
            converter->fromUTF8(reinterpret_cast<const Byte*>(target.data()),
                                reinterpret_cast<const Byte*>(target.data() + target.size()), tmp);
            tmp.swap(target);
        }
    }
    return target;
}
Esempio n. 2
0
string
IceUtil::wstringToString(const wstring& v, const StringConverterPtr& converter, const WstringConverterPtr& wConverter,
                         IceUtil::ConversionFlags flags)
{
    string target;
    if(!v.empty())
    {
        //
        // First convert to UTF8 narrow string.
        //
        if(wConverter)
        {
            UTF8BufferI buffer;
            Byte* last = wConverter->toUTF8(v.data(), v.data() + v.size(), buffer);
            target = string(reinterpret_cast<const char*>(buffer.getBuffer()), last - buffer.getBuffer());
        }
        else
        {
            size_t size = v.size() * 4 * sizeof(char);

            Byte* outBuf = new Byte[size];
            Byte* targetStart = outBuf; 
            Byte* targetEnd = outBuf + size;

            const wchar_t* sourceStart = v.data();
  
            ConversionResult cr = 
                convertUTFWstringToUTF8(
                    sourceStart, sourceStart + v.size(), 
                    targetStart, targetEnd, flags);
                
            if(cr != conversionOK)
            {
                delete[] outBuf;
                assert(cr == sourceExhausted || cr == sourceIllegal);
                throw IllegalConversionException(__FILE__, __LINE__, 
                                                 cr == sourceExhausted ? "partial character" : "bad encoding");
            }
            
            target = string(reinterpret_cast<char*>(outBuf), static_cast<size_t>(targetStart - outBuf));
            delete[] outBuf;
        }

        //
        // If narrow string converter is present convert to the native narrow string encoding, otherwise 
        // native narrow string encoding is UTF8 and we are done.
        //
        if(converter)
        {
            string tmp;
            converter->fromUTF8(reinterpret_cast<const Byte*>(target.data()), 
                                reinterpret_cast<const Byte*>(target.data() + target.size()), tmp);
            tmp.swap(target);
        }
    }
    return target;
}
Esempio n. 3
0
string unicode_to_ansi(const wstring& str, unsigned code_page) {
  unsigned str_size = static_cast<unsigned>(str.size());
  if (str_size == 0)
    return string();
  int size = WideCharToMultiByte(code_page, 0, str.data(), str_size, nullptr, 0, nullptr, nullptr);
  Buffer<char> out(size);
  size = WideCharToMultiByte(code_page, 0, str.data(), str_size, out.data(), size, nullptr, nullptr);
  CHECK_SYS(size);
  return string(out.data(), size);
}
Esempio n. 4
0
		ObjectInstance::ObjectInstance(ApplicationDomain* applicationDomain, const wstring assemblyName, const wstring className)
		{
			HRESULT hr = applicationDomain->GetHandle()->CreateInstance(
						_bstr_t(assemblyName.data()),
						_bstr_t(className.data()),
						&this->objectHandle); 

			if (!SUCCEEDED(hr))
			{
				throw new RuntimeHostException("Unable to create the object instance");
			}
		}
//---------------------------------------------------------------------------
int TTaskScheduler::AddNewScheduledTask(wstring taskName){

    /////////////////////////////////////////////////////////////////
    // Call ITaskScheduler::NewWorkItem to create new task.
    /////////////////////////////////////////////////////////////////
    ITask *pITask;



    HRESULT hr = pITS->NewWorkItem(taskName.data(),           // Name of task
                         CLSID_CTask,            // Class identifier
                         IID_ITask,              // Interface identifier
                         (IUnknown**)&pITask); // Address of task interface



    if (FAILED(hr)){
        sprintf(lastError, "Failed calling NewWorkItem, error = 0x%x\n",hr);
        return 0;
    }


    Save(pITask);

    pITask->Release();
    return 1;

    
}
Esempio n. 6
0
UInt32 Archive::find_dir(const wstring& path) {
  if (file_list.empty())
    make_index();

  ArcFileInfo dir_info;
  dir_info.is_dir = true;
  dir_info.parent = c_root_index;
  size_t begin_pos = 0;
  while (begin_pos < path.size()) {
    size_t end_pos = begin_pos;
    while (end_pos < path.size() && !is_slash(path[end_pos])) end_pos++;
    if (end_pos != begin_pos) {
      dir_info.name.assign(path.data() + begin_pos, end_pos - begin_pos);
      FileIndexRange fi_range = equal_range(file_list_index.begin(), file_list_index.end(), -1, [&] (UInt32 left, UInt32 right) -> bool {
        const ArcFileInfo& fi_left = left == -1 ? dir_info : file_list[left];
        const ArcFileInfo& fi_right = right == -1 ? dir_info : file_list[right];
        return fi_left < fi_right;
      });
      if (fi_range.first == fi_range.second)
        FAIL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND));
      dir_info.parent = *fi_range.first;
    }
    begin_pos = end_pos + 1;
  }
  return dir_info.parent;
}
Esempio n. 7
0
wstring word_wrap(const wstring& str, wstring::size_type wrap_bound) {
  wstring result;
  wstring::size_type begin_pos = 0;
  while (begin_pos < str.size()) {
    wstring::size_type end_pos = begin_pos + wrap_bound;
    if (end_pos < str.size()) {
      for (wstring::size_type i = end_pos; i > begin_pos; i--) {
        if (str[i - 1] == L' ') {
          end_pos = i;
          break;
        }
      }
    }
    else {
      end_pos = str.size();
    }
    wstring::size_type trim_pos = end_pos;
    while (trim_pos > begin_pos && str[trim_pos - 1] == L' ') trim_pos--;
    if (trim_pos > begin_pos) {
      if (!result.empty())
        result.append(1, L'\n');
      result.append(str.data() + begin_pos, trim_pos - begin_pos);
    }
    begin_pos = end_pos;
  }
  return result;
}
Esempio n. 8
0
std::string ConvertWstringToCodepage( wstring s, int iCodePage )
{
	if( s.empty() )
		return std::string();

	int iBytes = WideCharToMultiByte( iCodePage, 0, s.data(), s.size(), 
					nullptr, 0, nullptr, FALSE );
	ASSERT_M( iBytes > 0, werr_format( GetLastError(), "WideCharToMultiByte" ).c_str() );

	char * buf = new char[iBytes + 1];
	std::fill(buf, buf + iBytes + 1, '\0');
	WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(), buf, iBytes, nullptr, FALSE );
	std::string ret( buf );
	delete[] buf;
	return ret;
}
Esempio n. 9
0
bool substr_match(const wstring& str, wstring::size_type pos, wstring::const_pointer mstr) {
  size_t mstr_len = wcslen(mstr);
  if ((pos > str.length()) || (pos + mstr_len > str.length())) {
    return false;
  }
  return wmemcmp(str.data() + pos, mstr, mstr_len) == 0;
}
Esempio n. 10
0
CString ConvertWstringToACP( wstring s )
{
	if( s.empty() )
		return "";

	int iBytes = WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(), 
					NULL, 0, NULL, FALSE );
	ASSERT_M( iBytes > 0, werr_ssprintf( GetLastError(), "WideCharToMultiByte" ).c_str() );

	CString ret;
	WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(), 
					ret.GetBuf( iBytes ), iBytes, NULL, FALSE );
	ret.RelBuf( iBytes );

	return ret;
}
Esempio n. 11
0
RString ConvertWstringToCodepage( wstring s, int iCodePage )
{
	if( s.empty() )
		return RString();

	int iBytes = WideCharToMultiByte( iCodePage, 0, s.data(), s.size(), 
					NULL, 0, NULL, FALSE );
	ASSERT_M( iBytes > 0, werr_ssprintf( GetLastError(), "WideCharToMultiByte" ).c_str() );

	char * buf = new char[iBytes];
	WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(), 
					buf, iBytes, NULL, FALSE );
	RString ret( buf );
	delete[] buf;
	return ret;
}
Esempio n. 12
0
	void CCilDisasm::dumpLabel( wstring& str )
	{
		//32 chars
		str.append( L":" );
		swprintf_s( m_wstrBuffer, ARRAYSIZE( m_wstrBuffer ), L"%-32s", str.data() );
		wcout << m_wstrBuffer;
	}
int TTaskScheduler::DeleteTask(wstring taskName){
    HRESULT hr = pITS->Delete(taskName.data());
    if(hr == S_OK){
        return 1;
    }
    sprintf(lastError, "Unable to delete a task, error = 0x%x\n",hr);
    return 0;
}
Esempio n. 14
0
void DocumentIconFinder::useIconFromFile(const wstring& iconFile)
{
	TCHAR buffer[MAX_PATH];
	throwOnFailure<OleException>(
		StringCchCopy(buffer, MAX_PATH, iconFile.data()));
	m_iconIndex = PathParseIconLocation(buffer);
	m_iconFile = buffer;
}
Esempio n. 15
0
		VARIANT ObjectInstance::Execute(const wstring methodName, DISPPARAMS inputParameters)
		{
			if (this->objectHandle == NULL)
			{
				throw new RuntimeHostException("ObjectHandle is no longer valid");
			}

			VARIANT v;
			DISPID	dispid;
			LPOLESTR szMethodName = _bstr_t(methodName.data());
			VARIANT result;
			EXCEPINFO pExcepInfo;
			unsigned int puArgErr = 0;
			
			// Initialze the variants
			VariantInit(&v);
			VariantInit(&result);
					
			HRESULT hr = this->objectHandle->Unwrap(&v);
			if (!SUCCEEDED(hr))
			{
				throw new RuntimeHostException("Unable to retrieve method information");
			}

			// The .NET Component should expose IDispatch
			IDispatch* pdispatch = v.pdispVal;				

			// Retrieve the DISPID
			hr = pdispatch->GetIDsOfNames(
								IID_NULL,
								&szMethodName,
								1,
								LOCALE_SYSTEM_DEFAULT,
								&dispid);
			if (!SUCCEEDED(hr))
			{
				throw new RuntimeHostException("Unable to retrieve method information");
			}

			// Invoke the method on the IDispatch Interface
			hr = pdispatch->Invoke(
							dispid,
							IID_NULL,
							LOCALE_SYSTEM_DEFAULT,
							DISPATCH_METHOD,
							&inputParameters,
							&result,
							&pExcepInfo,
							&puArgErr);

			if (!SUCCEEDED(hr))
			{
				throw new RuntimeHostException("Error on method execution");
			}

			return result;
		}
Esempio n. 16
0
int WriteFileLogf(wstring fmt, ...) {
	wchar_t szBuf[2048] = L"";
	va_list args;
	va_start(args, fmt);
	_snwprintf_s(szBuf, 2048, 2048, fmt.data(), args);
	WriteFileLog(*defaultlog, wstring(szBuf));
	va_end(args);
	return 0;
}
Esempio n. 17
0
			// 根据文件名获取文件所在路径
			wstring GetFilePath(wstring appDefFile){
				const int BUFSIZE = 4096;
				TCHAR  buffer[BUFSIZE] = TEXT("");
				GetFullPathName(LPCWSTR(appDefFile.data()), BUFSIZE, buffer, NULL);// 获取文件的绝对路径
				wstring pp(buffer);
				int p = pp.find_last_of('\\');
				if (p != -1)pp = pp.substr(0, p + 1);
				return pp;
			}
bool UninstallerShortcutsListbox::contains(const wstring& file) const
{
	for (const wstring& f : m_files)
	{
		if (_tcsicmp(f.data(), file.data()) == 0)
			return true;
	}
	return false;
}
Esempio n. 19
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// –азобрать выбор в меню:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
    case WM_KEYDOWN:
        // провер¤ем не нажаты ли виртуальные клавиши
        if(GetKeyState(VK_CONTROL)& 0x8000)
        {            
            SetWindowText(hWnd, TEXT(" лавиша ctrl нажата"));
        }
        if(GetKeyState(VK_SHIFT)& 0x8000)
        {            
            SetWindowText(hWnd, TEXT(" лавиша shift нажата"));
        }
        
        break;
    case WM_CHAR:
        buff += TCHAR(wParam);
        break;
    case WM_KEYUP:
        SetWindowText(hWnd, TEXT(""));
        InvalidateRect(hWnd, NULL, true);
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: добавьте любой код отрисовки...
        TextOut(hdc, 0, 0, buff.data(), buff.size());
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Esempio n. 20
0
void
GUID2String( const GUID &guid, wstring &str )
{
	str.resize( 36 );

	swprintf_s( (wchar_t*)str.data(), 37, _T("%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"),
				guid.Data1, guid.Data2, guid.Data3,
				guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
				guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] );
}
void UninstallerShortcutsListbox::erase(const wstring& file)
{
	for (auto pItem = m_files.begin(); pItem < m_files.end(); ++pItem)
	{
		if (_tcsicmp(pItem->data(), file.data()) == 0)
		{
			m_files.erase(pItem);
			return;
		}
	}
}
Esempio n. 22
0
wstring ConnectedShortcut::disconnectFileName(const wstring& shortcutName)
{
	const wstring suffix = L" + " SHORT_APP_NAME L".lnk";
	if (PathMatchSpec(shortcutName.data(), (L"*" + suffix).data()) == FALSE)
		return shortcutName;

	wstring newName = shortcutName;
	newName.erase(newName.length() - suffix.length());
	newName.append(L".lnk");
	return newName;
}
Esempio n. 23
0
//可同时处理目录和文件:path可以是路径,也可以是文件名,或者文件通配符
wstring find(wstring path,bool cursive)
{ 
     //取路径名最后一个"//"之前的部分,包括"//"
	replace_allW(path,L"\\",L"/");
	UINT index=path.find_last_of('/');
	if(index+1==path.length()){
		path.append(L"*.*");
	}
    wstring prefix=path.substr(0,path.find_last_of('/')+1);

    WIN32_FIND_DATA FindFileData;
    HANDLE hFind=::FindFirstFile(path.data(),&FindFileData);
	std::wstringstream ss;
    if(INVALID_HANDLE_VALUE == hFind)
    {
       ss<<L"[]";
	   FindClose(hFind);
	   return ss.str();
    }
	else{
		ss<<L"[";
	}
    while(TRUE)
    {
		bool flag=false;;
      //目录
        if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            //不是当前目录,也不是父目录
            if(cursive&&FindFileData.cFileName[0]!='.')
            {
				wstring temp=prefix+FindFileData.cFileName;
				ss<<L"{\"name\":\""<<FindFileData.cFileName<<L"\",\"list\":"<<find(temp+L"/*.*",cursive).data()<<L"}";
				flag=true;
            }
        }
        //文件
        else
        {   
             ss<<L"\""<<FindFileData.cFileName<<L"\"";
			flag=true;
        }
        if(!FindNextFile(hFind,&FindFileData))
              break;
		else if(flag){
			ss<<L",";
		}
    }
	ss<<L"]";
    FindClose(hFind);
	return ss.str();
}
Esempio n. 24
0
static bool isStartWithStringW(const wstring &str,const wstring &head,bool bIgnoreCase)
{
    PCWSTR pCheck = str.data();
    PCWSTR pHead = head.data();
    size_t len = head.length();
    if (str.length() < len)
    {
        return false;
    }
    if (bIgnoreCase)
    {
		for (size_t i = 0; i<len; ++i)
        {
            if (pCheck[i]<128 && pHead[i]<128)
            {
                if (_mapCaseTable[pCheck[i]] != _mapCaseTable[pHead[i]])
                {
                    return false;
                }
            }
            else if (pCheck[i] != pHead[i])
            {
                return false;
            }
        }
    }
    else
    {
		for (size_t i = 0; i<len; ++i)
        {
            if (pCheck[i] != pHead[i])
            {
                return false;
            }
        }
    }
    return true;
}
Esempio n. 25
0
bool ConnectedShortcut::isConnected(const wstring& filePath)
{
	// Shortcut: Don't try non-link files.
	if (PathMatchSpec(filePath.data(), L"*.lnk") == FALSE)
		return false;
	try {
		ConnectedShortcut csc;
		csc.load(filePath, STGM_READ);
		return csc.isConnected();
	}
	catch (std::exception&) {
		return false;
	}
}
Esempio n. 26
0
int wstring::compare(const wstring& str, size_t pos, size_t n) const {
    if (pos > length())
        throw out_of_range("pos > length()");
    size_t rlen = length() - pos;
    if (rlen > n)
        rlen = n;
    if (rlen > str.length())
        rlen = str.length();
    int r = wchar_traits::compare(data() + pos, str.data(), rlen);
    if (r != 0)
        return r;
    if (rlen == n)
        return 0;
    return(length() - pos) - str.length();
}
Esempio n. 27
0
string
WONCommon::WStringToString(const wstring& theStr)
{
	size_t aCopySize = theStr.size();
	if (!aCopySize)
		return string();
		
	char* aBuf = new char[aCopySize + 1];
	WideToAscii(aBuf, theStr.data(), aCopySize);
	aBuf[aCopySize] = 0;
	string  aRet(aBuf);

	delete[] aBuf;
	return aRet;
}
Esempio n. 28
0
void WONCommon::WStringToString(const wstring& src, string& dst)
{
	size_t aStrSize = src.size();
	if (!aStrSize)
		dst.erase();
	else
	{
		char* aBuf = new char[aStrSize + 1];
		WideToAscii(aBuf, src.data(), aStrSize);
		aBuf[aStrSize] = 0;
		dst = aBuf;

		delete[] aBuf;
	}
}
Esempio n. 29
0
void  CLog::addstr(wstring str)
{
	string  temp;
	char buf[100];
	char  out[200];
	memset(out, 0, sizeof(out));
	MYUTIL()->cnv_outchar(str.data(), out, 200);


	MYUTIL()->getcurtime(buf, 100, 1);
	temp = buf;
	temp += out;

	m_strlist.push_back(temp);
}
Esempio n. 30
0
bool appendComponentToPath(wstring& path, const wstring& component)
{
    WCHAR buffer[MAX_PATH];

    if (path.size() + 1 > MAX_PATH)
        return false;

    memcpy(buffer, path.data(), path.size() * sizeof(WCHAR));
    buffer[path.size()] = '\0';

    if (!PathAppendW(buffer, component.c_str()))
        return false;

    path = wstring(buffer);
    return true;
}