1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: simstr.hxx,v $
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.
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
,
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
,
52 Simstr( /// Creates Simstr of 'anzahl' times 'c'.
61 operator const char*() const;
67 const Simstr
& S
) const;
74 const Simstr
& S
) const;
76 const Simstr
& S
) const;
78 const Simstr
& S
) const;
80 const Simstr
& S
) const;
82 const Simstr
& S
) const;
84 const Simstr
& S
) const;
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.
96 char get_front() const;
97 char get_back() const;
110 int startSearchPos
) const;
114 const Simstr
& S
) const;
116 const Simstr
& S
) 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(
124 Simstr
get_last_token(
128 char & ch( /** Reference to sz[n]. Allows change of this char.
129 !!! No safety, if n is out of the allowed range! */
151 void remove_trailing_blanks();
157 int removeStartPos
);
160 void remove_all( // Starts search left.
163 char c
); // Removes all characters == c from front and back.
164 // c == ' ' removes also TABs !!!
165 void empty(); // Changes object to the value "".
179 const Simstr
& newS
);
182 Simstr
take_first_token( /// Token is removed from the Simstr.
184 Simstr
take_last_token( /// Token is removed from the Simstr.
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
);
214 Simstr::str() const { return sz
; }
216 Simstr::s() { return sz
; }
218 Simstr::l() const { return len
; }
220 Simstr::operator const char*() const { return sz
; }
222 Simstr::is_empty() const { return len
== 0; }