OGRE  1.9.0
OgreString.h
Go to the documentation of this file.
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-2014 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 */
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 {
76 {
77 public:
79
87 static void trim( String& str, bool left = true, bool right = true );
88
99 static vector<String>::type split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0, bool preserveDelims = false);
100
113 static vector<String>::type tokenise( const String& str, const String& delims = "\t\n ", const String& doubleDelims = "\"", unsigned int maxSplits = 0);
114
117 static void toLowerCase( String& str );
118
121 static void toUpperCase( String& str );
122
123
129 static bool startsWith(const String& str, const String& pattern, bool lowerCase = true);
130
136 static bool endsWith(const String& str, const String& pattern, bool lowerCase = true);
137
140 static String standardisePath( const String &init);
152 static String normalizeFilePath(const String& init, bool makeLowerCase = true);
153
154
160 static void splitFilename(const String& qualifiedName,
161 String& outBasename, String& outPath);
162
168 static void splitFullFilename(const Ogre::String& qualifiedName,
169 Ogre::String& outBasename, Ogre::String& outExtention,
170 Ogre::String& outPath);
171
175 static void splitBaseFilename(const Ogre::String& fullName,
176 Ogre::String& outBasename, Ogre::String& outExtention);
177
178
184 static bool match(const String& str, const String& pattern, bool caseSensitive = true);
185
186
193 static const String replaceAll(const String& source, const String& replaceWhat, const String& replaceWithWhat);
194
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
222} // namespace Ogre
223
224#include "OgreHeaderSuffix.h"
225
226#endif // _String_H__
#define _OgreExport
Definition: OgrePlatform.h:260
Utility class for manipulating Strings.
Definition: OgreString.h:76
static void splitFilename(const String &qualifiedName, String &outBasename, String &outPath)
Method for splitting a fully qualified filename into the base name and path.
static const String replaceAll(const String &source, const String &replaceWhat, const String &replaceWithWhat)
replace all instances of a sub-string with a another sub-string.
static bool match(const String &str, const String &pattern, bool caseSensitive=true)
Simple pattern-matching routine allowing a wildcard pattern.
static vector< String >::type split(const String &str, const String &delims="\t\n ", unsigned int maxSplits=0, bool preserveDelims=false)
Returns a StringVector that contains all the substrings delimited by the characters in the passed del...
static void splitFullFilename(const Ogre::String &qualifiedName, Ogre::String &outBasename, Ogre::String &outExtention, Ogre::String &outPath)
Method for splitting a fully qualified filename into the base name, extension and path.
static bool endsWith(const String &str, const String &pattern, bool lowerCase=true)
Returns whether the string ends with the pattern passed in.
static void splitBaseFilename(const Ogre::String &fullName, Ogre::String &outBasename, Ogre::String &outExtention)
Method for splitting a filename into the base name and extension.
static vector< String >::type tokenise(const String &str, const String &delims="\t\n ", const String &doubleDelims="\"", unsigned int maxSplits=0)
Returns a StringVector that contains all the substrings delimited by the characters in the passed del...
StringStream StrStreamType
Definition: OgreString.h:78
static void toUpperCase(String &str)
Upper-cases all the characters in the string.
static String normalizeFilePath(const String &init, bool makeLowerCase=true)
Returns a normalized version of a file path This method can be used to make file path strings which p...
static void toLowerCase(String &str)
Lower-cases all the characters in the string.
static bool startsWith(const String &str, const String &pattern, bool lowerCase=true)
Returns whether the string begins with the pattern passed in.
static String standardisePath(const String &init)
Method for standardising paths - use forward slashes only, end with slash.
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:196
static void trim(String &str, bool left=true, bool right=true)
Removes any whitespace characters, be it standard space or TABs and so on.
stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash
Definition: OgreString.h:215
std::string _StringBase
_StringStreamBase StringStream
_StringBase String
std::vector< T, A > type