Loading...
Searching...
No Matches
coreutil.h
Go to the documentation of this file.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __IRR_CORE_UTIL_H_INCLUDED__
#define __IRR_CORE_UTIL_H_INCLUDED__
#include "irrString.h"
#include "path.h"
namespace irr
{
namespace core
{
// ----------- some basic quite often used string functions -----------------
inline s32 isFileExtension ( const io::path& filename,
const io::path& ext0,
const io::path& ext1,
const io::path& ext2)
{
s32 extPos = filename.findLast ( '.' );
if ( extPos < 0 )
return 0;
extPos += 1;
if ( filename.equals_substring_ignore_case ( ext0, extPos ) ) return 1;
if ( filename.equals_substring_ignore_case ( ext1, extPos ) ) return 2;
if ( filename.equals_substring_ignore_case ( ext2, extPos ) ) return 3;
return 0;
}
inline bool hasFileExtension ( const io::path& filename,
const io::path& ext0,
const io::path& ext1 = "",
const io::path& ext2 = "")
{
return isFileExtension ( filename, ext0, ext1, ext2 ) > 0;
}
inline io::path& cutFilenameExtension ( io::path &dest, const io::path &source )
{
s32 endPos = source.findLast ( '.' );
dest = source.subString ( 0, endPos < 0 ? source.size () : endPos );
return dest;
}
inline io::path& getFileNameExtension ( io::path &dest, const io::path &source )
{
s32 endPos = source.findLast ( '.' );
if ( endPos < 0 )
dest = "";
else
dest = source.subString ( endPos, source.size () );
return dest;
}
inline io::path& deletePathFromFilename(io::path& filename)
{
// delete path from filename
const fschar_t* s = filename.c_str();
const fschar_t* p = s + filename.size();
// search for path separator or beginning
while ( *p != '/' && *p != '\\' && p != s )
p--;
if ( p != s )
{
++p;
filename = p;
}
return filename;
}
inline io::path& deletePathFromPath(io::path& filename, s32 pathCount)
{
// delete path from filename
s32 i = filename.size();
// search for path separator or beginning
while ( i>=0 )
{
if ( filename[i] == '/' || filename[i] == '\\' )
{
if ( --pathCount <= 0 )
break;
}
--i;
}
if ( i>0 )
{
filename [ i + 1 ] = 0;
filename.validate();
}
else
filename="";
return filename;
}
inline s32 isInSameDirectory ( const io::path& path, const io::path& file )
{
s32 subA = 0;
s32 subB = 0;
s32 pos;
if ( path.size() && !path.equalsn ( file, path.size() ) )
return -1;
pos = 0;
while ( (pos = path.findNext ( '/', pos )) >= 0 )
{
subA += 1;
pos += 1;
}
pos = 0;
while ( (pos = file.findNext ( '/', pos )) >= 0 )
{
subB += 1;
pos += 1;
}
return subB - subA;
}
// splits a path into components
static inline void splitFilename(const io::path &name, io::path* path=0,
io::path* filename=0, io::path* extension=0, bool make_lower=false)
{
s32 i = name.size();
s32 extpos = i;
// search for path separator or beginning
while ( i >= 0 )
{
if ( name[i] == '.' )
{
extpos = i;
if ( extension )
*extension = name.subString ( extpos + 1, name.size() - (extpos + 1), make_lower );
}
else
if ( name[i] == '/' || name[i] == '\\' )
{
if ( filename )
*filename = name.subString ( i + 1, extpos - (i + 1), make_lower );
if ( path )
{
*path = name.subString ( 0, i + 1, make_lower );
path->replace ( '\\', '/' );
}
return;
}
i -= 1;
}
if ( filename )
*filename = name.subString ( 0, extpos, make_lower );
}
#undef isdigit
#undef isspace
#undef isupper
inline s32 isdigit(s32 c) { return c >= '0' && c <= '9'; }
inline s32 isspace(s32 c) { return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; }
inline s32 isupper(s32 c) { return c >= 'A' && c <= 'Z'; }
} // end namespace core
} // end namespace irr
#endif
irr::core::string::size
u32 size() const
Returns length of the string's content.
Definition irrString.h:481
irr::core::string::validate
string< T, TAlloc > & validate()
verify the existing string.
Definition irrString.h:1247
irr::core::string::subString
string< T > subString(u32 begin, s32 length, bool make_lower=false) const
Returns a substring.
Definition irrString.h:891
irr::core::string::findLast
s32 findLast(T c, s32 start=-1) const
finds last occurrence of character in string
Definition irrString.h:822
irr::core::string::replace
string< T, TAlloc > & replace(T toReplace, T replaceWith)
Replaces all characters of a special type with another one.
Definition irrString.h:1007
irr::core::string::findNext
s32 findNext(T c, u32 startPos) const
finds next occurrence of character in string
Definition irrString.h:807
irr::core::string::c_str
const T * c_str() const
Returns character string.
Definition irrString.h:495
irr::core::string::equals_substring_ignore_case
bool equals_substring_ignore_case(const string< T, TAlloc > &other, const s32 sourcePos=0) const
Compares the strings ignoring case.
Definition irrString.h:535
irr::core::string::equalsn
bool equalsn(const string< T, TAlloc > &other, u32 n) const
compares the first n characters of the strings
Definition irrString.h:569
irrString.h
irr::core
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
irr::core::deletePathFromPath
io::path & deletePathFromPath(io::path &filename, s32 pathCount)
trim paths
Definition coreutil.h:87
irr::core::isupper
s32 isupper(s32 c)
Definition coreutil.h:182
irr::core::hasFileExtension
bool hasFileExtension(const io::path &filename, const io::path &ext0, const io::path &ext1="", const io::path &ext2="")
search if a filename has a proper extension
Definition coreutil.h:40
irr::core::getFileNameExtension
io::path & getFileNameExtension(io::path &dest, const io::path &source)
get the filename extension from a file path
Definition coreutil.h:57
irr::core::isFileExtension
s32 isFileExtension(const io::path &filename, const io::path &ext0, const io::path &ext1, const io::path &ext2)
search if a filename has a proper extension
Definition coreutil.h:23
irr::core::isdigit
s32 isdigit(s32 c)
some standard function ( to remove dependencies )
Definition coreutil.h:180
irr::core::isspace
s32 isspace(s32 c)
Definition coreutil.h:181
irr::core::deletePathFromFilename
io::path & deletePathFromFilename(io::path &filename)
delete path from filename
Definition coreutil.h:68
irr::core::cutFilenameExtension
io::path & cutFilenameExtension(io::path &dest, const io::path &source)
cut the filename extension from a source file path and store it in a dest file path
Definition coreutil.h:49
irr::core::isInSameDirectory
s32 isInSameDirectory(const io::path &path, const io::path &file)
Definition coreutil.h:115
irr::io::path
core::string< fschar_t > path
Type used for all file system related strings.
Definition path.h:17
irr
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
irr::fschar_t
char fschar_t
Type name for character type used by the file system.
Definition irrTypes.h:158
irr::s32
signed int s32
32 bit signed variable.
Definition irrTypes.h:66
path.h
- Irrlicht Engine Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on for Irrlicht 3D Engine by Doxygen 1.15.0