00001 /* 00002 Copyright (c) 2000-2003 Lee Thomason (www.grinninglizard.com) 00003 00004 Grinning Lizard Utilities. Note that software that uses the 00005 utility package (including Lilith3D and Kyra) have more restrictive 00006 licences which applies to code outside of the utility package. 00007 00008 00009 This software is provided 'as-is', without any express or implied 00010 warranty. In no event will the authors be held liable for any 00011 damages arising from the use of this software. 00012 00013 Permission is granted to anyone to use this software for any 00014 purpose, including commercial applications, and to alter it and 00015 redistribute it freely, subject to the following restrictions: 00016 00017 1. The origin of this software must not be misrepresented; you must 00018 not claim that you wrote the original software. If you use this 00019 software in a product, an acknowledgment in the product documentation 00020 would be appreciated but is not required. 00021 00022 2. Altered source versions must be plainly marked as such, and 00023 must not be misrepresented as being the original software. 00024 00025 3. This notice may not be removed or altered from any source 00026 distribution. 00027 */ 00028 00029 #ifndef KYRA_STRING16_INCLUDED 00030 #define KYRA_STRING16_INCLUDED 00031 00032 #ifdef _MSC_VER 00033 // Disable the no-exception handling warning. 00034 #pragma warning( disable : 4530 ) 00035 #pragma warning( disable : 4786 ) 00036 #endif 00037 00038 #include "../../grinliz/gltypes.h" 00039 #include <string> 00040 #include <vector> 00041 00042 bool StrEqual( const char* s1, const char* s2 ); 00043 00044 class GlString 00045 { 00046 public: 00047 00048 static bool IsSpace( char p, const char* delimiter, bool useIsSpace ); 00049 00050 static const char* SkipWhiteSpace( const char* p, 00051 const char* delimiter, 00052 bool useIsSpace ); 00053 00054 static bool IEqual( const std::string& s1, const std::string& s2 ); 00055 static void AppendInt( std::string* s, int i ); 00056 00057 // Removes all white space in the given string. 00058 static void RemoveWhiteSpace( std::string* s ); 00059 00060 /* Creates an array of strings by splitting 'this' by 00061 the specified delimeters. 'this' will remain unchanged. 00062 The returned DynArray will need to be delete'd 00063 00064 @param delimeter An array of characters, any of which 00065 signals a split point. 00066 @param useIsSpace Use the ctype 'isspace' call to determine 00067 if a character is a delimeter. 00068 */ 00069 static void Split( std::vector<std::string>* output, 00070 const std::string& input, 00071 const char* delimiter, 00072 bool useIsSpace ); 00073 00074 /* Assuming 'this' is a filename or url, changes (or adds) 00075 the extension. The extension can be any number of letters, 00076 and should be passed in without the leading period. 00077 */ 00078 static void SetExtension( std::string*, const char* extension ); 00079 00080 private: 00081 static const char* ReadWord( const char* p, 00082 std::string* word, 00083 const char* delimiter, 00084 bool useIsSpace ); 00085 }; 00086 00087 #endif