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

Revision 692, 6.4 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

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 && !defined(STLPORT)
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
118        /** Returns whether the string begins with the pattern passed in.
119        @param pattern The pattern to compare with.
120        @param lowerCase If true, the end of the string will be lower cased before
121            comparison, pattern should also be in lower case.
122        */
123        static bool startsWith(const String& str, const String& pattern, bool lowerCase = true);
124
125        /** Returns whether the string ends with the pattern passed in.
126        @param pattern The pattern to compare with.
127        @param lowerCase If true, the end of the string will be lower cased before
128            comparison, pattern should also be in lower case.
129        */
130        static bool endsWith(const String& str, const String& pattern, bool lowerCase = true);
131
132        /** Method for standardising paths - use forward slashes only, end with slash.
133        */
134        static String standardisePath( const String &init);
135
136        /** Method for splitting a fully qualified filename into the base name
137            and path.
138        @remarks
139            Path is standardised as in standardisePath
140        */
141        static void splitFilename(const String& qualifiedName,
142            String& outBasename, String& outPath);
143
144        /** Simple pattern-matching routine allowing a wildcard pattern.
145        @param str String to test
146        @param pattern Pattern to match against; can include simple '*' wildcards
147        @param caseSensitive Whether the match is case sensitive or not
148        */
149        static bool match(const String& str, const String& pattern, bool caseSensitive = true);
150
151
152
153
154
155        /// Constant blank string, useful for returning by ref where local does not exist
156        static const String BLANK;
157    };
158
159
160#if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT)
161    typedef ::__gnu_cxx::hash< _StringBase > _StringHash;
162#elif !defined( _STLP_HASH_FUN_H )
163#       if _DEFINE_DEPRECATED_HASH_CLASSES
164                typedef std::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
165#       else
166                typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
167#       endif
168#else
169    typedef std::hash< _StringBase > _StringHash;
170#endif
171
172} // namespace Ogre
173
174#endif // _String_H__
Note: See TracBrowser for help on using the repository browser.