xref: /aoo41x/main/soltools/inc/simstr.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef SOLTOOLS_SIMSTR_HXX
29 #define SOLTOOLS_SIMSTR_HXX
30 
31 
32 class  Simstr   /// Simple string class.
33 {
34 // INTERFACE
35   public:
36     // LIFECYCLE
37                         Simstr(
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,
43                            int                  nrOfBytes);
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,
47                            int			        firstBytesPos,
48                            int                  nrOfBytes );
49                         Simstr(                 /// Creates Simstr of 'anzahl' times 'c'.
50                            char                 c,
51                            int                  anzahl);
52                         Simstr(
53                            const Simstr &       S);
54                         ~Simstr();
55 
56 
57     // OPERATORS
58                         operator const char*() const;
59 
60     Simstr &            operator=(
61                            const Simstr &       S );
62 
63     Simstr              operator+(
64                            const Simstr &       S ) const;
65     Simstr &            operator+=(
66                            const Simstr &       S );
67     Simstr &            operator+=(
68                            const char *         s );
69 
70     bool                operator==(
71                            const Simstr &       S ) const;
72     bool                operator!=(
73                            const Simstr &       S ) const;
74     bool                operator<(
75                            const Simstr &       S ) const;
76     bool                operator>(
77                            const Simstr &       S ) const;
78     bool                operator<=(
79                            const Simstr &       S ) const;
80     bool                operator>=(
81 						   const Simstr &       S ) const;
82     // INFO
83     static const Simstr &
84                         null_();
85 
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.
91     char                get(
92                             int                 n) const;
93 	char                get_front() const;
94     char                get_back() const;
95     Simstr              get(
96                             int                 startPos,
97 						    int                 anzahl ) const;
98     Simstr              get_front(
99                             int                 anzahl ) const;
100 	Simstr              get_back(
101                             int                 anzahl ) const;
102 
103     int                 pos_first(
104                             char                c ) const;
105 	int                 pos_first_after(
106 						    char                c,
107                             int                 startSearchPos ) const;
108     int                 pos_last(
109                             char                c ) const;
110 	int                 pos_first(
111                             const Simstr &      S ) const;
112 	int                 pos_last(
113                             const Simstr &      S ) const;
114 	int                 count(
115 	  					   char                 c ) const;
116 	bool                is_empty() const;                         // Only true if object == "".
117 	bool                is_no_text() const;                       // String may contain spaces or tabs.
118 
119     Simstr              get_first_token(
120                             char                c ) const;
121     Simstr              get_last_token(
122 						   char                 c ) const;
123 
124     // ACCESS
125     char &              ch(                     /** Reference to sz[n]. Allows change of this char.
126                                                     !!! No safety, if n is out of the allowed range! */
127                             int                 n );
128 
129     // OPERATIONS
130     void                insert(
131                             int                 pos,
132                             char                c );
133     void                push_front(
134                             char                c );
135     void                push_back(
136                             char                c );
137 	void                insert(
138                             int                 pos,
139                             const Simstr &      S );
140 	void                push_front(
141                             const Simstr &      S );
142 	void                push_back(
143                             const Simstr &      S );
144 
145 	void                remove(
146 	  					    int                 pos,
147 						    int                 anzahl = 1 );
148 	void			    remove_trailing_blanks();
149 	void                pop_front(
150 						    int                 anzahl = 1 );
151     void                pop_back(
152 						    int                 anzahl = 1 );
153     void                rem_back_from(
154 						    int                 removeStartPos );
155     void                remove_all(
156                             char                c );
157 	void                remove_all(                             // Starts search left.
158                             const Simstr &      S );
159     void                strip(
160                             char                c );                // Removes all characters == c from front and back.
161                                                              //   c == ' ' removes also TABs !!!
162     void                empty();                                // Changes object to the value "".
163 
164     void                replace(
165                             int                 pos,
166                             char                c );
167     void                replace(
168                             int                 startPos,
169                             int                 anzahl,
170 						    const Simstr &      S );
171     void                replace_all(
172                             char                oldCh,
173 						    char                newCh );
174 	void                replace_all(
175                             const Simstr &      oldS,
176                             const Simstr &      newS );
177     void                to_lower();
178 
179 	Simstr              take_first_token(       /// Token is removed from the Simstr.
180                            char                 c );
181 	Simstr              take_last_token(        /// Token is removed from the Simstr.
182                            char                 c );
183   private:
184     // DATA
185     char *              sz;
186     int                 len;
187 };
188 
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);
194 
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);
208 
209 
210 inline const char *
211 Simstr::str() const                    { return sz; }
212 inline char *
213 Simstr::s()                            { return sz; }
214 inline int
215 Simstr::l() const                      { return len; }
216 inline
217 Simstr::operator const char*() const   { return sz; }
218 inline bool
219 Simstr::is_empty() const               { return len == 0; }
220 
221 
222 #endif
223 
224