xref: /aoo4110/main/xml2cmp/source/support/sistr.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef XML2CMP_SISTR_HXX
25 #define XML2CMP_SISTR_HXX
26 
27 
28 class  Simstr
29 {
30 // INTERFACE
31    public:
32       // Constructors, destructor, '=' and typecasts
33                      Simstr(
34                            const char *   str = 0);
35 					 Simstr(                       // Creates Simstr out of a copy of the described bytes within 'anyBytes'.
36                                                    // Adds a '\0' at the end.
37                            const char *   anybytes,
38                            int			  firstBytesPos,
39                            int            nrOfBytes);
40       virtual        ~Simstr();
41                      Simstr(
42                            const Simstr & S);
43       Simstr &       operator=(
44                            const Simstr & S);
45                      operator const char*() const;
46 
47       // diverse utility functions
str() const48 	  const char *   str() const				{ return sz; }
49 	  char *         s();   // ATTENTION !!!       // Only to be used, when a function needs a 'char*' but
50 												   //   nevertheless THAT WILL BE NOT CHANGED!
51                                                    //   Typecasts to 'const char*' are performed automatically.
52       int            l() const;                    // Length of string without '\0' at end.
53       Simstr         operator+(
54                            const Simstr & S) const;
55       Simstr &       operator+=(
56                            const Simstr & S);
57 
58       // comparison operators
59       bool           operator==(
60                            const Simstr & S) const;
61       bool           operator!=(
62                            const Simstr & S) const;
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 
72 
73 	  // 'List of characters' - functions
74          // insert - functions
75       void           push_front(
76                            char           c);
77       void           push_back(
78                            char           c);
79 	  void           push_front(
80                            const Simstr & S);
81 	  void           push_back(
82                            const Simstr & S);
83          // remove - functions
84 	  void           remove(
85 	  					   int            pos,
86 						   int            anzahl = 1);
87 	  void			 remove_trailing_blanks();
88 
89          // search functions
90       int            pos_first(
91                            char           c) const;
92       int            pos_last(
93                            char           c) const;
94 	  bool           is_empty() const;                         // Only true if object == "".
95 	  bool           is_no_text() const;                       // String may contain spaces or tabs.
96 
97          // substitution functions
98       void           replace_all(
99                            char           oldCh,
100 						   char           newCh);
101          // token functions
102 			// get...-functions return the token, separated by char 'c' and leave the object unchanged.
103             // take...-functions return the same, but remove the token and the corresponding separator from the object.
104       Simstr         get_last_token(
105 						   char           c) const;
106 
107    private:
108       char *         sz;
109       int            len;
110 };
111 
112 // Simstr - char* / char - concatenations
113 Simstr operator+(const char * str, const Simstr & S);
114 Simstr operator+(const Simstr & S, const char * str);
115 Simstr operator+(char c, const Simstr & S);
116 Simstr operator+(const Simstr & S, char c);
117 
118 // Simstr - char* - comparison operators
119 bool  operator==(const Simstr & S, const char * str);
120 bool  operator!=(const Simstr & S, const char * str);
121 bool  operator<(const Simstr & S, const char * str);
122 bool  operator>(const Simstr & S, const char * str);
123 bool  operator<=(const Simstr & S, const char * str);
124 bool  operator>=(const Simstr & S, const char * str);
125 bool  operator==(const char * str, const Simstr & S);
126 bool  operator!=(const char * str, const Simstr & S);
127 bool  operator<(const char * str, const Simstr & S);
128 bool  operator>(const char * str, const Simstr & S);
129 bool  operator<=(const char * str, const Simstr & S);
130 bool  operator>=(const char * str, const Simstr & S);
131 
132 
133 inline char *
s()134 Simstr::s()                            { return sz; }
135 inline int
l() const136 Simstr::l() const                      { return len; }
137 inline
138 Simstr::operator const char*() const   { return sz; }
139 inline bool
is_empty() const140 Simstr::is_empty() const               { return len == 0; }
141 
142 
143 #endif
144 
145