1
0
mirror of https://github.com/minetest/irrlicht.git synced 2025-08-26 19:20:43 +02:00
Files
.github
bin
cmake
doc
examples
include
CDynamicMeshBuffer.h
CIndexBuffer.h
CMeshBuffer.h
CVertexBuffer.h
EAttributes.h
ECullingTypes.h
EDebugSceneTypes.h
EDeviceTypes.h
EDriverFeatures.h
EDriverTypes.h
EFocusFlags.h
EGUIAlignment.h
EGUIElementTypes.h
EHardwareBufferFlags.h
EMaterialFlags.h
EMaterialTypes.h
EMeshWriterEnums.h
EMessageBoxFlags.h
EPrimitiveTypes.h
EReadFileType.h
ESceneNodeAnimatorTypes.h
ESceneNodeTypes.h
EShaderTypes.h
ETerrainElements.h
EVertexAttributes.h
IAnimatedMesh.h
IAnimatedMeshMD2.h
IAnimatedMeshMD3.h
IAnimatedMeshSceneNode.h
IAttributeExchangingObject.h
IAttributes.h
IBillboardSceneNode.h
IBillboardTextSceneNode.h
IBoneSceneNode.h
ICameraSceneNode.h
IColladaMeshWriter.h
IContextManager.h
ICursorControl.h
IDummyTransformationSceneNode.h
IDynamicMeshBuffer.h
IEventReceiver.h
IFileArchive.h
IFileList.h
IFileSystem.h
IGPUProgrammingServices.h
IGUIButton.h
IGUICheckBox.h
IGUIColorSelectDialog.h
IGUIComboBox.h
IGUIContextMenu.h
IGUIEditBox.h
IGUIElement.h
IGUIElementFactory.h
IGUIEnvironment.h
IGUIFileOpenDialog.h
IGUIFont.h
IGUIFontBitmap.h
IGUIImage.h
IGUIImageList.h
IGUIInOutFader.h
IGUIListBox.h
IGUIMeshViewer.h
IGUIProfiler.h
IGUIScrollBar.h
IGUISkin.h
IGUISpinBox.h
IGUISpriteBank.h
IGUIStaticText.h
IGUITabControl.h
IGUITable.h
IGUIToolbar.h
IGUITreeView.h
IGUIWindow.h
IGeometryCreator.h
IImage.h
IImageLoader.h
IImageWriter.h
IIndexBuffer.h
ILightManager.h
ILightSceneNode.h
ILogger.h
IMaterialRenderer.h
IMaterialRendererServices.h
IMemoryReadFile.h
IMesh.h
IMeshBuffer.h
IMeshCache.h
IMeshLoader.h
IMeshManipulator.h
IMeshSceneNode.h
IMeshTextureLoader.h
IMeshWriter.h
IMetaTriangleSelector.h
IOSOperator.h
IOctreeSceneNode.h
IParticleAffector.h
IParticleAnimatedMeshSceneNodeEmitter.h
IParticleAttractionAffector.h
IParticleBoxEmitter.h
IParticleCylinderEmitter.h
IParticleEmitter.h
IParticleFadeOutAffector.h
IParticleGravityAffector.h
IParticleMeshEmitter.h
IParticleRingEmitter.h
IParticleRotationAffector.h
IParticleSphereEmitter.h
IParticleSystemSceneNode.h
IProfiler.h
IQ3LevelMesh.h
IQ3Shader.h
IRandomizer.h
IReadFile.h
IReferenceCounted.h
IRenderTarget.h
ISceneCollisionManager.h
ISceneLoader.h
ISceneManager.h
ISceneNode.h
ISceneNodeAnimator.h
ISceneNodeAnimatorCameraFPS.h
ISceneNodeAnimatorCameraMaya.h
ISceneNodeAnimatorCollisionResponse.h
ISceneNodeAnimatorFactory.h
ISceneNodeFactory.h
ISceneUserDataSerializer.h
IShaderConstantSetCallBack.h
IShadowVolumeSceneNode.h
ISkinnedMesh.h
ITerrainSceneNode.h
ITextSceneNode.h
ITexture.h
ITimer.h
ITriangleSelector.h
IVertexBuffer.h
IVideoDriver.h
IVideoModeList.h
IVolumeLightSceneNode.h
IWriteFile.h
IXMLReader.h
IXMLWriter.h
IrrCompileConfig.h
IrrlichtDevice.h
Keycodes.h
S3DVertex.h
SAnimatedMesh.h
SColor.h
SExposedVideoData.h
SIrrCreationParameters.h
SKeyMap.h
SLight.h
SMaterial.h
SMaterialLayer.h
SMesh.h
SMeshBuffer.h
SMeshBufferLightMap.h
SMeshBufferTangents.h
SOverrideMaterial.h
SParticle.h
SSharedMeshBuffer.h
SSkinMeshBuffer.h
SVertexIndex.h
SVertexManipulator.h
SViewFrustum.h
SceneParameters.h
aabbox3d.h
coreutil.h
dimension2d.h
driverChoice.h
exampleHelper.h
fast_atof.h
heapsort.h
irrAllocator.h
irrArray.h
irrList.h
irrMap.h
irrMath.h
irrString.h
irrTypes.h
irrXML.h
irrlicht.h
irrpack.h
irrunpack.h
leakHunter.h
line2d.h
line3d.h
matrix4.h
path.h
plane3d.h
position2d.h
quaternion.h
rect.h
triangle3d.h
vector2d.h
vector3d.h
lib
media
scripts
source
tests
tools
.gitignore
CMakeLists.txt
README.md
changes.txt
irr-readme.txt
ogles-readme.txt
irrlicht/include/coreutil.h
cutealien 2ae2a551a6 Merging r5975 through r6036 from trunk to ogl-es branch.
GLES drivers adapted, but only did make compile-tests.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6038 dfc29bdd-3216-0410-991c-e03cc46cb475
2020-01-03 19:05:16 +00:00

206 lines
4.9 KiB
C++

// 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
{
/*! \file coreutil.h
\brief File containing useful basic utility functions
*/
// ----------- some basic quite often used string functions -----------------
//! search if a filename has a proper extension
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;
}
//! search if a filename has a proper extension
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;
}
//! cut the filename extension from a source file path and store it in a dest file path
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;
}
//! get the filename extension from a file path
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;
}
//! delete path from filename
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;
}
//! trim paths
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;
}
//! looks if file is in the same directory of path. returns offset of directory.
//! 0 means in same directory. 1 means file is direct child of path
inline s32 isInSameDirectory ( const io::path& path, const io::path& file )
{
if ( path.size() && !path.equalsn ( file, path.size() ) )
return -1;
s32 subA = 0;
s32 subB = 0;
s32 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 );
}
//! create a filename from components
static inline io::path mergeFilename(const io::path& path, const io::path& filename, const io::path& extension = "")
{
io::path result(path);
if ( !result.empty() )
{
fschar_t last = result.lastChar();
if ( last != _IRR_TEXT('/') && last != _IRR_TEXT('\\') )
result += _IRR_TEXT('/');
}
if ( !filename.empty() )
result += filename;
if ( !extension.empty() )
{
if ( !result.empty() && extension[0] != _IRR_TEXT('.') )
result += _IRR_TEXT('.');
result += extension;
}
return result;
}
//! some standard function ( to remove dependencies )
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