Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreString.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 9.3 KB
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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef _String_H__
29#define _String_H__
30
31#include "OgrePrerequisites.h"
32#include "OgreHeaderPrefix.h"
33
34// If we're using the GCC 3.1 C++ Std lib
35#if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT)
36
37// For gcc 4.3 see http://gcc.gnu.org/gcc-4.3/changes.html
38#   if OGRE_COMP_VER >= 430
39#       include <tr1/unordered_map>
40#   else
41#       include <ext/hash_map>
42namespace __gnu_cxx
43{
44    template <> struct hash< Ogre::_StringBase >
45    {
46        size_t operator()( const Ogre::_StringBase _stringBase ) const
47        {
48            /* This is the PRO-STL way, but it seems to cause problems with VC7.1
49               and in some other cases (although I can't recreate it)
50            hash<const char*> H;
51            return H(_stringBase.c_str());
52            */
53            /** This is our custom way */
54            register size_t ret = 0;
55            for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it )
56                ret = 5 * ret + *it;
57
58            return ret;
59        }
60    };
61}
62#   endif
63
64#endif
65
66namespace Ogre {
67        /** \addtogroup Core
68        *  @{
69        */
70        /** \addtogroup General
71        *  @{
72        */
73
74    /** Utility class for manipulating Strings.  */
75    class _OgreExport StringUtil
76    {
77        public:
78                typedef StringStream StrStreamType;
79
80        /** Removes any whitespace characters, be it standard space or
81            TABs and so on.
82            @remarks
83                The user may specify whether they want to trim only the
84                beginning or the end of the String ( the default action is
85                to trim both).
86        */
87        static void trim( String& str, bool left = true, bool right = true );
88
89        /** Returns a StringVector that contains all the substrings delimited
90            by the characters in the passed <code>delims</code> argument.
91            @param
92                delims A list of delimiter characters to split by
93            @param
94                maxSplits The maximum number of splits to perform (0 for unlimited splits). If this
95                parameters is > 0, the splitting process will stop after this many splits, left to right.
96            @param
97                preserveDelims Flag to determine if delimiters should be saved as substrings
98        */
99                static vector<String>::type split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0, bool preserveDelims = false);
100
101                /** Returns a StringVector that contains all the substrings delimited
102            by the characters in the passed <code>delims</code> argument,
103                        or in the <code>doubleDelims</code> argument, which is used to include (normal)
104                        delimeters in the tokenised string. For example, "strings like this".
105            @param
106                delims A list of delimiter characters to split by
107                        @param
108                doubleDelims A list of double delimeters characters to tokenise by
109            @param
110                maxSplits The maximum number of splits to perform (0 for unlimited splits). If this
111                parameters is > 0, the splitting process will stop after this many splits, left to right.
112        */
113                static vector<String>::type tokenise( const String& str, const String& delims = "\t\n ", const String& doubleDelims = "\"", unsigned int maxSplits = 0);
114
115                /** Lower-cases all the characters in the string.
116        */
117        static void toLowerCase( String& str );
118
119        /** Upper-cases all the characters in the string.
120        */
121        static void toUpperCase( String& str );
122
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 start 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                /** Returns a normalized version of a file path
142                This method can be used to make file path strings which point to the same directory 
143                but have different texts to be normalized to the same text. The function:
144                - Transforms all backward slashes to forward slashes.
145                - Removes repeating slashes.
146                - Removes initial slashes from the beginning of the path.
147                - Removes ".\" and "..\" meta directories.
148                - Sets all characters to lowercase (if requested)
149                @param init The file path to normalize.
150                @param makeLowerCase If true, transforms all characters in the string to lowercase.
151                */
152       static String normalizeFilePath(const String& init, bool makeLowerCase = true);
153
154
155        /** Method for splitting a fully qualified filename into the base name
156            and path.
157        @remarks
158            Path is standardised as in standardisePath
159        */
160        static void splitFilename(const String& qualifiedName,
161            String& outBasename, String& outPath);
162
163                /** Method for splitting a fully qualified filename into the base name,
164                extension and path.
165                @remarks
166                Path is standardised as in standardisePath
167                */
168                static void splitFullFilename(const Ogre::String& qualifiedName, 
169                        Ogre::String& outBasename, Ogre::String& outExtention, 
170                        Ogre::String& outPath);
171
172                /** Method for splitting a filename into the base name
173                and extension.
174                */
175                static void splitBaseFilename(const Ogre::String& fullName, 
176                        Ogre::String& outBasename, Ogre::String& outExtention);
177
178
179        /** Simple pattern-matching routine allowing a wildcard pattern.
180        @param str String to test
181        @param pattern Pattern to match against; can include simple '*' wildcards
182        @param caseSensitive Whether the match is case sensitive or not
183        */
184        static bool match(const String& str, const String& pattern, bool caseSensitive = true);
185
186
187                /** replace all instances of a sub-string with a another sub-string.
188                @param source Source string
189                @param replaceWhat Sub-string to find and replace
190                @param replaceWithWhat Sub-string to replace with (the new sub-string)
191                @return An updated string with the sub-string replaced
192                */
193                static const String replaceAll(const String& source, const String& replaceWhat, const String& replaceWithWhat);
194
195        /// Constant blank string, useful for returning by ref where local does not exist
196        static const String BLANK;
197    };
198
199
200#if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT)
201#   if OGRE_COMP_VER < 430
202        typedef ::__gnu_cxx::hash< _StringBase > _StringHash;
203#   else
204        typedef ::std::tr1::hash< _StringBase > _StringHash;
205#   endif
206#elif OGRE_COMPILER == OGRE_COMPILER_CLANG
207#   if defined(_LIBCPP_VERSION)
208        typedef ::std::hash< _StringBase > _StringHash;
209#   else
210        typedef ::std::tr1::hash< _StringBase > _StringHash;
211#   endif
212#elif OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1600 && !defined(STLPORT) // VC++ 10.0
213        typedef ::std::tr1::hash< _StringBase > _StringHash;
214#elif !defined( _STLP_HASH_FUN_H )
215        typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
216#else
217        typedef std::hash< _StringBase > _StringHash;
218#endif
219        /** @} */
220        /** @} */
221
222} // namespace Ogre
223
224#include "OgreHeaderSuffix.h"
225
226#if OGRE_DEBUG_MODE && (OGRE_PLATFORM == OGRE_PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WINRT)
227#   pragma push_macro("NOMINMAX")
228#   define NOMINMAX
229#   include <windows.h>
230#   pragma pop_macro("NOMINMAX")
231#       define Ogre_OutputCString(str) ::OutputDebugStringA(str)
232#       define Ogre_OutputWString(str) ::OutputDebugStringW(str)
233#else
234#       define Ogre_OutputCString(str) std::cerr << str
235#       define Ogre_OutputWString(str) std::cerr << str
236#endif
237
238#endif // _String_H__
Note: See TracBrowser for help on using the repository browser.