Changeset 11185

Show
Ignore:
Timestamp:
03/10/10 13:04:14 (5 years ago)
Author:
robert
Message:

Refactored the find_last_of to simplify it.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgDB/FileNameUtils.cpp

    r11184 r11185  
    3434std::string osgDB::getFilePath(const std::string& fileName) 
    3535{ 
    36     std::string::size_type slash1 = fileName.find_last_of('/'); 
    37     std::string::size_type slash2 = fileName.find_last_of('\\'); 
    38     if (slash1==std::string::npos)  
    39     { 
    40         if (slash2==std::string::npos) return std::string(); 
    41         return std::string(fileName,0,slash2); 
    42     } 
    43     if (slash2==std::string::npos) return std::string(fileName,0,slash1); 
    44     return std::string(fileName, 0, slash1>slash2 ?  slash1 : slash2); 
     36    std::string::size_type slash = fileName.find_last_of("/\\"); 
     37    if (slash==std::string::npos) return std::string(); 
     38    else return std::string(fileName, 0, slash); 
    4539} 
    4640 
     
    4842std::string osgDB::getSimpleFileName(const std::string& fileName) 
    4943{ 
    50     std::string::size_type slash1 = fileName.find_last_of('/'); 
    51     std::string::size_type slash2 = fileName.find_last_of('\\'); 
    52     if (slash1==std::string::npos)  
    53     { 
    54         if (slash2==std::string::npos) return fileName; 
    55         return std::string(fileName.begin()+slash2+1,fileName.end()); 
    56     } 
    57     if (slash2==std::string::npos) return std::string(fileName.begin()+slash1+1,fileName.end()); 
    58     return std::string(fileName.begin()+(slash1>slash2?slash1:slash2)+1,fileName.end()); 
     44    std::string::size_type slash = fileName.find_last_of("/\\"); 
     45    if (slash==std::string::npos) return fileName; 
     46    else return std::string(fileName.begin()+slash+1,fileName.end()); 
    5947} 
    6048