Exemple #1
0
string IRI::IRIString() const
{
    if ( !_pureIRI.empty() )
        return _pureIRI;
    
    if ( !_url )
        return string::EmptyString;
    
    // we'll have to reverse-engineer it, grr
    string uri(URIString());
    std::string plainHost(_url->host());
    
    url_canon::RawCanonOutputW<256> idnDecoded;
    const string16 idnSrc = string(plainHost).utf16string();
    if ( url_canon::IDNToUnicode(idnSrc.c_str(), static_cast<int>(idnSrc.size()), &idnDecoded) && idnSrc != idnDecoded.data() )
    {
        // swap out the IDN-encoded hostname
        string::size_type pos = uri.find(plainHost);
        if ( pos != string::npos )
        {
            uri.replace(pos, plainHost.size(), idnDecoded.data());
        }
    }
    
    // have to leave it all url-encoded, sadly...
    return uri;
}
bool EqualsASCII(const string16& a, const base::StringPiece& b)
{
    if(a.length() != b.length())
    {
        return false;
    }
    return std::equal(b.begin(), b.end(), a.begin());
}
Exemple #3
0
string IRI::IDNEncodeHostname(const string& str)
{
    url_canon::RawCanonOutputW<256> output;
    const string16 src = str.utf16string();
    if ( url_canon::IDNToASCII(src.c_str(), static_cast<int>(src.size()), &output) )
        return output.data();
    return string::EmptyString;
}
Exemple #4
0
bool Pickle::WriteString16(const string16& value)
{
    if(!WriteInt(static_cast<int>(value.size())))
    {
        return false;
    }

    return WriteBytes(value.data(),
        static_cast<int>(value.size())*sizeof(char16));
}
bool ContainsOnlyWhitespace(const string16& str)
{
    for(string16::const_iterator i=str.begin(); i!=str.end(); ++i)
    {
        if(!IsWhitespace(*i))
        {
            return false;
        }
    }
    return true;
}
void DemoTextfiled::ContentsChanged(view::Textfield* sender,
                                    const string16& new_contents)
{
    if(sender == name_)
    {
        PrintStatus(base::StringPrintf(L"Name [%ls]", new_contents.c_str()));
    }
    else if(sender == password_)
    {
        PrintStatus(base::StringPrintf(L"Password [%ls]",new_contents.c_str()));
    }
}
Exemple #7
0
ZQ<Val> KeyRef::QGet(const string16& iName) const
	{
	if (iName.empty())
		return null;

	if (iName[0] != '!')
		{
		KeyRef subKey;
		if (ERROR_SUCCESS == ::RegOpenKeyExW(
			*this,
			iName.c_str(),
			0, // ulOptions
			KEY_ALL_ACCESS,
			&subKey.OParam()))
			{ return subKey; }
		else if (ERROR_SUCCESS == ::RegOpenKeyExW(
			*this,
			iName.c_str(),
			0, // ulOptions
			KEY_READ,
			&subKey.OParam()))
			{ return subKey; }
		return null;
		}

	DWORD curLength = 1024;
	for (;;)
		{
		DWORD type;
		vector<BYTE> bufferVec(curLength);
		DWORD length = curLength;
		LONG result = ::RegQueryValueExW(
			*this,
			&iName.c_str()[1],
			nullptr, // lpReserved
			&type,
			&bufferVec[0],
			&length);

		if (ERROR_SUCCESS == result)
			return spQGet(type, &bufferVec[0], length);

		if (ERROR_MORE_DATA == result)
			{
			// If we're hitting HKEY_PERFORMANCE_DATA then the value of length is not
			// useful, the next call may need more space. So we just double curLength.
			curLength *= 2;
			continue;
			}

		return null;
		}
	}
 void NativeTextfieldWin::AppendText(const string16& text)
 {
     int text_length = GetWindowTextLength();
     ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length));
     ::SendMessage(m_hWnd, EM_REPLACESEL, false,
         reinterpret_cast<LPARAM>(text.c_str()));
 }
Exemple #9
0
 // Show the Windows "Open With" dialog box to ask the user to pick an app to
 // open the file with.
 bool OpenItemWithExternalApp(const string16& full_path)
 {
     SHELLEXECUTEINFO sei = { sizeof(sei) };
     sei.fMask = SEE_MASK_FLAG_DDEWAIT;
     sei.nShow = SW_SHOWNORMAL;
     sei.lpVerb = L"openas";
     sei.lpFile = full_path.c_str();
     return (TRUE == ::ShellExecuteExW(&sei));
 }
Exemple #10
0
    bool AdjustStringForLocaleDirection(const string16& text,
        string16* localized_text)
    {
        if(!IsRTL() || text.empty())
        {
            return false;
        }

        // TODO: 根据IsRTL()实际值进行处理.
        *localized_text = text;
        return true;
    }
Exemple #11
0
bool ZTextCollatorRep_ICU::Equals(const string16& iLeft, const string16& iRight)
	{
	if (iLeft.empty())
		return iRight.empty();

	if (iRight.empty())
		return false;

	return UCOL_EQUAL == ::ucol_strcoll(fCollator, iLeft.data(), iLeft.size(),
		iRight.data(), iRight.size());
	}
