[1809] | 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-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://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>
|
---|
| 34 | namespace __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 | #endif
|
---|
| 56 |
|
---|
| 57 | namespace Ogre {
|
---|
| 58 |
|
---|
| 59 | /** Utility class for manipulating Strings. */
|
---|
| 60 | class _OgreExport StringUtil
|
---|
| 61 | {
|
---|
| 62 | public:
|
---|
| 63 | typedef std::ostringstream StrStreamType;
|
---|
| 64 |
|
---|
| 65 | /** Removes any whitespace characters, be it standard space or
|
---|
| 66 | TABs and so on.
|
---|
| 67 | @remarks
|
---|
| 68 | The user may specify wether they want to trim only the
|
---|
| 69 | beginning or the end of the String ( the default action is
|
---|
| 70 | to trim both).
|
---|
| 71 | */
|
---|
| 72 | static void trim( String& str, bool left = true, bool right = true );
|
---|
| 73 |
|
---|
| 74 | /** Returns a StringVector that contains all the substrings delimited
|
---|
| 75 | by the characters in the passed <code>delims</code> argument.
|
---|
| 76 | @param
|
---|
| 77 | delims A list of delimiter characters to split by
|
---|
| 78 | @param
|
---|
| 79 | maxSplits The maximum number of splits to perform (0 for unlimited splits). If this
|
---|
| 80 | parameters is > 0, the splitting process will stop after this many splits, left to right.
|
---|
| 81 | */
|
---|
| 82 | static std::vector< String > split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0);
|
---|
| 83 |
|
---|
| 84 | /** Upper-cases all the characters in the string.
|
---|
| 85 | */
|
---|
| 86 | static void toLowerCase( String& str );
|
---|
| 87 |
|
---|
| 88 | /** Lower-cases all the characters in the string.
|
---|
| 89 | */
|
---|
| 90 | static void toUpperCase( String& str );
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | /** Returns whether the string begins with the pattern passed in.
|
---|
| 94 | @param pattern The pattern to compare with.
|
---|
| 95 | @param lowerCase If true, the end of the string will be lower cased before
|
---|
| 96 | comparison, pattern should also be in lower case.
|
---|
| 97 | */
|
---|
| 98 | static bool startsWith(const String& str, const String& pattern, bool lowerCase = true);
|
---|
| 99 |
|
---|
| 100 | /** Returns whether the string ends with the pattern passed in.
|
---|
| 101 | @param pattern The pattern to compare with.
|
---|
| 102 | @param lowerCase If true, the end of the string will be lower cased before
|
---|
| 103 | comparison, pattern should also be in lower case.
|
---|
| 104 | */
|
---|
| 105 | static bool endsWith(const String& str, const String& pattern, bool lowerCase = true);
|
---|
| 106 |
|
---|
| 107 | /** Method for standardising paths - use forward slashes only, end with slash.
|
---|
| 108 | */
|
---|
| 109 | static String standardisePath( const String &init);
|
---|
| 110 |
|
---|
| 111 | /** Method for splitting a fully qualified filename into the base name
|
---|
| 112 | and path.
|
---|
| 113 | @remarks
|
---|
| 114 | Path is standardised as in standardisePath
|
---|
| 115 | */
|
---|
| 116 | static void splitFilename(const String& qualifiedName,
|
---|
| 117 | String& outBasename, String& outPath);
|
---|
| 118 |
|
---|
| 119 | /** Simple pattern-matching routine allowing a wildcard pattern.
|
---|
| 120 | @param str String to test
|
---|
| 121 | @param pattern Pattern to match against; can include simple '*' wildcards
|
---|
| 122 | @param caseSensitive Whether the match is case sensitive or not
|
---|
| 123 | */
|
---|
| 124 | static bool match(const String& str, const String& pattern, bool caseSensitive = true);
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | /// Constant blank string, useful for returning by ref where local does not exist
|
---|
| 131 | static const String BLANK;
|
---|
| 132 | };
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT)
|
---|
| 136 | typedef ::__gnu_cxx::hash< _StringBase > _StringHash;
|
---|
| 137 | #elif !defined( _STLP_HASH_FUN_H )
|
---|
| 138 | typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
|
---|
| 139 | #else
|
---|
| 140 | typedef std::hash< _StringBase > _StringHash;
|
---|
| 141 | #endif
|
---|
| 142 |
|
---|
| 143 | } // namespace Ogre
|
---|
| 144 |
|
---|
| 145 | #endif // _String_H__
|
---|