CrystalSpace

Public API Reference

csutil/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 
00040 CS_CRYSTALSPACE_EXPORT char *csStrNew (const char *s);
00045 CS_CRYSTALSPACE_EXPORT char *csStrNew (const wchar_t *s);
00049 CS_CRYSTALSPACE_EXPORT wchar_t* csStrNewW (const wchar_t *s);
00054 CS_CRYSTALSPACE_EXPORT wchar_t* csStrNewW (const char *s);
00055 
00062 CS_CRYSTALSPACE_EXPORT int csStrCaseCmp(char const* str1, char const* str2);
00063 
00071 CS_CRYSTALSPACE_EXPORT int csStrNCaseCmp(char const* str1, char const* str2,
00072   size_t n);
00073 
00087 struct csWtoC
00088 {
00089 private:
00090   char* s;
00091 public:
00096   csWtoC (const wchar_t* ws)
00097   { s = csStrNew (ws); }
00101   ~csWtoC ()
00102   { delete[] s; }
00106   operator const char* () const
00107   { return s; }
00108 };
00109 
00117 struct csCtoW
00118 {
00119 private:
00120   wchar_t* ws;
00121 public:
00126   csCtoW (const char* s)
00127   { ws = csStrNewW (s); }
00131   ~csCtoW ()
00132   { delete[] ws; }
00136   operator const wchar_t* () const
00137   { return ws; }
00138 };
00139 
00149 CS_CRYSTALSPACE_EXPORT char *csExpandName (const char *iName);
00150 
00154 CS_CRYSTALSPACE_EXPORT void csSplitPath (const char *iPathName, char *oPath,
00155   size_t iPathSize, char *oName, size_t iNameSize);
00156 
00165 CS_CRYSTALSPACE_EXPORT bool csGlobMatches (const char *fName,
00166         const char *fMask);
00167 
00172 CS_CRYSTALSPACE_EXPORT int csFindNearestPowerOf2 (int n);
00173 
00175 CS_CRYSTALSPACE_EXPORT bool csIsPowerOf2 (int n);
00176 
00178 static inline int csLog2 (int n)
00179 {
00180   const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
00181   const unsigned int S[] = {1, 2, 4, 8, 16};
00182   int i;
00183 
00184   register unsigned int c = 0; // result of log2(v) will go here
00185   for (i = 4; i >= 0; i--) // unroll for speed...
00186   {
00187     if (n & b[i])
00188     {
00189       n >>= S[i];
00190       c |= S[i];
00191     } 
00192   }
00193   return c;
00194 }
00195 
00201 CS_CRYSTALSPACE_EXPORT void csReplaceAll (char *dest, const char *src,
00202   const char *search, const char *replace, int max);
00203 
00210 CS_DEPRECATED_METHOD_MSG("Use csReplaceAll() instead.")
00211 inline void csFindReplace (char *dest, const char *src,
00212   const char *search, const char *replace, int max)
00213 { csReplaceAll(dest, src, search, replace, max); }
00214 
00217 #endif // __CS_UTIL_H__

Generated for Crystal Space by doxygen 1.4.7