CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

util.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 1998 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_UTIL_H__
00020 #define __CS_UTIL_H__
00021 
00022 #include <stdio.h>
00023 #include "csextern.h"
00024 #include "csutil/csunicode.h"
00025 
00039 CS_CRYSTALSPACE_EXPORT char *csStrNew (const char *s);
00044 CS_CRYSTALSPACE_EXPORT char *csStrNew (const wchar_t *s);
00048 CS_CRYSTALSPACE_EXPORT wchar_t* csStrNewW (const wchar_t *s);
00053 CS_CRYSTALSPACE_EXPORT wchar_t* csStrNewW (const char *s);
00054 
00061 CS_CRYSTALSPACE_EXPORT int csStrCaseCmp(char const* str1, char const* str2);
00062 
00070 CS_CRYSTALSPACE_EXPORT int csStrNCaseCmp(char const* str1, char const* str2,
00071   size_t n);
00072 
00086 struct csWtoC
00087 {
00088 private:
00089   char* s;
00090 public:
00095   csWtoC (const wchar_t* ws)
00096   { s = csStrNew (ws); }
00100   ~csWtoC ()
00101   { delete[] s; }
00105   operator const char* () const
00106   { return s; }
00107 };
00108 
00116 struct csCtoW
00117 {
00118 private:
00119   wchar_t* ws;
00120 public:
00125   csCtoW (const char* s)
00126   { ws = csStrNewW (s); }
00130   ~csCtoW ()
00131   { delete[] ws; }
00135   operator const wchar_t* () const
00136   { return ws; }
00137 };
00138 
00148 CS_CRYSTALSPACE_EXPORT char *csExpandName (const char *iName);
00149 
00153 CS_CRYSTALSPACE_EXPORT void csSplitPath (const char *iPathName, char *oPath,
00154   size_t iPathSize, char *oName, size_t iNameSize);
00155 
00164 CS_CRYSTALSPACE_EXPORT bool csGlobMatches (const char *fName, const char *fMask);
00165 
00170 CS_CRYSTALSPACE_EXPORT int csFindNearestPowerOf2 (int n);
00171 
00173 CS_CRYSTALSPACE_EXPORT bool csIsPowerOf2 (int n);
00174 
00176 static inline int csLog2 (int n)
00177 {
00178   const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
00179   const unsigned int S[] = {1, 2, 4, 8, 16};
00180   int i;
00181 
00182   register unsigned int c = 0; // result of log2(v) will go here
00183   for (i = 4; i >= 0; i--) // unroll for speed...
00184   {
00185     if (n & b[i])
00186     {
00187       n >>= S[i];
00188       c |= S[i];
00189     } 
00190   }
00191   return c;
00192 }
00193 
00199 CS_CRYSTALSPACE_EXPORT void csReplaceAll (char *dest, const char *src,
00200   const char *search, const char *replace, int max);
00201 
00208 CS_DEPRECATED_METHOD 
00209 inline void csFindReplace (char *dest, const char *src,
00210   const char *search, const char *replace, int max)
00211 { csReplaceAll(dest, src, search, replace, max); }
00212 
00215 #endif // __CS_UTIL_H__

Generated for Crystal Space by doxygen 1.4.4