Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreString.h

Go to the documentation of this file.
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-2005 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef _String_H__
00026 #define _String_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 
00030 // If we're using the GCC 3.1 C++ Std lib
00031 #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT)
00032 
00033 #include <ext/hash_map>
00034 namespace __gnu_cxx
00035 {
00036     template <> struct hash< Ogre::_StringBase >
00037     {
00038         size_t operator()( const Ogre::_StringBase _stringBase ) const
00039         {
00040             /* This is the PRO-STL way, but it seems to cause problems with VC7.1
00041                and in some other cases (although I can't recreate it)
00042             hash<const char*> H;
00043             return H(_stringBase.c_str());
00044             */
00046             register size_t ret = 0;
00047             for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it )
00048                 ret = 5 * ret + *it;
00049 
00050             return ret;
00051         }
00052     };
00053 }
00054 
00055 // If we're using plain vanilla VC7 Std lib
00056 #elif !defined( _STLP_HASH_FUN_H )
00057 
00058 #   if _DEFINE_DEPRECATED_HASH_CLASSES
00059 namespace std
00060 #   else
00061 namespace stdext
00062 #   endif
00063 {
00064     template<> size_t hash_compare< Ogre::_StringBase, std::less< Ogre::_StringBase > >::operator ()( const Ogre::_StringBase& _stringBase ) const
00065     {
00066         /* This is the PRO-STL way, but it seems to cause problems with VC7.1
00067             and in some other cases (although I can't recreate it)
00068         hash<const char*> H;
00069         return H(_stringBase.c_str());
00070         */
00072         register size_t ret = 0;
00073         for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it )
00074             ret = 5 * ret + *it;
00075 
00076         return ret;
00077     }
00078 }
00079 
00080 #endif
00081 
00082 namespace Ogre {
00083 
00085     class _OgreExport StringUtil
00086     {
00087     public:
00088         typedef std::ostringstream StrStreamType;
00089 
00097         static void trim( String& str, bool left = true, bool right = true );
00098 
00107         static std::vector< String > split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0);
00108 
00111         static void toLowerCase( String& str );
00112 
00115         static void toUpperCase( String& str );
00116 
00117 
00123         static bool startsWith(const String& str, const String& pattern, bool lowerCase = true);
00124 
00130         static bool endsWith(const String& str, const String& pattern, bool lowerCase = true);
00131 
00134         static String standardisePath( const String &init);
00135 
00141         static void splitFilename(const String& qualifiedName,
00142             String& outBasename, String& outPath);
00143 
00149         static bool match(const String& str, const String& pattern, bool caseSensitive = true);
00150 
00151 
00152 
00153 
00154 
00156         static const String BLANK;
00157     };
00158 
00159 
00160 #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT)
00161     typedef ::__gnu_cxx::hash< _StringBase > _StringHash;
00162 #elif !defined( _STLP_HASH_FUN_H )
00163 #   if _DEFINE_DEPRECATED_HASH_CLASSES
00164         typedef std::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
00165 #   else
00166         typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
00167 #   endif
00168 #else
00169     typedef std::hash< _StringBase > _StringHash;
00170 #endif
00171 
00172 } // namespace Ogre
00173 
00174 #endif // _String_H__

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:50 2006