Changeset 11184

Show
Ignore:
Timestamp:
03/10/10 12:40:17 (4 years ago)
Author:
robert
Message:

From Sukender, "Here is my proposal. I fixed what Paul said, added some doxygen comments, added the function I told about, and removed the two "find('/')"-like calls to use only one."

Location:
OpenSceneGraph/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgDB/FileNameUtils

    r9884 r11184  
    2121namespace osgDB { 
    2222 
     23/** Gets the parent path from full name (Ex: /a/b/c.Ext => /a/b). */ 
    2324extern OSGDB_EXPORT std::string getFilePath(const std::string& filename); 
     25/** Gets the extension without dot (Ex: /a/b/c.Ext => Ext). */ 
    2426extern OSGDB_EXPORT std::string getFileExtension(const std::string& filename); 
     27/** Gets the extension including dot (Ex: /a/b/c.Ext => .Ext). */ 
    2528extern OSGDB_EXPORT std::string getFileExtensionIncludingDot(const std::string& filename); 
     29/** Gets the lowercase extension without dot (Ex: /a/b/c.Ext => ext). */ 
    2630extern OSGDB_EXPORT std::string getLowerCaseFileExtension(const std::string& filename); 
     31/** Gets file name with extension (Ex: /a/b/c.Ext => c.Ext). */ 
    2732extern OSGDB_EXPORT std::string getSimpleFileName(const std::string& fileName); 
     33/** Gets file path without last extension (Ex: /a/b/c.Ext => /a/b/c ; file.ext1.ext2 => file.ext1). */ 
    2834extern OSGDB_EXPORT std::string getNameLessExtension(const std::string& fileName); 
     35/** Gets file path without \b all extensions (Ex: /a/b/c.Ext => /a/b/c ; file.ext1.ext2 => file). */ 
     36extern OSGDB_EXPORT std::string getNameLessAllExtensions(const std::string& fileName); 
     37/** Gets file name without last extension (Ex: /a/b/c.Ext => c ; file.ext1.ext2 => file.ext1). */ 
    2938extern OSGDB_EXPORT std::string getStrippedName(const std::string& fileName); 
    3039 
    3140 
     41/** Converts forward slashes (/) to back slashes (\). */ 
    3242extern OSGDB_EXPORT std::string convertFileNameToWindowsStyle(const std::string& fileName); 
     43/** Converts back slashes (\) to forward slashes (/). */ 
    3344extern OSGDB_EXPORT std::string convertFileNameToUnixStyle(const std::string& fileName); 
    3445extern OSGDB_EXPORT std::string convertToLowerCase(const std::string& fileName); 
  • OpenSceneGraph/trunk/src/osgDB/FileNameUtils.cpp

    r11171 r11184  
    139139std::string osgDB::getNameLessExtension(const std::string& fileName) 
    140140{ 
    141     std::string::size_type dot = fileName.find_last_of('.');  
    142     std::string::size_type back_slash = fileName.find_last_of('\\'); 
    143     std::string::size_type slash = fileName.find_last_of('/');  
    144     if (dot==std::string::npos || (dot<back_slash && dot<slash)) return fileName; 
     141    std::string::size_type dot = fileName.find_last_of('.'); 
     142    std::string::size_type slash = fileName.find_last_of("/\\");        // Finds forward slash *or* back slash 
     143    if (dot==std::string::npos || (slash!=std::string::npos && dot<slash)) return fileName; 
    145144    return std::string(fileName.begin(),fileName.begin()+dot); 
    146145} 
    147146 
     147 
     148// strip all extensions from the filename. 
     149std::string osgDB::getNameLessAllExtensions(const std::string& fileName) 
     150{ 
     151    // Finds start serach position: from last slash, or the begining of the string if none found 
     152    std::string::size_type startPos = fileName.find_last_of("/\\");            // Finds forward slash *or* back slash 
     153    if (startPos == std::string::npos) startPos = 0; 
     154    std::string::size_type dot = fileName.find_first_of('.', startPos);        // Finds *FIRST* dot from start pos 
     155    if (dot==std::string::npos) return fileName; 
     156    return std::string(fileName.begin(),fileName.begin()+dot); 
     157} 
    148158 
    149159std::string osgDB::getStrippedName(const std::string& fileName)