Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / soltools / inc / simstr.hxx
blob72c99dd93e183310e62ab7ee1ecd2a13b5363b1e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef SOLTOOLS_SIMSTR_HXX
30 #define SOLTOOLS_SIMSTR_HXX
33 class Simstr /// Simple string class.
35 // INTERFACE
36 public:
37 // LIFECYCLE
38 Simstr(
39 const char * str = 0);
40 Simstr( /** Creates Simstr out of a copy of the first
41 'nrOfBytes' bytes of 'anyBytes'.
42 Adds a '\0' at the end. */
43 const char * anybytes,
44 int nrOfBytes);
45 Simstr( /** Creates Simstr out of a copy of the described bytes within 'anyBytes'.
46 Adds a '\0' at the end. */
47 const char * anybytes,
48 int firstBytesPos,
49 int nrOfBytes );
50 Simstr( /// Creates Simstr of 'anzahl' times 'c'.
51 char c,
52 int anzahl);
53 Simstr(
54 const Simstr & S);
55 ~Simstr();
58 // OPERATORS
59 operator const char*() const;
61 Simstr & operator=(
62 const Simstr & S );
64 Simstr operator+(
65 const Simstr & S ) const;
66 Simstr & operator+=(
67 const Simstr & S );
68 Simstr & operator+=(
69 const char * s );
71 bool operator==(
72 const Simstr & S ) const;
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 // INFO
84 static const Simstr &
85 null_();
87 const char * str() const;
88 int l() const; // Length of string without '\0' at end.
89 char * s(); // ATTENTION !!! // Only to be used, when a function needs a 'char*' but
90 // nevertheless THAT WILL BE NOT CHANGED!
91 // Typecasts to 'const char*' are performed automatically.
92 char get(
93 int n) const;
94 char get_front() const;
95 char get_back() const;
96 Simstr get(
97 int startPos,
98 int anzahl ) const;
99 Simstr get_front(
100 int anzahl ) const;
101 Simstr get_back(
102 int anzahl ) const;
104 int pos_first(
105 char c ) const;
106 int pos_first_after(
107 char c,
108 int startSearchPos ) const;
109 int pos_last(
110 char c ) const;
111 int pos_first(
112 const Simstr & S ) const;
113 int pos_last(
114 const Simstr & S ) const;
115 int count(
116 char c ) const;
117 bool is_empty() const; // Only true if object == "".
118 bool is_no_text() const; // String may contain spaces or tabs.
120 Simstr get_first_token(
121 char c ) const;
122 Simstr get_last_token(
123 char c ) const;
125 // ACCESS
126 char & ch( /** Reference to sz[n]. Allows change of this char.
127 !!! No safety, if n is out of the allowed range! */
128 int n );
130 // OPERATIONS
131 void insert(
132 int pos,
133 char c );
134 void push_front(
135 char c );
136 void push_back(
137 char c );
138 void insert(
139 int pos,
140 const Simstr & S );
141 void push_front(
142 const Simstr & S );
143 void push_back(
144 const Simstr & S );
146 void remove(
147 int pos,
148 int anzahl = 1 );
149 void remove_trailing_blanks();
150 void pop_front(
151 int anzahl = 1 );
152 void pop_back(
153 int anzahl = 1 );
154 void rem_back_from(
155 int removeStartPos );
156 void remove_all(
157 char c );
158 void remove_all( // Starts search left.
159 const Simstr & S );
160 void strip(
161 char c ); // Removes all characters == c from front and back.
162 // c == ' ' removes also TABs !!!
163 void empty(); // Changes object to the value "".
165 void replace(
166 int pos,
167 char c );
168 void replace(
169 int startPos,
170 int anzahl,
171 const Simstr & S );
172 void replace_all(
173 char oldCh,
174 char newCh );
175 void replace_all(
176 const Simstr & oldS,
177 const Simstr & newS );
178 void to_lower();
180 Simstr take_first_token( /// Token is removed from the Simstr.
181 char c );
182 Simstr take_last_token( /// Token is removed from the Simstr.
183 char c );
184 private:
185 // DATA
186 char * sz;
187 int len;
190 // Simstr - char* / char - concatenations
191 Simstr operator+(const char * str, const Simstr & S);
192 Simstr operator+(const Simstr & S, const char * str);
193 Simstr operator+(char c, const Simstr & S);
194 Simstr operator+(const Simstr & S, char c);
196 // Simstr - char* - comparison operators
197 bool operator==(const Simstr & S, const char * str);
198 bool operator!=(const Simstr & S, const char * str);
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 char * str, const Simstr & S);
204 bool operator!=(const char * str, const Simstr & S);
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);
211 inline const char *
212 Simstr::str() const { return sz; }
213 inline char *
214 Simstr::s() { return sz; }
215 inline int
216 Simstr::l() const { return len; }
217 inline
218 Simstr::operator const char*() const { return sz; }
219 inline bool
220 Simstr::is_empty() const { return len == 0; }
223 #endif
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */