Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef XML2CMP_SISTR_HXX
21 : : #define XML2CMP_SISTR_HXX
22 : :
23 : :
24 : : class Simstr
25 : : {
26 : : // INTERFACE
27 : : public:
28 : : // Constructors, destructor, '=' and typecasts
29 : : Simstr(
30 : : const char * str = 0);
31 : : Simstr( // Creates Simstr out of a copy of the described bytes within 'anyBytes'.
32 : : // Adds a '\0' at the end.
33 : : const char * anybytes,
34 : : int firstBytesPos,
35 : : int nrOfBytes);
36 : : virtual ~Simstr();
37 : : Simstr(
38 : : const Simstr & S);
39 : : Simstr & operator=(
40 : : const Simstr & S);
41 : : operator const char*() const;
42 : :
43 : : // diverse utility functions
44 : 22622 : const char * str() const { return sz; }
45 : : char * s(); // CAUTION!!! // Only use when a function needs a 'char*' but
46 : : // still will NOT MODIFY THE STRING!
47 : : // Typecasts to 'const char*' are performed automatically.
48 : : int l() const; // Length of string without '\0' at end.
49 : : Simstr operator+(
50 : : const Simstr & S) const;
51 : : Simstr & operator+=(
52 : : const Simstr & S);
53 : :
54 : : // comparison operators
55 : : bool operator==(
56 : : const Simstr & S) const;
57 : : bool operator!=(
58 : : const Simstr & S) const;
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 : :
68 : :
69 : : // 'List of characters' - functions
70 : : // insert - functions
71 : : void push_front(
72 : : char c);
73 : : void push_back(
74 : : char c);
75 : : void push_front(
76 : : const Simstr & S);
77 : : void push_back(
78 : : const Simstr & S);
79 : : // remove - functions
80 : : void remove(
81 : : int pos,
82 : : int anzahl = 1);
83 : : void remove_trailing_blanks();
84 : :
85 : : // search functions
86 : : int pos_first(
87 : : char c) const;
88 : : int pos_last(
89 : : char c) const;
90 : : bool is_empty() const; // Only true if object == "".
91 : : bool is_no_text() const; // String may contain spaces or tabs.
92 : :
93 : : // substitution functions
94 : : void replace_all(
95 : : char oldCh,
96 : : char newCh);
97 : : // token functions
98 : : // get...-functions return the token, separated by char 'c' and leave the object unchanged.
99 : : // take...-functions return the same, but remove the token and the corresponding separator from the object.
100 : : Simstr get_last_token(
101 : : char c) const;
102 : :
103 : : private:
104 : : char * sz;
105 : : int len;
106 : : };
107 : :
108 : : // Simstr - char* / char - concatenations
109 : : Simstr operator+(const char * str, const Simstr & S);
110 : : Simstr operator+(const Simstr & S, const char * str);
111 : : Simstr operator+(char c, const Simstr & S);
112 : : Simstr operator+(const Simstr & S, char c);
113 : :
114 : : // Simstr - char* - comparison operators
115 : : bool operator==(const Simstr & S, const char * str);
116 : : bool operator!=(const Simstr & S, const char * str);
117 : : bool operator<(const Simstr & S, const char * str);
118 : : bool operator>(const Simstr & S, const char * str);
119 : : bool operator<=(const Simstr & S, const char * str);
120 : : bool operator>=(const Simstr & S, const char * str);
121 : : bool operator==(const char * str, const Simstr & S);
122 : : bool operator!=(const char * str, const Simstr & S);
123 : : bool operator<(const char * str, const Simstr & S);
124 : : bool operator>(const char * str, const Simstr & S);
125 : : bool operator<=(const char * str, const Simstr & S);
126 : : bool operator>=(const char * str, const Simstr & S);
127 : :
128 : :
129 : : inline char *
130 : : Simstr::s() { return sz; }
131 : : inline int
132 : 500 : Simstr::l() const { return len; }
133 : : inline
134 : 1742 : Simstr::operator const char*() const { return sz; }
135 : : inline bool
136 : 0 : Simstr::is_empty() const { return len == 0; }
137 : :
138 : :
139 : : #endif
140 : :
141 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|