Files
yugioh-legacy-engine/server/irrlicht/include/coreutil.h
T
donnyandClaude Fable 5.1 da27435cdb server: import the duel server (nanahira/ygopro server at 52c868ce)
The server tree of https://code.moenext.com/nanahira/ygopro.git, branch
server, commit 52c868ce071ea0f2fcb0cf39bf2fb4151d12b90c, stock: gframe/,
premake5.lua, .ci/, LICENSE, and gframe/ygopro.rc + .ico (upstream keeps
them in resource/ and copies them in before building). No game assets, no
scripts, no ocgcore submodule: the core is ../core.

The third-party sources upstream's Windows CI downloads are vendored here
at the positions its premake expects, each with its premake fragment from
upstream's premake/ folder inside it: lua 5.4.8, sqlite 3.53.3, libevent
2.1.13-stable (tests, samples and autotools helpers left out; the files
its Windows prebuild copies into include/ left out), zlib 1.3.2 (contrib
and examples left out), xz 5.8.3 (src/liblzma + src/common only), and
irrlicht 1.9 from mycard at 20f86d25: include/ plus the source/Irrlicht
headers and the 11 .cpp files the server's zip reader project compiles.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-14 20:58:21 -07:00

214 lines
5.4 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
//\param ext0, ext1, ext2 should be extension without dot (like "abc")
//\return 0 when extension was not found otherwise index of first extension
//! 1 = ext0, 2 = ext1, 3 = ext2
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
//\param ext0, ext1, ext2 should be extension without dot (like "abc")
//\return true when filename has any of the given extensions
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;
}
//! get source file path without filename extension
/** Example: If source is "path/file.abc" then dest returns "path/file" */
inline io::path& cutFilenameExtension ( io::path &dest, const io::path &source )
{
const s32 endPos = source.findLast ( '.' );
dest = source.subString ( 0, endPos < 0 ? source.size () : endPos );
return dest;
}
//! get the filename extension from a file path
/** Example: If source is "path/file.abc" then dest returns ".abc" */
inline io::path& getFileNameExtension ( io::path &dest, const io::path &source )
{
const s32 endPos = source.findLast ( '.' );
if ( endPos < 0 )
dest = "";
else
dest = source.subString ( endPos, source.size () );
return dest;
}
//! delete path from filename
/** Example: "c:/path/subpath/file.abc" returns "file.abc" */
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() )
{
const 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