# 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _String_H__
    00030 #define _String_H__
    00031
    00032 #include "OgrePrerequisites.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 {
    00067
    00069     class _OgreExport StringUtil
    00070     {
    00071     public:
    00072         typedef std::ostringstream StrStreamType;
    00073
    00081         static void trim( String& str, bool left = true, bool right = true );
    00082
    00091         static std::vector< String > split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0);
    00092
    00095         static void toLowerCase( String& str );
    00096
    00099         static void toUpperCase( String& str );
    00100
    00101
    00107         static bool startsWith(const String& str, const String& pattern, bool lowerCase = true);
    00108
    00114         static bool endsWith(const String& str, const String& pattern, bool lowerCase = true);
    00115
    00118         static String standardisePath( const String &init);
    00119
    00125         static void splitFilename(const String& qualifiedName,
    00126             String& outBasename, String& outPath);
    00127
    00133         static void splitFullFilename(const Ogre::String& qualifiedName,
    00134             Ogre::String& outBasename, Ogre::String& outExtention,
    00135             Ogre::String& outPath);
    00136
    00140         static void splitBaseFilename(const Ogre::String& fullName,
    00141             Ogre::String& outBasename, Ogre::String& outExtention);
    00142
    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 #   if OGRE_COMP_VER < 430
    00162     typedef ::__gnu_cxx::hash< _StringBase > _StringHash;
    00163 #   else
    00164     typedef ::std::tr1::hash< _StringBase > _StringHash;
    00165 #   endif
    00166 #elif OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1600 && !defined(STLPORT) // VC++ 10.0
    00167     typedef ::std::tr1::hash< _StringBase > _StringHash;
    00168 #elif !defined( _STLP_HASH_FUN_H )
    00169     typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
    00170 #else
    00171     typedef std::hash< _StringBase > _StringHash;
    00172 #endif
    00173
    00174 } // namespace Ogre
    00175
    00176 #endif // _String_H__

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:20 2009