00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef _String_H__ 00029 #define _String_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 00033 // If we're using the GCC 3.1 C++ Std lib 00034 #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT) 00035 00036 // For gcc 4.3 see http://gcc.gnu.org/gcc-4.3/changes.html 00037 # if OGRE_COMP_VER >= 430 00038 # include <tr1/unordered_map> 00039 # else 00040 # include <ext/hash_map> 00041 namespace __gnu_cxx 00042 { 00043 template <> struct hash< Ogre::_StringBase > 00044 { 00045 size_t operator()( const Ogre::_StringBase _stringBase ) const 00046 { 00047 /* This is the PRO-STL way, but it seems to cause problems with VC7.1 00048 and in some other cases (although I can't recreate it) 00049 hash<const char*> H; 00050 return H(_stringBase.c_str()); 00051 */ 00053 register size_t ret = 0; 00054 for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it ) 00055 ret = 5 * ret + *it; 00056 00057 return ret; 00058 } 00059 }; 00060 } 00061 # endif 00062 00063 #endif 00064 00065 namespace Ogre { 00074 class _OgreExport StringUtil 00075 { 00076 public: 00077 typedef StringStream StrStreamType; 00078 00086 static void trim( String& str, bool left = true, bool right = true ); 00087 00098 static vector<String>::type split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0, bool preserveDelims = false); 00099 00112 static vector<String>::type tokenise( const String& str, const String& delims = "\t\n ", const String& doubleDelims = "\"", unsigned int maxSplits = 0); 00113 00116 static void toLowerCase( String& str ); 00117 00120 static void toUpperCase( String& str ); 00121 00122 00128 static bool startsWith(const String& str, const String& pattern, bool lowerCase = true); 00129 00135 static bool endsWith(const String& str, const String& pattern, bool lowerCase = true); 00136 00139 static String standardisePath( const String &init); 00151 static String normalizeFilePath(const String& init, bool makeLowerCase = true); 00152 00153 00159 static void splitFilename(const String& qualifiedName, 00160 String& outBasename, String& outPath); 00161 00167 static void splitFullFilename(const Ogre::String& qualifiedName, 00168 Ogre::String& outBasename, Ogre::String& outExtention, 00169 Ogre::String& outPath); 00170 00174 static void splitBaseFilename(const Ogre::String& fullName, 00175 Ogre::String& outBasename, Ogre::String& outExtention); 00176 00177 00183 static bool match(const String& str, const String& pattern, bool caseSensitive = true); 00184 00185 00192 static const String replaceAll(const String& source, const String& replaceWhat, const String& replaceWithWhat); 00193 00195 static const String BLANK; 00196 }; 00197 00198 00199 #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT) 00200 # if OGRE_COMP_VER < 430 00201 typedef ::__gnu_cxx::hash< _StringBase > _StringHash; 00202 # else 00203 typedef ::std::tr1::hash< _StringBase > _StringHash; 00204 # endif 00205 #elif OGRE_COMPILER == OGRE_COMPILER_CLANG 00206 # if defined(_LIBCPP_VERSION) 00207 typedef ::std::hash< _StringBase > _StringHash; 00208 # else 00209 typedef ::std::tr1::hash< _StringBase > _StringHash; 00210 # endif 00211 #elif OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1600 && !defined(STLPORT) // VC++ 10.0 00212 typedef ::std::tr1::hash< _StringBase > _StringHash; 00213 #elif !defined( _STLP_HASH_FUN_H ) 00214 typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash; 00215 #else 00216 typedef std::hash< _StringBase > _StringHash; 00217 #endif 00218 00221 } // namespace Ogre 00222 00223 #endif // _String_H__
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:27 2012