# 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
    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::stringstream 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
    00122         static Real toReal( const String& str );
    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);
    00141
    00147         static void splitFilename(const String& qualifiedName,
    00148             String& outBasename, String& outPath);
    00149
    00155         static bool match(const String& str, const String& pattern, bool caseSensitive = true);
    00156
    00157
    00158
    00159
    00160
    00162         static const String BLANK;
    00163     };
    00164
    00165
    00166 #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310
    00167     typedef ::__gnu_cxx::hash< _StringBase > _StringHash;
    00168 #elif !defined( _STLP_HASH_FUN_H )
    00169 #   if _DEFINE_DEPRECATED_HASH_CLASSES
    00170         typedef std::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
    00171 #   else
    00172         typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
    00173 #   endif
    00174 #else
    00175     typedef std::hash< _StringBase > _StringHash;
    00176 #endif
    00177
    00178 } // namespace Ogre
    00179
    00180 #endif // _String_H__

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Nov 20 12:36:07 2005