Exemple #12
0
bool ZTextCollatorRep_ICU::Contains(const string16& iPattern, const string16& iTarget)
	{
	if (iPattern.empty())
		return true;

	if (iTarget.empty())
		return false;

	return spContains(fCollator, iPattern.data(), iPattern.size(), iTarget.data(), iTarget.size());
	}
Exemple #13
0
int ZTextCollatorRep_ICU::Compare(const string16& iLeft, const string16& iRight)
	{
	if (iLeft.empty())
		{
		if (iRight.empty())
			return 0;
		return -1;
		}

	if (iRight.empty())
		return 1;

	return ::ucol_strcoll(fCollator, iLeft.data(), iLeft.size(), iRight.data(), iRight.size());
	}
Exemple #14
0
        void SetAppIdForWindow(const string16& app_id, HWND hwnd)
        {
            // This functionality is only available on Win7+.
            if(base::win::GetVersion() < base::win::VERSION_WIN7)
            {
                return;
            }

            // Load Shell32.dll into memory.
            // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk.
            std::wstring shell32_filename(kShell32);
            FilePath shell32_filepath(shell32_filename);
            base::NativeLibrary shell32_library = base::LoadNativeLibrary(shell32_filepath);

            if(!shell32_library)
            {
                return;
            }

            // Get the function pointer for SHGetPropertyStoreForWindow.
            void* function = base::GetFunctionPointerFromNativeLibrary(
                shell32_library,
                kSHGetPropertyStoreForWindow);

            if(!function)
            {
                base::UnloadNativeLibrary(shell32_library);
                return;
            }

            // Set the application's name.
            base::win::ScopedComPtr<IPropertyStore> pps;
            SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function);
            HRESULT result = SHGetPropertyStoreForWindow(
                hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive()));
            if(S_OK == result)
            {
                base::win::SetAppIdForPropertyStore(pps, app_id.c_str());
            }

            // Cleanup.
            base::UnloadNativeLibrary(shell32_library);
        }
Exemple #15
0
bool MatchPattern(const string16& eval, const string16& pattern) {
	return MatchPatternT(eval.c_str(), eval.c_str() + eval.size(),
		pattern.c_str(), pattern.c_str() + pattern.size(),
		0, NextCharUTF16());
}
Exemple #16
0
bool LowerCaseEqualsASCII(const string16& a, const char* b) {
	return DoLowerCaseEqualsASCII(a.begin(), a.end(), b);
}
std::string UTF16ToASCII(const string16& utf16)
{
    DCHECK(IsStringASCII(utf16)) << utf16;
    return std::string(utf16.begin(), utf16.end());
}
Exemple #18
0
	void PuttyView::searchNext(const string16& str)
	{
		return term_find(puttyController_->term, str.c_str(), 0);
	}
Exemple #19
0
	void PuttyView::searchPrevious(const string16& str)
	{
		return term_find(puttyController_->term, str.c_str(), 1);
	}
    bool LaunchProcess(const string16& cmdline,
        const LaunchOptions& options,
        ProcessHandle* process_handle)
    {
        STARTUPINFO startup_info = {};
        startup_info.cb = sizeof(startup_info);
        if(options.empty_desktop_name)
        {
            startup_info.lpDesktop = L"";
        }
        startup_info.dwFlags = STARTF_USESHOWWINDOW;
        startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW;
        PROCESS_INFORMATION process_info;

        DWORD flags = 0;

        if(options.job_handle)
        {
            flags |= CREATE_SUSPENDED;

            // If this code is run under a debugger, the launched process is
            // automatically associated with a job object created by the debugger.
            // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this.
            flags |= CREATE_BREAKAWAY_FROM_JOB;
        }

        if(options.as_user)
        {
            flags |= CREATE_UNICODE_ENVIRONMENT;
            void* enviroment_block = NULL;

            if(!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE))
            {
                return false;
            }

            BOOL launched = CreateProcessAsUser(options.as_user, NULL,
                const_cast<wchar_t*>(cmdline.c_str()),
                NULL, NULL, options.inherit_handles, flags,
                enviroment_block, NULL, &startup_info,
                &process_info);
            DestroyEnvironmentBlock(enviroment_block);
            if(!launched)
            {
                return false;
            }
        }
        else
        {
            if(!CreateProcess(NULL,
                const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL,
                options.inherit_handles, flags, NULL, NULL,
                &startup_info, &process_info))
            {
                return false;
            }
        }

        if(options.job_handle)
        {
            if(0 == AssignProcessToJobObject(options.job_handle, process_info.hProcess))
            {
                LOG(ERROR) << "Could not AssignProcessToObject.";
                KillProcess(process_info.hProcess, kProcessKilledExitCode, true);
                return false;
            }

            ResumeThread(process_info.hThread);
        }

        // Handles must be closed or they will leak.
        CloseHandle(process_info.hThread);

        if(options.wait)
        {
            WaitForSingleObject(process_info.hProcess, INFINITE);
        }

        // If the caller wants the process handle, we won't close it.
        if(process_handle)
        {
            *process_handle = process_info.hProcess;
        }
        else
        {
            CloseHandle(process_info.hProcess);
        }
        return true;
    }
Exemple #21
0
void sWrite(const string16& iString, const ChanW_UTF& iChanW)
	{
	if (const size_t countCU = iString.size())
		spWriteMust(iString.data(), countCU, iChanW);
	}