Exemplo n.º 1
0
String FilePath::GetFilename(const String &pathname)
{
    String::size_type dotpos = pathname.rfind(String("/"));
    if (dotpos == String::npos)
        return pathname;
    
    return pathname.substr(dotpos+1);
}
Exemplo n.º 2
0
String lastComponent(const String &path) {
	size_t pos = path.rfind('/');
	if (pos != String::npos) {
		return path.substr(pos + 1);
	} else {
		return path;
	}
}
Exemplo n.º 3
0
	inline String xRemoveScope(const String& str) {
		size_t pos = str.rfind('.');
		if (pos == String::npos || pos >= str.length()-1) {
			return str;
		}

		return str.substr(pos+1, str.length()-pos-1);
	}
Exemplo n.º 4
0
static String extractModelName( const String& filename )
{
    size_t startPos = filename.rfind('/');
    if( startPos == String::npos )
        startPos = filename.rfind('\\');

    if( startPos == String::npos )
        startPos = 0;
    else
        startPos++;

    const int extentionSize = 4; //.xml

    int substrLength = (int)(filename.size() - startPos - extentionSize);

    return filename.substr(startPos, substrLength);
}
Exemplo n.º 5
0
void FileSystemLayer::getConfigPaths()
{
#if U2_PLATFORM == U2_PLATFORM_WIN32
    // try to determine the application's path
    DWORD bufsize = 256;
    char* resolved = 0;
    do
    {
        char* buf = U2_ALLOC_T(char, bufsize, MEMCATEGORY_GENERAL);
        DWORD retval = GetModuleFileNameA(NULL, buf, bufsize);
        if (retval == 0)
        {
            // failed
            U2_FREE(buf, MEMCATEGORY_GENERAL);
            break;
        }

        if (retval < bufsize)
        {
            // operation was successful.
            resolved = buf;
        }
        else
        {
            // buffer was too small, grow buffer and try again
            U2_FREE(buf, MEMCATEGORY_GENERAL);
            bufsize <<= 1;
        }
    } while (!resolved);

    String appPath = resolved;
    if (resolved)
        U2_FREE(resolved, MEMCATEGORY_GENERAL);
    if (!appPath.empty())
    {
        // need to strip the application filename from the path
        String::size_type pos = appPath.rfind('\\');
        if (pos != String::npos)
            appPath.erase(pos);
    }
    else
    {
        // fall back to current working dir
        appPath = ".";
    }

#elif U2_PLATFORM == U2_PLATFORM_WINRT
    String appPath;
    if(!widePathToOgreString(appPath, Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data()))
    {
        // fallback to current working dir
        appPath = ".";
    }
#endif

    // use application path as config search path
    mConfigPaths.push_back(appPath + '\\');
}
 Variant rvalAt(const String& needle) const {
   /* First try to find exact match, afterwards try wildcard matches */
   int lastDotPos = needle.rfind('.');
   if (String::npos == lastDotPos || m_filters.exists(needle.toKey())) {
     return m_filters.rvalAtRef(needle);
   }
   String wildcard = needle.substr(0, lastDotPos) + ".*";
   return m_filters.rvalAtRef(wildcard);
 }
