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); 00046 CS_CRYSTALSPACE_EXPORT char *csStrNew (const wchar_t *s); 00052 CS_CRYSTALSPACE_EXPORT wchar_t* csStrNewW (const wchar_t *s); 00058 CS_CRYSTALSPACE_EXPORT wchar_t* csStrNewW (const char *s); 00059 00060 namespace CS 00061 { 00070 CS_CRYSTALSPACE_EXPORT char* StrDup (const char *s); 00076 CS_CRYSTALSPACE_EXPORT char* StrDup (const wchar_t *s); 00082 CS_CRYSTALSPACE_EXPORT wchar_t* StrDupW (const wchar_t *s); 00088 CS_CRYSTALSPACE_EXPORT wchar_t* StrDupW (const char *s); 00089 } 00090 00097 CS_CRYSTALSPACE_EXPORT int csStrCaseCmp(char const* str1, char const* str2); 00098 00106 CS_CRYSTALSPACE_EXPORT int csStrNCaseCmp(char const* str1, char const* str2, 00107 size_t n); 00108 00122 struct csWtoC 00123 { 00124 private: 00125 char* s; 00126 public: 00131 csWtoC (const wchar_t* ws) 00132 { s = csStrNew (ws); } 00136 ~csWtoC () 00137 { delete[] s; } 00141 operator const char* () const 00142 { return s; } 00143 }; 00144 00152 struct csCtoW 00153 { 00154 private: 00155 wchar_t* ws; 00156 public: 00161 csCtoW (const char* s) 00162 { ws = csStrNewW (s); } 00166 ~csCtoW () 00167 { delete[] ws; } 00171 operator const wchar_t* () const 00172 { return ws; } 00173 }; 00174 00184 CS_CRYSTALSPACE_EXPORT char *csExpandName (const char *iName); 00185 00189 CS_CRYSTALSPACE_EXPORT void csSplitPath (const char *iPathName, char *oPath, 00190 size_t iPathSize, char *oName, size_t iNameSize); 00191 00200 CS_CRYSTALSPACE_EXPORT bool csGlobMatches (const char *fName, 00201 const char *fMask); 00202 00207 static inline int csFindNearestPowerOf2 (int n) 00208 { 00209 int v=n; 00210 00211 v--; 00212 v |= v >> 1; 00213 v |= v >> 2; 00214 v |= v >> 4; 00215 v |= v >> 8; 00216 v |= v >> 16; 00217 v++; 00218 00219 return v; 00220 } 00221 00223 static inline bool csIsPowerOf2 (int n) 00224 { 00225 return !(n & (n - 1)) && n; // (n-1) ^ n >= n; 00226 } 00227 00229 CS_CRYSTALSPACE_EXPORT int csLog2 (int n); 00230 00236 CS_CRYSTALSPACE_EXPORT void csReplaceAll (char *dest, const char *src, 00237 const char *search, const char *replace, int max); 00238 00239 00242 #endif // __CS_UTIL_H__
Generated for Crystal Space 1.2 by doxygen 1.4.7