Irrlicht Engine: coreutil.h Source File

Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials

# coreutil.h

Go to the documentation of this file.

    00001 // Copyright (C) 2002-2010 Nikolaus Gebhardt
    00002 // This file is part of the "Irrlicht Engine".
    00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
    00004
    00005 #ifndef __IRR_CORE_UTIL_H_INCLUDED__
    00006 #define __IRR_CORE_UTIL_H_INCLUDED__
    00007
    00008 #include "irrString.h"
    00009 #include "path.h"
    00010
    00011 namespace irr
    00012 {
    00013 namespace core
    00014 {
    00015
    00020 // ----------- some basic quite often used string functions -----------------
    00021
    00023 inline s32 isFileExtension (    const io::path& filename,
    00024                                                                 const io::path& ext0,
    00025                                                                 const io::path& ext1,
    00026                                                                 const io::path& ext2)
    00027 {
    00028         s32 extPos = filename.findLast ( '.' );
    00029         if ( extPos < 0 )
    00030                 return 0;
    00031
    00032         extPos += 1;
    00033         if ( filename.equals_substring_ignore_case ( ext0, extPos ) ) return 1;
    00034         if ( filename.equals_substring_ignore_case ( ext1, extPos ) ) return 2;
    00035         if ( filename.equals_substring_ignore_case ( ext2, extPos ) ) return 3;
    00036         return 0;
    00037 }
    00038
    00040 inline bool hasFileExtension (  const io::path& filename,
    00041                                                                 const io::path& ext0,
    00042                                                                 const io::path& ext1 = "",
    00043                                                                 const io::path& ext2 = "")
    00044 {
    00045         return isFileExtension ( filename, ext0, ext1, ext2 ) > 0;
    00046 }
    00047
    00049 inline io::path& cutFilenameExtension ( io::path &dest, const io::path &source )
    00050 {
    00051         s32 endPos = source.findLast ( '.' );
    00052         dest = source.subString ( 0, endPos < 0 ? source.size () : endPos );
    00053         return dest;
    00054 }
    00055
    00057 inline io::path& getFileNameExtension ( io::path &dest, const io::path &source )
    00058 {
    00059         s32 endPos = source.findLast ( '.' );
    00060         if ( endPos < 0 )
    00061                 dest = "";
    00062         else
    00063                 dest = source.subString ( endPos, source.size () );
    00064         return dest;
    00065 }
    00066
    00068 inline io::path& deletePathFromFilename(io::path& filename)
    00069 {
    00070         // delete path from filename
    00071         const fschar_t* s = filename.c_str();
    00072         const fschar_t* p = s + filename.size();
    00073
    00074         // search for path separator or beginning
    00075         while ( *p != '/' && *p != '\\' && p != s )
    00076                 p--;
    00077
    00078         if ( p != s )
    00079         {
    00080                 ++p;
    00081                 filename = p;
    00082         }
    00083         return filename;
    00084 }
    00085
    00087 inline io::path& deletePathFromPath(io::path& filename, s32 pathCount)
    00088 {
    00089         // delete path from filename
    00090         s32 i = filename.size();
    00091
    00092         // search for path separator or beginning
    00093         while ( i>=0 )
    00094         {
    00095                 if ( filename[i] == '/' || filename[i] == '\\' )
    00096                 {
    00097                         if ( --pathCount <= 0 )
    00098                                 break;
    00099                 }
    00100                 --i;
    00101         }
    00102
    00103         if ( i>0 )
    00104         {
    00105                 filename [ i + 1 ] = 0;
    00106                 filename.validate();
    00107         }
    00108         else
    00109                 filename="";
    00110         return filename;
    00111 }
    00112
    00115 inline s32 isInSameDirectory ( const io::path& path, const io::path& file )
    00116 {
    00117         s32 subA = 0;
    00118         s32 subB = 0;
    00119         s32 pos;
    00120
    00121         if ( path.size() && !path.equalsn ( file, path.size() ) )
    00122                 return -1;
    00123
    00124         pos = 0;
    00125         while ( (pos = path.findNext ( '/', pos )) >= 0 )
    00126         {
    00127                 subA += 1;
    00128                 pos += 1;
    00129         }
    00130
    00131         pos = 0;
    00132         while ( (pos = file.findNext ( '/', pos )) >= 0 )
    00133         {
    00134                 subB += 1;
    00135                 pos += 1;
    00136         }
    00137
    00138         return subB - subA;
    00139 }
    00140
    00141
    00143 #undef isdigit
    00144 #undef isspace
    00145 #undef isupper
    00146 inline s32 isdigit(s32 c) { return c >= '0' && c <= '9'; }
    00147 inline s32 isspace(s32 c) { return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; }
    00148 inline s32 isupper(s32 c) { return c >= 'A' && c <= 'Z'; }
    00149
    00150
    00151 } // end namespace core
    00152 } // end namespace irr
    00153
    00154 #endif
    00155

| The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Sun Oct 24 12:41:56 2010 by Doxygen (1.6.2)