Exemplo n.º 7
0
void Tag::setID( const String& newID )
{
    id = newID;
    size_t pos = newID.rfind( delimiter );
    if( pos == String::npos )
        shortID = newID;
    else
        shortID = newID.substr( pos+1, newID.length() - 1 );
}
Exemplo n.º 8
0
String FileSystem::ReplaceExtension(const String & filename, const String & newExt)
{
	String::size_type dotpos = filename.rfind(".");
	if (dotpos == String::npos)
		return String();
	
	String result = filename.substr(0, dotpos) + newExt;
	return result;
}	
size_t Reader_Directory::Format_Test(MediaInfo_Internal* MI, const String &File_Name)
{
    #ifdef MEDIAINFO_BDMV_YES
        if (Dir::Exists(File_Name) && File_Name.find(Ztring(1, PathSeparator)+_T("BDMV"))+5==File_Name.size())
            return Bdmv_Format_Test(MI, File_Name);
    #endif //MEDIAINFO_BDMV_YES

    #ifdef MEDIAINFO_P2_YES
        if (Dir::Exists(File_Name) && File_Name.rfind(Ztring(1, PathSeparator)+_T("CONTENT"))+8==File_Name.size())
            return P2_Format_Test(MI, File_Name);
    #endif //MEDIAINFO_P2_YES

    #ifdef MEDIAINFO_XDCAM_YES
        if (Dir::Exists(File_Name) && File_Name.rfind(Ztring(1, PathSeparator)+_T("XDCAM"))+5==File_Name.size())
            return Xdcam_Format_Test(MI, File_Name);
    #endif //MEDIAINFO_XDCAM_YES

    return 0;
}
Exemplo n.º 10
0
String FilePath::GetExtension() const
{
    const String filename = GetFilename();
    
    const String::size_type dotpos = filename.rfind(String("."));
	if (dotpos == String::npos)
        return String();
    
    return filename.substr(dotpos);
}
Exemplo n.º 11
0
// FIXME method naming
String GetPerServerString(const String& orig, const ServerID& sid) {
    int32 dot_pos = orig.rfind(".");
    String prefix = orig.substr(0, dot_pos);
    String ext = orig.substr(dot_pos+1);

    char buffer[1024];
    sprintf(buffer, "%s-%04d.%s", prefix.c_str(), (uint32)sid, ext.c_str());

    return buffer;
}
Exemplo n.º 12
0
	//--------------------------------------------------------------------------------
	static void setTextureAndTexAniFPS(const MaterialPtr& _material, const String& _texture, Real _texAniFPS)
	{
		Technique* technique = _material->getTechnique(0);
		Pass* pass = technique->getPass(0);
		if(_texture.empty())
		{
			pass->removeAllTextureUnitStates();
		}
		else
		{
			TextureManager& tmgr = TextureManager::getSingleton();
			Ogre::TextureUnitState* tus = pass->getNumTextureUnitStates() ? pass->getTextureUnitState(0) : pass->createTextureUnitState();
			if(_texAniFPS == 0)
			{
				TexturePtr ogreTexture = tmgr.createOrRetrieve(_texture).first;
				const String& ogreTexName = ogreTexture->getName();
				tus->setTextureName(ogreTexName);
			}
			else
			{
				vector<String>::type ogreTexNames;
				TexturePtr ogreTexture = tmgr.createOrRetrieve(_texture).first;
				ogreTexNames.push_back(ogreTexture->getName());

				size_t dotpos = _texture.rfind('.');
				if(dotpos != String::npos && dotpos >= 1 
					&& '0' <= _texture[dotpos-1]  && _texture[dotpos-1] < '9')
				{
					String tmpname = _texture;
					char& dig0 = tmpname[dotpos - 1];
					++dig0;
					while(!tmgr.getByName(tmpname).isNull() || tmgr.canLoadResource(tmpname, TextureManager::GROUP_NAME))
					{
						TexturePtr ogreTexture = tmgr.createOrRetrieve(tmpname).first;
						ogreTexNames.push_back(ogreTexture->getName());
						++dig0;
						if(dig0 > '9')
						{
							if(dotpos >= 2 && '0' <= _texture[dotpos-2]  && _texture[dotpos-2] < '9')
							{
								char& dig1 = tmpname[dotpos-2];
								++dig1;
								dig0 = '0';
							}
							else
								break;
						}
					}
				}
				Real duration = ogreTexNames.size() / _texAniFPS;
				tus->setAnimatedTextureName(&ogreTexNames[0], ogreTexNames.size(), duration);
			}
		}
	}
Exemplo n.º 13
0
void ConvertPaletted::convert(const String& fileName) {
    if (fileName.rfind(".bmp") == std::string::npos) return;
    String out = fileName;
    size_t extPos = out.rfind('.');
    if (extPos != String::npos) out = out.substr(0, extPos);
    out += ".png";
    if (!g_dryrun) {
        SDL_Surface *surf = IMG_Load(fileName.c_str());
        if (!surf) {
            std::cerr << String("Couldn't open ") << fileName << ": " << IMG_GetError() << std::endl;
            return;
        }
        uint8_t r, g, b, a;
        if (surf->format->palette) {
            SDL_GetRGBA(0, surf->format, &r, &g, &b, &a);
            std::cout << fileName << ": converting [" << uint16_t(r) << ", " << uint16_t(g) << ", " <<
                uint16_t(b) << ", " << uint16_t(a) << "] to alpha" << std::endl;
            SDL_SetColorKey(surf, SDL_TRUE, 0);
        } else {
            std::cout << fileName << ": no palette" << std::endl;
        }
        SDL_Surface *other = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_RGBA8888, 0);
        SDL_FreeSurface(surf);
        if (!other) {
            std::cerr << "Couldn't convert " << fileName << ": " << SDL_GetError() << std::endl;
            return;
        }
        uint32_t *pixels = (uint32_t *)other->pixels;
        for (int i = 0; i < other->w * other->h; i++, pixels++) {
            SDL_GetRGBA(*pixels, other->format, &r, &g, &b, &a);
            float aFloat = a / 255;
            r *= aFloat; g *= aFloat; b *= aFloat;
            *pixels = SDL_MapRGBA(other->format, r, g, b, a);
        }
        if (IMG_SavePNG(other, out.c_str()) == -1)
            std::cerr << "Couldn't save " << out << ":" << IMG_GetError() << std::endl;
        SDL_FreeSurface(other);
    } else {
        std::cout << "converting " << fileName << " to " << out << std::endl;
    }
}
Exemplo n.º 14
0
String root(const String &path) {
	size_t pos = path.rfind('/');
	if (pos == String::npos) {
		return "";
	} else {
		if (pos == 0) {
			return "/";
		} else {
			return path.substr(0, pos);
		}
	}
}
Exemplo n.º 15
0
    //-----------------------------------------------------------------------
    bool ZipArchive::exists(const String& filename)
    {       
        OGRE_LOCK_AUTO_MUTEX;
        String cleanName = filename;
        if(filename.rfind("/") != String::npos)
        {
            StringVector tokens = StringUtil::split(filename, "/");
            cleanName = tokens[tokens.size() - 1];
        }

        return std::find_if (mFileList.begin(), mFileList.end(), std::bind2nd<FileNameCompare>(FileNameCompare(), cleanName)) != mFileList.end();
    }
Exemplo n.º 16
0
 bool exists(const String& needle) const {
   if (m_filters.exists(m_filters.convertKey(needle))) {
     return true;
   }
   /* Could not find exact match, now try wildcard match */
   int lastDotPos = needle.rfind('.');
   if (String::npos == lastDotPos) {
     return false;
   }
   String wildcard = needle.substr(0, lastDotPos) + ".*";
   return m_filters.exists(m_filters.convertKey(wildcard));
 }
