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-2013 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 #include "OgreHeaderPrefix.h" 00033 00034 // If we're using the GCC 3.1 C++ Std lib 00035 #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT) 00036 00037 // For gcc 4.3 see http://gcc.gnu.org/gcc-4.3/changes.html 00038 # if OGRE_COMP_VER >= 430 00039 # include <tr1/unordered_map> 00040 # else 00041 # include <ext/hash_map> 00042 namespace __gnu_cxx 00043 { 00044 template <> struct hash< Ogre::_StringBase > 00045 { 00046 size_t operator()( const Ogre::_StringBase _stringBase ) const 00047 { 00048 /* This is the PRO-STL way, but it seems to cause problems with VC7.1 00049 and in some other cases (although I can't recreate it) 00050 hash<const char*> H; 00051 return H(_stringBase.c_str()); 00052 */ 00054 register size_t ret = 0; 00055 for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it ) 00056 ret = 5 * ret + *it; 00057 00058 return ret; 00059 } 00060 }; 00061 } 00062 # endif 00063 00064 #endif 00065 00066 namespace Ogre { 00075 class _OgreExport StringUtil 00076 { 00077 public: 00078 typedef StringStream StrStreamType; 00079 00087 static void trim( String& str, bool left = true, bool right = true ); 00088 00099 static vector<String>::type split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0, bool preserveDelims = false); 00100 00113 static vector<String>::type tokenise( const String& str, const String& delims = "\t\n ", const String& doubleDelims = "\"", unsigned int maxSplits = 0); 00114 00117 static void toLowerCase( String& str ); 00118 00121 static void toUpperCase( String& str ); 00122 00123 00129 static bool startsWith(const String& str, const String& pattern, bool lowerCase = true); 00130 00136 static bool endsWith(const String& str, const String& pattern, bool lowerCase = true); 00137 00140 static String standardisePath( const String &init); 00152 static String normalizeFilePath(const String& init, bool makeLowerCase = true); 00153 00154 00160 static void splitFilename(const String& qualifiedName, 00161 String& outBasename, String& outPath); 00162 00168 static void splitFullFilename(const Ogre::String& qualifiedName, 00169 Ogre::String& outBasename, Ogre::String& outExtention, 00170 Ogre::String& outPath); 00171 00175 static void splitBaseFilename(const Ogre::String& fullName, 00176 Ogre::String& outBasename, Ogre::String& outExtention); 00177 00178 00184 static bool match(const String& str, const String& pattern, bool caseSensitive = true); 00185 00186 00193 static const String replaceAll(const String& source, const String& replaceWhat, const String& replaceWithWhat); 00194 00196 static const String BLANK; 00197 }; 00198 00199 00200 #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT) 00201 # if OGRE_COMP_VER < 430 00202 typedef ::__gnu_cxx::hash< _StringBase > _StringHash; 00203 # else 00204 typedef ::std::tr1::hash< _StringBase > _StringHash; 00205 # endif 00206 #elif OGRE_COMPILER == OGRE_COMPILER_CLANG 00207 # if defined(_LIBCPP_VERSION) 00208 typedef ::std::hash< _StringBase > _StringHash; 00209 # else 00210 typedef ::std::tr1::hash< _StringBase > _StringHash; 00211 # endif 00212 #elif OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1600 && !defined(STLPORT) // VC++ 10.0 00213 typedef ::std::tr1::hash< _StringBase > _StringHash; 00214 #elif !defined( _STLP_HASH_FUN_H ) 00215 typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash; 00216 #else 00217 typedef std::hash< _StringBase > _StringHash; 00218 #endif 00219 00222 } // namespace Ogre 00223 00224 #include "OgreHeaderSuffix.h" 00225 00226 #if OGRE_DEBUG_MODE && (OGRE_PLATFORM == OGRE_PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WINRT) 00227 # pragma push_macro("NOMINMAX") 00228 # define NOMINMAX 00229 # include <windows.h> 00230 # pragma pop_macro("NOMINMAX") 00231 # define Ogre_OutputCString(str) ::OutputDebugStringA(str) 00232 # define Ogre_OutputWString(str) ::OutputDebugStringW(str) 00233 #else 00234 # define Ogre_OutputCString(str) std::cerr << str 00235 # define Ogre_OutputWString(str) std::cerr << str 00236 #endif 00237 00238 #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 Mon Jul 27 2020 13:40:47