OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreString.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE 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>
42 namespace __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 
66 namespace Ogre {
76  {
77  public:
78 
86  static void trim( String& str, bool left = true, bool right = true );
87 
98  static vector<String>::type split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0, bool preserveDelims = false);
99 
112  static vector<String>::type tokenise( const String& str, const String& delims = "\t\n ", const String& doubleDelims = "\"", unsigned int maxSplits = 0);
113 
116  static void toLowerCase( String& str );
117 
120  static void toUpperCase( String& str );
121 
124  static void toTitleCase( String& str );
125 
126 
132  static bool startsWith(const String& str, const String& pattern, bool lowerCase = true);
133 
139  static bool endsWith(const String& str, const String& pattern, bool lowerCase = true);
140 
143  static String standardisePath( const String &init);
155  static String normalizeFilePath(const String& init, bool makeLowerCase = true);
156 
157 
163  static void splitFilename(const String& qualifiedName,
164  String& outBasename, String& outPath);
165 
171  static void splitFullFilename(const Ogre::String& qualifiedName,
172  Ogre::String& outBasename, Ogre::String& outExtention,
173  Ogre::String& outPath);
174 
178  static void splitBaseFilename(const Ogre::String& fullName,
179  Ogre::String& outBasename, Ogre::String& outExtention);
180 
181 
187  static bool match(const String& str, const String& pattern, bool caseSensitive = true);
188 
189 
196  static const String replaceAll(const String& source, const String& replaceWhat, const String& replaceWithWhat);
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 
222 } // namespace Ogre
223 
224 #include "OgreHeaderSuffix.h"
225 
226 #endif // _String_H__
#define _OgreExport
Definition: OgrePlatform.h:255
std::string _StringBase
stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash
Definition: OgreString.h:215
Utility class for manipulating Strings.
Definition: OgreString.h:75
_StringBase String
Definition: OgreCommon.h:53