1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SOLTOOLS_SIMSTR_HXX
29 #define SOLTOOLS_SIMSTR_HXX
32 class Simstr
/// Simple string class.
38 const char * str
= 0);
39 Simstr( /** Creates Simstr out of a copy of the first
40 'nrOfBytes' bytes of 'anyBytes'.
41 Adds a '\0' at the end. */
42 const char * anybytes
,
44 Simstr( /** Creates Simstr out of a copy of the described bytes within 'anyBytes'.
45 Adds a '\0' at the end. */
46 const char * anybytes
,
49 Simstr( /// Creates Simstr of 'anzahl' times 'c'.
58 operator const char*() const;
64 const Simstr
& S
) const;
71 const Simstr
& S
) const;
73 const Simstr
& S
) const;
75 const Simstr
& S
) const;
77 const Simstr
& S
) const;
79 const Simstr
& S
) const;
81 const Simstr
& S
) const;
86 const char * str() const;
87 int l() const; // Length of string without '\0' at end.
88 char * s(); // ATTENTION !!! // Only to be used, when a function needs a 'char*' but
89 // nevertheless THAT WILL BE NOT CHANGED!
90 // Typecasts to 'const char*' are performed automatically.
93 char get_front() const;
94 char get_back() const;
107 int startSearchPos
) const;
111 const Simstr
& S
) const;
113 const Simstr
& S
) const;
116 bool is_empty() const; // Only true if object == "".
117 bool is_no_text() const; // String may contain spaces or tabs.
119 Simstr
get_first_token(
121 Simstr
get_last_token(
125 char & ch( /** Reference to sz[n]. Allows change of this char.
126 !!! No safety, if n is out of the allowed range! */
148 void remove_trailing_blanks();
154 int removeStartPos
);
157 void remove_all( // Starts search left.
160 char c
); // Removes all characters == c from front and back.
161 // c == ' ' removes also TABs !!!
162 void empty(); // Changes object to the value "".
176 const Simstr
& newS
);
179 Simstr
take_first_token( /// Token is removed from the Simstr.
181 Simstr
take_last_token( /// Token is removed from the Simstr.
189 // Simstr - char* / char - concatenations
190 Simstr
operator+(const char * str
, const Simstr
& S
);
191 Simstr
operator+(const Simstr
& S
, const char * str
);
192 Simstr
operator+(char c
, const Simstr
& S
);
193 Simstr
operator+(const Simstr
& S
, char c
);
195 // Simstr - char* - comparison operators
196 bool operator==(const Simstr
& S
, const char * str
);
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 char * str
, const Simstr
& S
);
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
);
211 Simstr::str() const { return sz
; }
213 Simstr::s() { return sz
; }
215 Simstr::l() const { return len
; }
217 Simstr::operator const char*() const { return sz
; }
219 Simstr::is_empty() const { return len
== 0; }