Exemplo n.º 17
0
void AssetDownloadTask::handleAssetParsed(Mesh::MeshdataPtr md) {
    mAsset = md;

    if (!md) {
        SILOG(ogre,error,"Failed to parse mesh " << mAssetURI.toString());
        mCB();
        return;
    }

    // This is a sanity check. There's no way Ogre can reasonably handle meshes
    // that require a ton of draw calls. Estimate them here and if its too high,
    // destroy the data and invoke the callback to make it look like failure.
    {
        // Draw calls =
        //   Number of instances * number of primitives in instance
        uint32 draw_calls = 0;
        Meshdata::GeometryInstanceIterator geoinst_it = md->getGeometryInstanceIterator();
        uint32 geoinst_idx;
        Matrix4x4f pos_xform;
        while( geoinst_it.next(&geoinst_idx, &pos_xform) )
            draw_calls += md->geometry[ md->instances[geoinst_idx].geometryIndex ].primitives.size();

        // Arbitrary number, but probably more than we should even allow given
        // that there are probably hundreds or thousands of other objects
        if (draw_calls > 500) {
            SILOG(ogre,error,"Excessively complicated mesh: " << mAssetURI.toString() << " has " << draw_calls << " draw calls. Ignoring this mesh.");
            mAsset = Mesh::MeshdataPtr();
            mCB();
            return;
        }
    }

    mRemainingDownloads = md->textures.size();

    // Special case for no dependent downloads
    if (mRemainingDownloads == 0) {
        mCB();
        return;
    }

    String assetURIString = mAssetURI.toString();
    for(TextureList::const_iterator it = md->textures.begin(); it != md->textures.end(); it++) {
        String texURIString = assetURIString.substr(0, assetURIString.rfind("/")+1) + (*it);
        Transfer::URI texURI(texURIString);
        ResourceDownloadTaskPtr dl = ResourceDownloadTask::construct(
            texURI, mScene->transferPool(),
            mPriority,
            std::tr1::bind(&AssetDownloadTask::weakTextureDownloaded, getWeakPtr(), _1, _2)
        );
        mActiveDownloads[texURI] = dl;
        dl->start();
    }
}
Exemplo n.º 18
0
Boolean Table::GetParent(const String &strRecordName,
                         String &strParent)
{
	int pos = strRecordName.rfind(CDB_HIERARCHY_SEPARATOR);
	if(pos == String::npos) 
	{ 
		strParent = ""; 
		return FALSE; 
	}
	strParent = strRecordName.substr(0,pos);
	return TRUE;
}
Exemplo n.º 19
0
String FileManager::GetFileExtension( const String& pFilename )
{
    String  strExtension;
    int     position = pFilename.rfind( '.' );

    if( position != String::npos )
    {
        strExtension = pFilename.substr( position+1 );
    }

    return strExtension;
}
Exemplo n.º 20
0
FilePath FilePath::GetDirectory(const String &pathname, const ePathType pType)
{
    FilePath directory;
    
    const String::size_type slashpos = pathname.rfind(String("/"));
    if (slashpos != String::npos)
    {
        directory = pathname.substr(0, slashpos + 1);
    }
        
    directory.pathType = pType;
    return directory;
}
Exemplo n.º 21
0
	String SynonymPath::calculate(const String& _srcPath)
	{
		// This name and base archive's name are the same directory.
		// However the names must be different to allow 
		// to find archives by unique name.
		String retPath = _srcPath;
		size_t slashPos = retPath.rfind('\\');
		if(slashPos != String.npos)
		{
			retPath.insert(slashPos, "\\");
		}
		else
		{
			slashPos = retPath.rfind('/');
			if(slashPos != String.npos)
			{
				retPath.insert(slashPos, "/");
			}
		}
		GOTHOGRE_ASSERT(retPath != _srcPath, "Pathes must differs!");
		return retPath;
	}
