update dev300-m58
[ooovba.git] / soltools / inc / simstr.hxx
blobe66ac0e577cc3e19a42670017224ba54d181b73a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: simstr.hxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SOLTOOLS_SIMSTR_HXX
32 #define SOLTOOLS_SIMSTR_HXX
35 class Simstr /// Simple string class.
37 // INTERFACE
38 public:
39 // LIFECYCLE
40 Simstr(
41 const char * str = 0);
42 Simstr( /** Creates Simstr out of a copy of the first
43 'nrOfBytes' bytes of 'anyBytes'.
44 Adds a '\0' at the end. */
45 const char * anybytes,
46 int nrOfBytes);
47 Simstr( /** Creates Simstr out of a copy of the described bytes within 'anyBytes'.
48 Adds a '\0' at the end. */
49 const char * anybytes,
50 int firstBytesPos,
51 int nrOfBytes );
52 Simstr( /// Creates Simstr of 'anzahl' times 'c'.
53 char c,
54 int anzahl);
55 Simstr(
56 const Simstr & S);
57 ~Simstr();
60 // OPERATORS
61 operator const char*() const;
63 Simstr & operator=(
64 const Simstr & S );
66 Simstr operator+(
67 const Simstr & S ) const;
68 Simstr & operator+=(
69 const Simstr & S );
70 Simstr & operator+=(
71 const char * s );
73 bool operator==(
74 const Simstr & S ) const;
75 bool operator!=(
76 const Simstr & S ) const;
77 bool operator<(
78 const Simstr & S ) const;
79 bool operator>(
80 const Simstr & S ) const;
81 bool operator<=(
82 const Simstr & S ) const;
83 bool operator>=(
84 const Simstr & S ) const;
85 // INFO
86 static const Simstr &
87 null_();
89 const char * str() const;
90 int l() const; // Length of string without '\0' at end.
91 char * s(); // ATTENTION !!! // Only to be used, when a function needs a 'char*' but
92 // nevertheless THAT WILL BE NOT CHANGED!
93 // Typecasts to 'const char*' are performed automatically.
94 char get(
95 int n) const;
96 char get_front() const;
97 char get_back() const;
98 Simstr get(
99 int startPos,
100 int anzahl ) const;
101 Simstr get_front(
102 int anzahl ) const;
103 Simstr get_back(
104 int anzahl ) const;
106 int pos_first(
107 char c ) const;
108 int pos_first_after(
109 char c,
110 int startSearchPos ) const;
111 int pos_last(
112 char c ) const;
113 int pos_first(
114 const Simstr & S ) const;
115 int pos_last(
116 const Simstr & S ) const;
117 int count(
118 char c ) const;
119 bool is_empty() const; // Only true if object == "".
120 bool is_no_text() const; // String may contain spaces or tabs.
122 Simstr get_first_token(
123 char c ) const;
124 Simstr get_last_token(
125 char c ) const;
127 // ACCESS
128 char & ch( /** Reference to sz[n]. Allows change of this char.
129 !!! No safety, if n is out of the allowed range! */
130 int n );
132 // OPERATIONS
133 void insert(
134 int pos,
135 char c );
136 void push_front(
137 char c );
138 void push_back(
139 char c );
140 void insert(
141 int pos,
142 const Simstr & S );
143 void push_front(
144 const Simstr & S );
145 void push_back(
146 const Simstr & S );
148 void remove(
149 int pos,
150 int anzahl = 1 );
151 void remove_trailing_blanks();
152 void pop_front(
153 int anzahl = 1 );
154 void pop_back(
155 int anzahl = 1 );
156 void rem_back_from(
157 int removeStartPos );
158 void remove_all(
159 char c );
160 void remove_all( // Starts search left.
161 const Simstr & S );
162 void strip(
163 char c ); // Removes all characters == c from front and back.
164 // c == ' ' removes also TABs !!!
165 void empty(); // Changes object to the value "".
167 void replace(
168 int pos,
169 char c );
170 void replace(
171 int startPos,
172 int anzahl,
173 const Simstr & S );
174 void replace_all(
175 char oldCh,
176 char newCh );
177 void replace_all(
178 const Simstr & oldS,
179 const Simstr & newS );
180 void to_lower();
182 Simstr take_first_token( /// Token is removed from the Simstr.
183 char c );
184 Simstr take_last_token( /// Token is removed from the Simstr.
185 char c );
186 private:
187 // DATA
188 char * sz;
189 int len;
192 // Simstr - char* / char - concatenations
193 Simstr operator+(const char * str, const Simstr & S);
194 Simstr operator+(const Simstr & S, const char * str);
195 Simstr operator+(char c, const Simstr & S);
196 Simstr operator+(const Simstr & S, char c);
198 // Simstr - char* - comparison operators
199 bool operator==(const Simstr & S, const char * str);
200 bool operator!=(const Simstr & S, const char * str);
201 bool operator<(const Simstr & S, const char * str);
202 bool operator>(const Simstr & S, const char * str);
203 bool operator<=(const Simstr & S, const char * str);
204 bool operator>=(const Simstr & S, const char * str);
205 bool operator==(const char * str, const Simstr & S);
206 bool operator!=(const char * str, const Simstr & S);
207 bool operator<(const char * str, const Simstr & S);
208 bool operator>(const char * str, const Simstr & S);
209 bool operator<=(const char * str, const Simstr & S);
210 bool operator>=(const char * str, const Simstr & S);
213 inline const char *
214 Simstr::str() const { return sz; }
215 inline char *
216 Simstr::s() { return sz; }
217 inline int
218 Simstr::l() const { return len; }
219 inline
220 Simstr::operator const char*() const { return sz; }
221 inline bool
222 Simstr::is_empty() const { return len == 0; }
225 #endif