Added new utilities for handling different '/' and '\' entries.

This commit is contained in:
Robert Osfield 2005-02-11 09:58:30 +00:00
parent 7282adef2b
commit dd0c29d19b
3 changed files with 60 additions and 0 deletions

View File

@ -27,6 +27,13 @@ extern OSGDB_EXPORT std::string getSimpleFileName(const std::string& fileName);
extern OSGDB_EXPORT std::string getNameLessExtension(const std::string& fileName);
extern OSGDB_EXPORT std::string getStrippedName(const std::string& fileName);
extern OSGDB_EXPORT std::string convertFileNameToWindowsStyle(const std::string& fileName);
extern OSGDB_EXPORT std::string convertFileNameToUnixStyle(const std::string& fileName);
extern OSGDB_EXPORT bool isFileNameNativeStyle(const std::string& fileName);
extern OSGDB_EXPORT std::string convertFileNameToNativeStyle(const std::string& fileName);
extern OSGDB_EXPORT bool equalCaseInsensitive(const std::string& lhs,const std::string& rhs);
extern OSGDB_EXPORT bool equalCaseInsensitive(const std::string& lhs,const char* rhs);

View File

@ -20,6 +20,8 @@
using std::strlen;
#endif
#include <osg/Notify>
using namespace std;
std::string osgDB::getFilePath(const std::string& fileName)
@ -57,6 +59,54 @@ std::string osgDB::getFileExtension(const std::string& fileName)
return std::string(fileName.begin()+dot+1,fileName.end());
}
std::string osgDB::convertFileNameToWindowsStyle(const std::string& fileName)
{
std::string new_fileName(fileName);
std::string::size_type slash = 0;
while( (slash=new_fileName.find_first_of('/',slash)) != std::string::npos)
{
new_fileName[slash]='\\';
}
return new_fileName;
}
std::string osgDB::convertFileNameToUnixStyle(const std::string& fileName)
{
osg::notify(osg::NOTICE)<<"convertFileNameToUnixStyle("<<fileName<<")"<<std::endl;
std::string new_fileName(fileName);
std::string::size_type slash = 0;
while( (slash=new_fileName.find_first_of('\\',slash)) != std::string::npos)
{
new_fileName[slash]='/';
}
osg::notify(osg::NOTICE)<<"convertFileNameToUnixStyle("<<new_fileName<<")"<<std::endl;
return new_fileName;
}
bool osgDB::isFileNameNativeStyle(const std::string& fileName)
{
#ifdef WIN32
return fileName.find('/') == std::string::npos; // return true if no unix style slash exist
#else
return fileName.find('\\') == std::string::npos; // return true if no windows style slash exist
#endif
}
std::string osgDB::convertFileNameToNativeStyle(const std::string& fileName)
{
#ifdef WIN32
return convertFileNameToWindowsStyle(fileName);
#else
return convertFileNameToUnixStyle(fileName);
#endif
}
std::string osgDB::getLowerCaseFileExtension(const std::string& filename)
{

View File

@ -171,6 +171,9 @@ std::string osgDB::findFileInPath(const std::string& filename, const FilePathLis
if (filename.empty())
return filename;
if (!isFileNameNativeStyle(filename))
return findFileInPath(convertFileNameToNativeStyle(filename), filepath, caseSensitivity);
for(FilePathList::const_iterator itr=filepath.begin();
itr!=filepath.end();