Exemplo n.º 22
0
/**
GetFileName: Returns the base file name

@internalComponent
@released

@param aName - Input file name
@param aFile - Output parameter to hold the return value
*/
void Sis2Iby::GetFileName(String aName, String& aFile)
{
    TUint spos = 0, epos = 0;

    spos = aName.rfind(PATHSEPARATOR);
    if(spos != String::npos)
    {
        spos += 1;
    }
    else
    {
        spos = 0;
    }

    epos = aName.rfind(".");
    if(epos == String::npos)
    {
        epos = aName.size();
    }

    aFile.append(aName.substr(spos, (epos-spos)));
}
Exemplo n.º 23
0
String
ValueNode_Bone::unique_name(String name)const
{
	if (!find(name))
		return name;

	// printf("%s:%d making unique name for '%s'\n", __FILE__, __LINE__, name.c_str());

	size_t last_close(name.size()-1);
	int number = -1;
	String prefix;

	do
	{
		if (name.substr(last_close) != ")")
			break;

		size_t last_open(name.rfind('('));
		if (last_open == String::npos)
			break;

		if (last_open+2 > last_close)
			break;

		String between(name.substr(last_open+1, last_close - (last_open+1)));
		String::iterator iter;
		for (iter = between.begin(); iter != between.end(); iter++)
			if (!isdigit(*iter))
				break;

		if (iter != between.end())
			break;

		prefix = name.substr(0, last_open);
		number = atoi(between.c_str());
	} while (0);

	if (number == -1)
	{
		prefix = name + " ";
		number = 2;
	}

	do
	{
		name = prefix + "(" + strprintf("%d", number++) + ")";
	} while (find(name));

	// printf("%s:%d unique name is '%s'\n", __FILE__, __LINE__, name.c_str());
	return name;
}
Exemplo n.º 24
0
const String& FGetModuleDir()
{
	static String sDir = FGetModuleFile();
	String::size_type nPos = sDir.rfind(STR('/'));
	if (nPos != String::npos)
	{
		sDir.erase(nPos);
	}
	else
	{
		sDir.erase();
	}
	return sDir;
}
Exemplo n.º 25
0
void Path::convertToCanonicalPath(String& path){
	//get real path
	//char buffer[FILENAME_MAX];
	//realpath(path,buffer);
	//path=buffer;
	//unix format:
	for(auto& c:path) if(c=='\\') c='/';
	//delete space at end
	int space_len=0;
	for(auto c:reverse(path))
		if(c==' ')
			++space_len;
		else
			break;
	path=path.substr(0,path.size()-space_len);
	//replace "void path"
	path.replace("//","");
	if(path.size()==0||path=="."||path=="./"){ path="./"; return; }
	//replace ../
	std::vector<String> dirs;
	path.split("/",dirs);
	path=""; //release
	for(uint i=0;i<dirs.size()-1;++i){
	 if(dirs[i]!="."){
		 if(dirs[i+1]!="..")
			path+=dirs[i]+"/";
		  else
			  ++i;
	 }
	}
	if(dirs.size()>1){
		 if(dirs[dirs.size()-1]!=".")
			 if(dirs[dirs.size()-1]!="..")
				path+=dirs[dirs.size()-1];
	}
	else
		path=dirs[0];
	//replace is made a void path..
	if(path.size()==0){ path="./"; return; }
	//directory?
	int point=path.rfind(".");
	int flash=path.rfind("/");
	//is a directory path
	if(flash>point){
		//if directory not have end part
		if(path[path.size()-1]!='/') path+='/';
	}
	//
}
Exemplo n.º 26
0
String lastComponent(const String &path, size_t allowedComponents) {
	if (allowedComponents == 0) {
		return "";
	}
	size_t pos = path.rfind('/');
	allowedComponents --;
	if (pos == 0) {
		pos = String::npos;
	}

	while (pos != String::npos && allowedComponents > 0) {
		pos = path.rfind('/', pos - 1);
		allowedComponents --;
		if (pos == 0) {
			pos = String::npos;
		}
	}

	if (pos != String::npos) {
		return path.substr(pos + 1);
	} else {
		return path;
	}
}
String sb_fextension(const String& path)
{
  String fixedPath = posixPath(path);

  String ext;
  size_t ext_pos = fixedPath.rfind(".");
  size_t dir_pos = fixedPath.rfind("/");

  if (ext_pos != String::npos) {
    if (dir_pos == String::npos || (dir_pos != String::npos && dir_pos < ext_pos)) {
      ext = fixedPath.substr(ext_pos + 1);
    }
  }
  return ext;
}
Exemplo n.º 28
0
	String PathUtil::getName(const String& fullpath) {
		size_t extpos = fullpath.rfind('.');
		size_t pathpos = fullpath.find_last_of("/\\");

		if (pathpos == String::npos) {
			pathpos = 0;
		} else {
			pathpos++;
		}

		if (extpos == String::npos || extpos <= pathpos ) {
			extpos = fullpath.size();
		}

		return fullpath.substr(pathpos, extpos-pathpos);
	}
Exemplo n.º 29
0
void process_args(int & argc, char *argv[], 
		  String & filename, String & filtration){
  std::string usage = "Usage: persistence input-space.asc [filtration.flt]";
  if (argc != 2 && argc != 3){ std::cerr << usage << std::endl; exit( 1); }
  filename = std::string( argv[ 1]);
  if( argc == 2){
    filtration = filename;
    std::size_t pos = filtration.rfind('.');
    if (pos != std::string::npos){ filtration.erase(pos); }
    filtration.append(".flt");
    return;
  }else { filtration = std::string( argv[ 2]); }
  std::cout << "filename: " << filename << std::endl;
  std::cout << "filtration filename: " << filtration << std::endl;

}
	//-------------------------------------------------------------------------------------------------
	String EncodingSettings::getEncoding(const String& _filename, const String& _defaultEncoding)
	{
		static const String ENCODING = "Encoding";
		String r;
		if(hasSetting(ENCODING, _filename, &r))
			return r;

		size_t dotpos = _filename.rfind('.');
		if(dotpos != String::npos)
		{
			String filemask = "*" + _filename.substr(dotpos);
			StrUtil::toUpperCase(filemask);
			r = getSetting<String>(ENCODING, filemask, _defaultEncoding);
			return r;
		}

		return _defaultEncoding;
	}