Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | 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 "csunicode.h" 00025 00039 extern CS_CSUTIL_EXPORT char *csStrNew (const char *s); 00044 extern CS_CSUTIL_EXPORT char *csStrNew (const wchar_t *s); 00048 extern CS_CSUTIL_EXPORT wchar_t* csStrNewW (const wchar_t *s); 00053 extern CS_CSUTIL_EXPORT wchar_t* csStrNewW (const char *s); 00054 00061 extern CS_CSUTIL_EXPORT int csStrCaseCmp(char const* str1, char const* str2); 00062 00070 extern CS_CSUTIL_EXPORT int csStrNCaseCmp(char const* str1, char const* str2, 00071 size_t n); 00072 00085 struct csWtoC 00086 { 00087 private: 00088 char* s; 00089 public: 00094 csWtoC (const wchar_t* ws) 00095 { s = csStrNew (ws); } 00099 ~csWtoC () 00100 { delete[] s; } 00104 operator const char* () const 00105 { return s; } 00106 }; 00107 00114 struct csCtoW 00115 { 00116 private: 00117 wchar_t* ws; 00118 public: 00123 csCtoW (const char* s) 00124 { ws = csStrNewW (s); } 00128 ~csCtoW () 00129 { delete[] ws; } 00133 operator const wchar_t* () const 00134 { return ws; } 00135 }; 00136 00146 extern CS_CSUTIL_EXPORT char *csExpandName (const char *iName); 00147 00151 extern CS_CSUTIL_EXPORT void csSplitPath (const char *iPathName, char *oPath, 00152 size_t iPathSize, char *oName, size_t iNameSize); 00153 00162 extern CS_CSUTIL_EXPORT bool csGlobMatches (const char *fName, const char *fMask); 00163 00168 CS_CSUTIL_EXPORT int csFindNearestPowerOf2 (int n); 00169 00171 CS_CSUTIL_EXPORT bool csIsPowerOf2 (int n); 00172 00174 static inline int csLog2 (int n) 00175 { 00176 const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000}; 00177 const unsigned int S[] = {1, 2, 4, 8, 16}; 00178 int i; 00179 00180 register unsigned int c = 0; // result of log2(v) will go here 00181 for (i = 4; i >= 0; i--) // unroll for speed... 00182 { 00183 if (n & b[i]) 00184 { 00185 n >>= S[i]; 00186 c |= S[i]; 00187 } 00188 } 00189 return c; 00190 } 00191 00197 CS_CSUTIL_EXPORT void csFindReplace (char *dest, const char *src, 00198 const char *search, const char *replace, int max); 00199 00202 #endif // __CS_UTIL_H__
Generated for Crystal Space by doxygen 1.3.9.1