| 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-2006 Torus Knot Software Ltd |
|---|
| 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 | You may alternatively use this source under the terms of a specific version of |
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
|---|
| 26 | Torus Knot Software Ltd. |
|---|
| 27 | ----------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | #ifndef _String_H__ |
|---|
| 30 | #define _String_H__ |
|---|
| 31 | |
|---|
| 32 | #include "OgrePrerequisites.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 | #include <ext/hash_map> |
|---|
| 38 | namespace __gnu_cxx |
|---|
| 39 | { |
|---|
| 40 | template <> struct hash< Ogre::_StringBase > |
|---|
| 41 | { |
|---|
| 42 | size_t operator()( const Ogre::_StringBase _stringBase ) const |
|---|
| 43 | { |
|---|
| 44 | /* This is the PRO-STL way, but it seems to cause problems with VC7.1 |
|---|
| 45 | and in some other cases (although I can't recreate it) |
|---|
| 46 | hash<const char*> H; |
|---|
| 47 | return H(_stringBase.c_str()); |
|---|
| 48 | */ |
|---|
| 49 | /** This is our custom way */ |
|---|
| 50 | register size_t ret = 0; |
|---|
| 51 | for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it ) |
|---|
| 52 | ret = 5 * ret + *it; |
|---|
| 53 | |
|---|
| 54 | return ret; |
|---|
| 55 | } |
|---|
| 56 | }; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | #endif |
|---|
| 60 | |
|---|
| 61 | namespace Ogre { |
|---|
| 62 | |
|---|
| 63 | /** Utility class for manipulating Strings. */ |
|---|
| 64 | class _OgreExport StringUtil |
|---|
| 65 | { |
|---|
| 66 | public: |
|---|
| 67 | typedef std::ostringstream StrStreamType; |
|---|
| 68 | |
|---|
| 69 | /** Removes any whitespace characters, be it standard space or |
|---|
| 70 | TABs and so on. |
|---|
| 71 | @remarks |
|---|
| 72 | The user may specify wether they want to trim only the |
|---|
| 73 | beginning or the end of the String ( the default action is |
|---|
| 74 | to trim both). |
|---|
| 75 | */ |
|---|
| 76 | static void trim( String& str, bool left = true, bool right = true ); |
|---|
| 77 | |
|---|
| 78 | /** Returns a StringVector that contains all the substrings delimited |
|---|
| 79 | by the characters in the passed <code>delims</code> argument. |
|---|
| 80 | @param |
|---|
| 81 | delims A list of delimiter characters to split by |
|---|
| 82 | @param |
|---|
| 83 | maxSplits The maximum number of splits to perform (0 for unlimited splits). If this |
|---|
| 84 | parameters is > 0, the splitting process will stop after this many splits, left to right. |
|---|
| 85 | */ |
|---|
| 86 | static std::vector< String > split( const String& str, const String& delims = "\t\n ", unsigned int maxSplits = 0); |
|---|
| 87 | |
|---|
| 88 | /** Upper-cases all the characters in the string. |
|---|
| 89 | */ |
|---|
| 90 | static void toLowerCase( String& str ); |
|---|
| 91 | |
|---|
| 92 | /** Lower-cases all the characters in the string. |
|---|
| 93 | */ |
|---|
| 94 | static void toUpperCase( String& str ); |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | /** Returns whether the string begins with the pattern passed in. |
|---|
| 98 | @param pattern The pattern to compare with. |
|---|
| 99 | @param lowerCase If true, the end of the string will be lower cased before |
|---|
| 100 | comparison, pattern should also be in lower case. |
|---|
| 101 | */ |
|---|
| 102 | static bool startsWith(const String& str, const String& pattern, bool lowerCase = true); |
|---|
| 103 | |
|---|
| 104 | /** Returns whether the string ends with the pattern passed in. |
|---|
| 105 | @param pattern The pattern to compare with. |
|---|
| 106 | @param lowerCase If true, the end of the string will be lower cased before |
|---|
| 107 | comparison, pattern should also be in lower case. |
|---|
| 108 | */ |
|---|
| 109 | static bool endsWith(const String& str, const String& pattern, bool lowerCase = true); |
|---|
| 110 | |
|---|
| 111 | /** Method for standardising paths - use forward slashes only, end with slash. |
|---|
| 112 | */ |
|---|
| 113 | static String standardisePath( const String &init); |
|---|
| 114 | |
|---|
| 115 | /** Method for splitting a fully qualified filename into the base name |
|---|
| 116 | and path. |
|---|
| 117 | @remarks |
|---|
| 118 | Path is standardised as in standardisePath |
|---|
| 119 | */ |
|---|
| 120 | static void splitFilename(const String& qualifiedName, |
|---|
| 121 | String& outBasename, String& outPath); |
|---|
| 122 | |
|---|
| 123 | /** Method for splitting a fully qualified filename into the base name, |
|---|
| 124 | extension and path. |
|---|
| 125 | @remarks |
|---|
| 126 | Path is standardised as in standardisePath |
|---|
| 127 | */ |
|---|
| 128 | static void splitFullFilename(const Ogre::String& qualifiedName, |
|---|
| 129 | Ogre::String& outBasename, Ogre::String& outExtention, |
|---|
| 130 | Ogre::String& outPath); |
|---|
| 131 | |
|---|
| 132 | /** Method for splitting a filename into the base name |
|---|
| 133 | and extension. |
|---|
| 134 | */ |
|---|
| 135 | static void splitBaseFilename(const Ogre::String& fullName, |
|---|
| 136 | Ogre::String& outBasename, Ogre::String& outExtention); |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | /** Simple pattern-matching routine allowing a wildcard pattern. |
|---|
| 140 | @param str String to test |
|---|
| 141 | @param pattern Pattern to match against; can include simple '*' wildcards |
|---|
| 142 | @param caseSensitive Whether the match is case sensitive or not |
|---|
| 143 | */ |
|---|
| 144 | static bool match(const String& str, const String& pattern, bool caseSensitive = true); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | /// Constant blank string, useful for returning by ref where local does not exist |
|---|
| 151 | static const String BLANK; |
|---|
| 152 | }; |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT) |
|---|
| 156 | typedef ::__gnu_cxx::hash< _StringBase > _StringHash; |
|---|
| 157 | #elif !defined( _STLP_HASH_FUN_H ) |
|---|
| 158 | typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash; |
|---|
| 159 | #else |
|---|
| 160 | typedef std::hash< _StringBase > _StringHash; |
|---|
| 161 | #endif |
|---|
| 162 | |
|---|
| 163 | } // namespace Ogre |
|---|
| 164 | |
|---|
| 165 | #endif // _String_H__ |
|---|