Planeshift
psstring.h
Go to the documentation of this file.
1 /*
2  * psstring.h
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  *
19  * A slightly improved string over csString. Adds a couple of functions
20  * that will be needed by the XML parser.
21  */
22 #ifndef PS_STRING_H
23 #define PS_STRING_H
24 
25 #include <csutil/csstring.h>
26 
27 class csStringArray;
28 class MathEnvironment;
29 
34 #define XML_CASE_INSENSITIVE true
35 #define XML_CASE_SENSITIVE false
36 
37 class psString : public csString
38 {
39 public:
40  psString() {}
41  psString(const char* str) : csString(str) {}
42  psString(const csStringBase& str) : csString(str) {}
43  psString(const csString& str) : csString(str) {}
44 
45  int FindSubString(const char *sub, size_t start=0, bool caseInsense=XML_CASE_SENSITIVE,bool wholeWord=false) const;
46  int FindSubStringReverse(psString& sub, size_t start, bool caseInsense=XML_CASE_SENSITIVE);
47  void GetSubString(psString& str, size_t from, size_t to) const;
48  bool FindNumber(unsigned int & pos, unsigned int & end) const;
49  bool FindString(const char *border, unsigned int & pos, unsigned int & end) const;
50 
51  enum
52  {
55  };
56 
57  void GetWord(size_t pos,psString &buff,bool wantPunct=INCLUDE_PUNCT) const;
58  void GetWordNumber(int which,psString& buff) const;
59  void GetLine(size_t start,csString& line) const;
60 
61  bool ReplaceSubString(const char* what, const char* with);
62 
63  bool operator==(const psString& other) const
64  { return strcmp(GetData(),other.GetData())==0; }
65 
66  bool operator<(const psString& other) const
67  { return strcmp(GetData(),other.GetData())<0; }
68 
69  bool operator==(const char* other) const
70  { return strcmp(GetData() ? GetData() : "",other ? other : "") == 0;}
71 
72  int PartialEquals(const psString& other) const
73  { return strncmp(GetData(),other.GetData(),other.Length()); }
74 
75  size_t FindCommonLength(const psString& other) const;
76 
77  bool IsVowel(size_t pos);
78  psString& Plural();
79 
80  void Split(csStringArray& result, char delim='|');
81 };
82 
85 #endif
86 
bool ReplaceSubString(const char *what, const char *with)
bool IsVowel(size_t pos)
void Split(csStringArray &result, char delim='|')
Turn the last word of the string into an English plural.
A specific MathEnvironment to be used in a MathScript.
Definition: mathscript.h:188
psString(const csString &str)
Definition: psstring.h:43
psString(const csStringBase &str)
Definition: psstring.h:42
int PartialEquals(const psString &other) const
Definition: psstring.h:72
bool operator<(const psString &other) const
Definition: psstring.h:66
int FindSubStringReverse(psString &sub, size_t start, bool caseInsense=XML_CASE_SENSITIVE)
bool operator==(const char *other) const
Definition: psstring.h:69
#define XML_CASE_SENSITIVE
Definition: psstring.h:35
int FindSubString(const char *sub, size_t start=0, bool caseInsense=XML_CASE_SENSITIVE, bool wholeWord=false) const
void GetWord(size_t pos, psString &buff, bool wantPunct=INCLUDE_PUNCT) const
bool FindNumber(unsigned int &pos, unsigned int &end) const
psString & Plural()
Check if a character is a vowel.
psString(const char *str)
Definition: psstring.h:41
void GetWordNumber(int which, psString &buff) const
bool operator==(const psString &other) const
Definition: psstring.h:63
void GetLine(size_t start, csString &line) const
size_t FindCommonLength(const psString &other) const
psString()
Definition: psstring.h:40
bool FindString(const char *border, unsigned int &pos, unsigned int &end) const
void GetSubString(psString &str, size_t from, size_t to) const