Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/support/agstring.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /********************************************************** | |
2 | |
3 The AnaGram Class Library | |
4 | |
5 The AgString Class | |
6 Copyright 1997 Parsifal Software. All Rights Reserved. | |
7 See the file COPYING for license and usage terms. | |
8 | |
9 ***********************************************************/ | |
10 | |
11 #ifndef AGSTRING_H | |
12 #define AGSTRING_H | |
13 | |
14 #include <string.h> | |
15 #include "port.h" | |
16 | |
17 #include "agcontainer.h" | |
18 | |
19 | |
20 class AgString : public AgIndexedContainer<char> { | |
21 protected: | |
22 char *store; | |
23 | |
24 void lock(); | |
25 void unlock(); | |
26 void allocate(unsigned n); | |
27 | |
28 public: | |
29 class Cut { | |
30 char *store; | |
31 int index; | |
32 | |
33 void lock(); | |
34 void unlock(); | |
35 | |
36 public: | |
37 Cut() : store(0), index(0) {} | |
38 Cut(const AgString &s, const int x); | |
39 ~Cut() { unlock(); } | |
40 int exists() const { return store != 0; } | |
41 | |
42 char &character() const; | |
43 | |
44 AgString leftI() const; | |
45 AgString leftX() const; | |
46 AgString rightI() const; | |
47 AgString rightX() const; | |
48 | |
49 //AgString insertLeft(const AgString &s) const; | |
50 //AgString insertLeft(const char *s) const; | |
51 //AgString insertRight(const AgString &s) const; | |
52 //AgString insertRight(const char *s) const; | |
53 //String replace(const AgString &s) const; | |
54 //String replace(const char *s) const; | |
55 }; | |
56 | |
57 inline AgString() : store(0) {} | |
58 AgString(const unsigned n); | |
59 | |
60 AgString(const char *s); | |
61 AgString(const char *s, const unsigned n); | |
62 AgString(const AgString &s, const unsigned n); | |
63 AgString(const AgString &s); | |
64 AgString &operator = (const AgString &s); | |
65 AgString &operator = (const char *s); | |
66 | |
67 char &operator [] (const unsigned x); | |
68 | |
69 const char &operator [] (const unsigned x) const; | |
70 AgString &discardData(); | |
71 ~AgString(); | |
72 | |
73 AgString concat(const char *s) const; | |
74 AgString concat(const AgString s) const; | |
75 | |
76 inline int exists() const { return store != 0; } | |
77 inline unsigned size() const { return store ? strlen(store) : 0; } | |
78 | |
79 AgString &toUpper(); | |
80 //AgString &toLower(); | |
81 | |
82 inline char *pointer() const { | |
83 return store; | |
84 } | |
85 inline unsigned char *unsignedPointer() const { | |
86 return (unsigned char *) store; | |
87 } | |
88 | |
89 int operator < (const AgString &s) const; | |
90 int operator <= (const AgString &s) const; | |
91 int operator > (const AgString &s) const; | |
92 int operator >= (const AgString &s) const; | |
93 int operator == (const AgString &s) const; | |
94 int operator != (const AgString &s) const; | |
95 int iEq(const AgString &s) const; | |
96 | |
97 int operator < (const char *s) const; | |
98 int operator <= (const char *s) const; | |
99 int operator > (const char *s) const; | |
100 int operator >= (const char *s) const; | |
101 int operator == (const char *s) const; | |
102 int operator != (const char *s) const; | |
103 int iEq(const char *s) const; | |
104 | |
105 static AgString format(const char *fs, ...) PRINTFFY(1,2); | |
106 | |
107 Cut firstCut(const char c) const; | |
108 Cut lastCut(const char c) const; | |
109 Cut firstCut(const char* s) const; | |
110 Cut lastCut(const char* s) const; | |
111 }; | |
112 | |
113 inline AgString::AgString(const AgString &s) | |
114 : AgIndexedContainer<char>() | |
115 { | |
116 store = s.store; | |
117 lock(); | |
118 } | |
119 | |
120 inline AgString::~AgString() { | |
121 unlock(); | |
122 } | |
123 | |
124 inline AgString &AgString::discardData() { | |
125 unlock(); | |
126 store = 0; | |
127 return *this; | |
128 } | |
129 | |
130 inline AgString &AgString::operator = (const char *s) { | |
131 return *this = AgString(s); | |
132 } | |
133 | |
134 #endif /* AGSTRING_H */ |