Exemple #1
0
//
// Replace all occurrences of the string szOld with szNew
//
WString WString::Replace ( const wchar_t* szOld, const wchar_t* szNew, bool bSearchJustReplaced ) const
{
    // Check if anything to replace first
    size_t idx = 0;
    if( ( idx = this->find ( szOld, idx ) ) == npos )
        return *this;

    size_t iOldLength = wcslen ( szOld );
    size_t iNewLength = wcslen ( szNew );
    WString strResult = *this;
    do
    {
        strResult.replace ( idx, iOldLength, szNew );
        if ( !bSearchJustReplaced )
            idx += iNewLength;
    }
    while( ( idx = strResult.find ( szOld, idx ) ) != npos );
    return strResult;
}
Exemple #2
0
SharedPtr<FormatBase> FormatBase::loadImport(const String &filename, int architecture)
{
	if(File::isPathExists(filename))
		return ::loadImport(filename, architecture);

	List<String> searchPaths;
	String currentDirectory = WStringToString(Win32NativeHelper::get()->getCurrentDirectory());
	searchPaths.push_back(currentDirectory.substr(0, currentDirectory.length() - 1));
#ifdef _WIN32
	wchar_t *environmentBlock = Win32NativeHelper::get()->getEnvironments();
	WString path;
	while(*environmentBlock)
	{
		size_t equal = 0;
		size_t currentLength = 0;
		wchar_t *start = environmentBlock;
		while(*environmentBlock ++) 
		{
			if(*environmentBlock == L'=')
				equal = currentLength;
			currentLength ++;
		}
		if(equal >= 3 && 
			WString::to_lower(start[0]) == L'p' &&
			WString::to_lower(start[1]) == L'a' &&
			WString::to_lower(start[2]) == L't' &&
			WString::to_lower(start[3]) == L'h' &&
			start[4] == L'=')
		{
			path.assign(start + equal + 2);
			break;
		}
	}
	int s = 0, e = 0;
	while(true)
	{
		e = path.find(L';', e + 1);
		if(e == -1)
			break;
		String currentPath = WStringToString(path.substr(s, e - s));
		searchPaths.push_back(currentPath);
		s = e + 1;
	}
#endif
	for(auto &i : searchPaths)
	{
		String path = File::combinePath(i, filename);
		SharedPtr<FormatBase> result = ::loadImport(path, architecture);
		if(!result)
		{
			if(path.substr(path.length() - 4).icompare(".dll") != 0)
			{
				path.append(".dll");
				result = ::loadImport(path, architecture);
			}
		}
		if(result.get())
			return result;
	}
	return SharedPtr<FormatBase>(nullptr);
}