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-2009 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 stringc& cutFilenameExtension ( stringc &dest, const stringc &source )
    00050 {
    00051         s32 endPos = source.findLast ( '.' );
    00052         dest = source.subString ( 0, endPos < 0 ? source.size () : endPos );
    00053         return dest;
    00054 }
    00055
    00057 inline stringw& cutFilenameExtension ( stringw &dest, const stringw &source )
    00058 {
    00059         s32 endPos = source.findLast ( '.' );
    00060         dest = source.subString ( 0, endPos < 0 ? source.size () : endPos );
    00061         return dest;
    00062 }
    00063
    00065 inline stringc& getFileNameExtension ( stringc &dest, const stringc &source )
    00066 {
    00067         s32 endPos = source.findLast ( '.' );
    00068         if ( endPos < 0 )
    00069                 dest = "";
    00070         else
    00071                 dest = source.subString ( endPos, source.size () );
    00072         return dest;
    00073 }
    00074
    00076 inline core::stringw& deletePathFromFilename(core::stringw& filename)
    00077 {
    00078         // delete path from filename
    00079         const wchar_t *s = filename.c_str();
    00080         const wchar_t* p = s + filename.size();
    00081
    00082         // search for path separator or beginning
    00083         while ( *p != '/' && *p != '\\' && p != s )
    00084                 p--;
    00085
    00086         if ( p != s )
    00087         {
    00088                 ++p;
    00089                 filename = p;
    00090         }
    00091         return filename;
    00092 }
    00093
    00095 inline core::stringc& deletePathFromFilename(core::stringc& filename)
    00096 {
    00097         // delete path from filename
    00098         const c8 *s = filename.c_str();
    00099         const c8* p = s + filename.size();
    00100
    00101         // search for path separator or beginning
    00102         while ( *p != '/' && *p != '\\' && p != s )
    00103                 p--;
    00104
    00105         if ( p != s )
    00106         {
    00107                 ++p;
    00108                 filename = p;
    00109         }
    00110         return filename;
    00111 }
    00112
    00114 inline io::path& deletePathFromPath(io::path& filename, s32 pathCount)
    00115 {
    00116         // delete path from filename
    00117         s32 i = filename.size();
    00118
    00119         // search for path separator or beginning
    00120         while ( i )
    00121         {
    00122                 if ( filename[i] == '/' || filename[i] == '\\' )
    00123                 {
    00124                         if ( --pathCount <= 0 )
    00125                                 break;
    00126                 }
    00127                 i -= 1;
    00128         }
    00129
    00130         if ( i )
    00131         {
    00132                 filename [ i + 1 ] = 0;
    00133                 filename.validate();
    00134         }
    00135         return filename;
    00136 }
    00137
    00140 inline s32 isInSameDirectory ( const io::path& path, const io::path& file )
    00141 {
    00142         s32 subA = 0;
    00143         s32 subB = 0;
    00144         s32 pos;
    00145
    00146         if ( path.size() && !path.equalsn ( file, path.size() ) )
    00147                 return -1;
    00148
    00149         pos = 0;
    00150         while ( (pos = path.findNext ( '/', pos )) >= 0 )
    00151         {
    00152                 subA += 1;
    00153                 pos += 1;
    00154         }
    00155
    00156         pos = 0;
    00157         while ( (pos = file.findNext ( '/', pos )) >= 0 )
    00158         {
    00159                 subB += 1;
    00160                 pos += 1;
    00161         }
    00162
    00163         return subB - subA;
    00164 }
    00165
    00166
    00168 #undef isdigit
    00169 #undef isspace
    00170 #undef isupper
    00171 inline s32 isdigit(s32 c) { return c >= '0' && c <= '9'; }
    00172 inline s32 isspace(s32 c) { return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; }
    00173 inline s32 isupper(s32 c) { return c >= 'A' && c <= 'Z'; }
    00174
    00175
    00176 } // end namespace core
    00177 } // end namespace irr
    00178
    00179 #endif
    00180

| The Irrlicht Engine Documentation © 2003-2009 by Nikolaus Gebhardt. Generated on Sun Jan 10 09:24:03 2010 by Doxygen (1.5.6)