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