source: OGRE/trunk/ogrenew/OgreMain/include/OgreString.h @ 657

Revision 657, 6.7 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef _String_H__
26#define _String_H__
27
28#include "OgrePrerequisites.h"
29
30// If we're using the GCC 3.1 C++ Std lib
31#if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310
32
33#include <ext/hash_map>
34namespace __gnu_cxx
35{
36    template <> struct hash< Ogre::_StringBase >
37    {
38        size_t operator()( const Ogre::_StringBase _stringBase ) const
39        {
40            /* This is the PRO-STL way, but it seems to cause problems with VC7.1
41               and in some other cases (although I can't recreate it)
42            hash<const char*> H;
43            return H(_stringBase.c_str());
44            */
45            /** This is our custom way */
46            register size_t ret = 0;
47            for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it )
48                ret = 5 * ret + *it;
49
50            return ret;
51        }
52    };
53}
54
55// If we're using plain vanilla VC7 Std lib
56#elif !defined( _STLP_HASH_FUN_H )
57
58#       if _DEFINE_DEPRECATED_HASH_CLASSES
59namespace std
60#       else
61namespace stdext
62#       endif
63{
64    template<> size_t hash_compare< Ogre::_StringBase, std::less< Ogre::_StringBase > >::operator ()( const Ogre::_StringBase& _stringBase ) const
65    {
66        /* This is the PRO-STL way, but it seems to cause problems with VC7.1
67            and in some other cases (although I can't recreate it)
68        hash<const char*> H;
69        return H(_stringBase.c_str());
70        */
71        /** This is our custom way */
72        register size_t ret = 0;
73        for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it )
74            ret = 5 * ret + *it;
75
76        return ret;
77    }
78}
79
80#endif
81
82namespace Ogre {
83
84    /** Utility class for manipulating Strings.  */
85    class _OgreExport StringUtil
86    {
87        public:
88        typedef std::ostringstream StrStreamType;
89
90        /** Removes any whitespace characters, be it standard space or
91            TABs and so on.
92            @remarks
93                The user may specify wether they want to trim only the
94                beginning or the end of the String ( the default action is
95                to trim both).
96        */
97        static void trim( String& str, bool left = true, bool right = true );
98
99        /** Returns a StringVector that contains all the substrings delimited
100            by the characters in the passed <code>delims</code> argument.
101            @param
102                delims A list of delimiter characters to split by
103            @param
104                maxSplits The maximum number of splits to perform (0 for unlimited splits). If this
105                parameters is > 0, the splitting process will stop after this many splits, left to right.
106        */
107                static std::vector< String > split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0);
108
109        /** Upper-cases all the characters in the string.
110        */
111        static void toLowerCase( String& str );
112
113        /** Lower-cases all the characters in the string.
114        */
115        static void toUpperCase( String& str );
116
117        /** Converts the contents of the string to a Real.
118        @remarks
119            Assumes the only contents of the string are a valid parsable Real. Defaults to  a
120            value of 0.0 if conversion is not possible.
121        */
122        static Real toReal( const String& str );
123
124        /** Returns whether the string begins with the pattern passed in.
125        @param pattern The pattern to compare with.
126        @param lowerCase If true, the end of the string will be lower cased before
127            comparison, pattern should also be in lower case.
128        */
129        static bool startsWith(const String& str, const String& pattern, bool lowerCase = true);
130
131        /** Returns whether the string ends with the pattern passed in.
132        @param pattern The pattern to compare with.
133        @param lowerCase If true, the end of the string will be lower cased before
134            comparison, pattern should also be in lower case.
135        */
136        static bool endsWith(const String& str, const String& pattern, bool lowerCase = true);
137
138        /** Method for standardising paths - use forward slashes only, end with slash.
139        */
140        static String standardisePath( const String &init);
141
142        /** Method for splitting a fully qualified filename into the base name
143            and path.
144        @remarks
145            Path is standardised as in standardisePath
146        */
147        static void splitFilename(const String& qualifiedName,
148            String& outBasename, String& outPath);
149
150        /** Simple pattern-matching routine allowing a wildcard pattern.
151        @param str String to test
152        @param pattern Pattern to match against; can include simple '*' wildcards
153        @param caseSensitive Whether the match is case sensitive or not
154        */
155        static bool match(const String& str, const String& pattern, bool caseSensitive = true);
156           
157
158
159
160
161        /// Constant blank string, useful for returning by ref where local does not exist
162        static const String BLANK;
163    };
164
165
166#if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310
167    typedef ::__gnu_cxx::hash< _StringBase > _StringHash;   
168#elif !defined( _STLP_HASH_FUN_H )
169#       if _DEFINE_DEPRECATED_HASH_CLASSES
170                typedef std::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
171#       else
172                typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
173#       endif
174#else
175    typedef std::hash< _StringBase > _StringHash;
176#endif
177
178} // namespace Ogre
179
180#endif // _String_H__
Note: See TracBrowser for help on using the repository browser.