xref: /trunk/main/xml2cmp/source/support/sistr.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 XML2CMP_SISTR_HXX
29 #define XML2CMP_SISTR_HXX
30 
31 
32 class  Simstr
33 {
34 // INTERFACE
35    public:
36       // Constructors, destructor, '=' and typecasts
37                      Simstr(
38                            const char *   str = 0);
39 					 Simstr(                       // Creates Simstr out of a copy of the described bytes within 'anyBytes'.
40                                                    // Adds a '\0' at the end.
41                            const char *   anybytes,
42                            int			  firstBytesPos,
43                            int            nrOfBytes);
44       virtual        ~Simstr();
45                      Simstr(
46                            const Simstr & S);
47       Simstr &       operator=(
48                            const Simstr & S);
49                      operator const char*() const;
50 
51       // diverse utility functions
52 	  const char *   str() const				{ return sz; }
53 	  char *         s();   // ATTENTION !!!       // Only to be used, when a function needs a 'char*' but
54 												   //   nevertheless THAT WILL BE NOT CHANGED!
55                                                    //   Typecasts to 'const char*' are performed automatically.
56       int            l() const;                    // Length of string without '\0' at end.
57       Simstr         operator+(
58                            const Simstr & S) const;
59       Simstr &       operator+=(
60                            const Simstr & S);
61 
62       // comparison operators
63       bool           operator==(
64                            const Simstr & S) const;
65       bool           operator!=(
66                            const Simstr & S) const;
67       bool           operator<(
68                            const Simstr & S) const;
69       bool           operator>(
70                            const Simstr & S) const;
71       bool           operator<=(
72                            const Simstr & S) const;
73       bool           operator>=(
74 						   const Simstr & S) const;
75 
76 
77 	  // 'List of characters' - functions
78          // insert - functions
79       void           push_front(
80                            char           c);
81       void           push_back(
82                            char           c);
83 	  void           push_front(
84                            const Simstr & S);
85 	  void           push_back(
86                            const Simstr & S);
87          // remove - functions
88 	  void           remove(
89 	  					   int            pos,
90 						   int            anzahl = 1);
91 	  void			 remove_trailing_blanks();
92 
93          // search functions
94       int            pos_first(
95                            char           c) const;
96       int            pos_last(
97                            char           c) const;
98 	  bool           is_empty() const;                         // Only true if object == "".
99 	  bool           is_no_text() const;                       // String may contain spaces or tabs.
100 
101          // substitution functions
102       void           replace_all(
103                            char           oldCh,
104 						   char           newCh);
105          // token functions
106 			// get...-functions return the token, separated by char 'c' and leave the object unchanged.
107             // take...-functions return the same, but remove the token and the corresponding separator from the object.
108       Simstr         get_last_token(
109 						   char           c) const;
110 
111    private:
112       char *         sz;
113       int            len;
114 };
115 
116 // Simstr - char* / char - concatenations
117 Simstr operator+(const char * str, const Simstr & S);
118 Simstr operator+(const Simstr & S, const char * str);
119 Simstr operator+(char c, const Simstr & S);
120 Simstr operator+(const Simstr & S, char c);
121 
122 // Simstr - char* - comparison operators
123 bool  operator==(const Simstr & S, const char * str);
124 bool  operator!=(const Simstr & S, const char * str);
125 bool  operator<(const Simstr & S, const char * str);
126 bool  operator>(const Simstr & S, const char * str);
127 bool  operator<=(const Simstr & S, const char * str);
128 bool  operator>=(const Simstr & S, const char * str);
129 bool  operator==(const char * str, const Simstr & S);
130 bool  operator!=(const char * str, const Simstr & S);
131 bool  operator<(const char * str, const Simstr & S);
132 bool  operator>(const char * str, const Simstr & S);
133 bool  operator<=(const char * str, const Simstr & S);
134 bool  operator>=(const char * str, const Simstr & S);
135 
136 
137 inline char *
138 Simstr::s()                            { return sz; }
139 inline int
140 Simstr::l() const                      { return len; }
141 inline
142 Simstr::operator const char*() const   { return sz; }
143 inline bool
144 Simstr::is_empty() const               { return len == 0; }
145 
146 
147 #endif
148 
149