Planeshift
|
00001 /* 00002 * psstring.h 00003 * 00004 * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org) 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation (version 2 of the License) 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 * 00019 * A slightly improved string over csString. Adds a couple of functions 00020 * that will be needed by the XML parser. 00021 */ 00022 #ifndef PS_STRING_H 00023 #define PS_STRING_H 00024 00025 #include <csutil/csstring.h> 00026 00027 class csStringArray; 00028 class MathEnvironment; 00029 00034 #define XML_CASE_INSENSITIVE true 00035 #define XML_CASE_SENSITIVE false 00036 00037 class psString : public csString 00038 { 00039 public: 00040 psString() {} 00041 psString(const char* str) : csString(str) {} 00042 psString(const csStringBase& str) : csString(str) {} 00043 psString(const csString& str) : csString(str) {} 00044 00045 int FindSubString(const char *sub, size_t start=0, bool caseInsense=XML_CASE_SENSITIVE,bool wholeWord=false) const; 00046 int FindSubStringReverse(psString& sub, size_t start, bool caseInsense=XML_CASE_SENSITIVE); 00047 void GetSubString(psString& str, size_t from, size_t to) const; 00048 bool FindNumber(unsigned int & pos, unsigned int & end) const; 00049 bool FindString(const char *border, unsigned int & pos, unsigned int & end) const; 00050 00051 enum 00052 { 00053 NO_PUNCT=0, 00054 INCLUDE_PUNCT=1 00055 }; 00056 00057 void GetWord(size_t pos,psString &buff,bool wantPunct=INCLUDE_PUNCT) const; 00058 void GetWordNumber(int which,psString& buff) const; 00059 void GetLine(size_t start,csString& line) const; 00060 00061 bool ReplaceSubString(const char* what, const char* with); 00062 00063 bool operator==(const psString& other) const 00064 { return strcmp(GetData(),other.GetData())==0; } 00065 00066 bool operator<(const psString& other) const 00067 { return strcmp(GetData(),other.GetData())<0; } 00068 00069 bool operator==(const char* other) const 00070 { return strcmp(GetData() ? GetData() : "",other ? other : "") == 0;} 00071 00072 int PartialEquals(const psString& other) const 00073 { return strncmp(GetData(),other.GetData(),other.Length()); } 00074 00075 size_t FindCommonLength(const psString& other) const; 00076 00077 bool IsVowel(size_t pos); 00078 psString& Plural(); 00079 00080 void Split(csStringArray& result, char delim='|'); 00081 }; 00082 00085 #endif 00086