CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

util.h File Reference

More...

#include <stdio.h>

Go to the source code of this file.

Functions

char * csStrNew (const char *s)
 Allocate a new char [] and copy the string into newly allocated storage. More...

char * csExpandName (const char *iName)
 Expand a filename if it contains shortcuts. More...

void csSplitPath (const char *iPathName, char *oPath, size_t iPathSize, char *oName, size_t iNameSize)
 Split a pathname into separate path and name. More...

bool csGlobMatches (const char *fName, const char *fMask)
 This is a really simple function that does very nice "filename against filemask" comparisons. More...

int csFindNearestPowerOf2 (int n)
 Finds the smallest number that is a power of two and is larger or equal to n. More...

bool csIsPowerOf2 (int n)
 returns true if n is a power of two. More...

int csLog2 (int n)
 Find the log2 of argument. More...

void csFindReplace (char *dest, const char *src, const char *search, const char *replace, int max)
 given src and dest, which are already allocated, copy source to dest. More...


Detailed Description

Definition in file util.h.


Function Documentation

char* csExpandName (  const char *    iName ) 
 

Expand a filename if it contains shortcuts.

Currently the following macros are recognised and expanded:

 '.', '~', '..', 'drive:' (on DOS/Win32/OS2)
 
The returned filename is always absolute, i.e. it always starts from root. Return a string allocated with csStrNew().

int csFindNearestPowerOf2 (  int    n ) 
 

Finds the smallest number that is a power of two and is larger or equal to n.

void csFindReplace (  char *    dest,
const char *    src,
const char *    search,
const char *    replace,
int    max
) 
 

given src and dest, which are already allocated, copy source to dest.

But, do not copy 'search', instead replace that with 'replace' string. max is size of dest.

bool csGlobMatches (  const char *    fName,
const char *    fMask
) 
 

This is a really simple function that does very nice "filename against filemask" comparisons.

It understands even such things like "*a*.txt" or "*a?b*" or even "*" (wish I DOS could do it ...). No "[]" wildcards though :-)

NOTE: If you want case-insensitive comparison, upcase strings first.

bool csIsPowerOf2 (  int    n ) 
 

returns true if n is a power of two.

int csLog2 (  int    n )  [inline, static]
 

Find the log2 of argument.

Definition at line 73 of file util.h.

void csSplitPath (  const char *    iPathName,
char *    oPath,
size_t    iPathSize,
char *    oName,
size_t    iNameSize
) 
 

Split a pathname into separate path and name.

Path delimiters are either '/', PATH_SEPARATOR and, for OS/2, MS-DOS and Win32 targets, ':'.

char* csStrNew (  const char *    s ) 
 

Allocate a new char [] and copy the string into newly allocated storage.

This is a handy method for copying strings, in fact it is the C++ analogue of the strdup() function from string.h (strdup() is not present on some platforms). To free the pointer the caller should call delete[].

Referenced by csVariant::SetString.


Generated for Crystal Space by doxygen 1.2.14