OGRE  1.9
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:
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
219 
222 } // namespace Ogre
223 
224 #include "OgreHeaderSuffix.h"
225 
226 #endif // _String_H__
#define _OgreExport
Definition: OgrePlatform.h:260
std::string _StringBase
stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash
Definition: OgreString.h:215
StringStream StrStreamType
Definition: OgreString.h:78
_StringStreamBase StringStream
Utility class for manipulating Strings.
Definition: OgreString.h:75
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:196
_StringBase String