/src/librevenge/inc/librevenge/RVNGString.h
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
2 | | /* librevenge |
3 | | * Version: MPL 2.0 / LGPLv2.1+ |
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 | | * Major Contributor(s): |
10 | | * Copyright (C) 2004 William Lachance (wrlach@gmail.com) |
11 | | * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
12 | | * |
13 | | * For minor contributions see the git repository. |
14 | | * |
15 | | * Alternatively, the contents of this file may be used under the terms |
16 | | * of the GNU Lesser General Public License Version 2.1 or later |
17 | | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
18 | | * applicable instead of those above. |
19 | | */ |
20 | | |
21 | | #ifndef RVNGSTRING_H |
22 | | #define RVNGSTRING_H |
23 | | |
24 | | #include "librevenge-api.h" |
25 | | |
26 | | namespace librevenge |
27 | | { |
28 | | |
29 | | class RVNGStringImpl; |
30 | | |
31 | | /** UTF-8 string. |
32 | | */ |
33 | | class REVENGE_API RVNGString |
34 | | { |
35 | | public: |
36 | | RVNGString(); |
37 | | RVNGString(const RVNGString &other); |
38 | | RVNGString(const char *str); |
39 | | ~RVNGString(); |
40 | | |
41 | | /** Create a new string from \a s as escaped XML. |
42 | | * |
43 | | * This function can be used instead of #appendEscapedXML(const RVNGString&) in contexts |
44 | | * where only a temporary string is needed. |
45 | | * |
46 | | * @sa appendEscapedXML(const RVNGString&) |
47 | | */ |
48 | | static RVNGString escapeXML(const RVNGString &s); |
49 | | |
50 | | /** Create a new string from \a s as escaped XML. |
51 | | * |
52 | | * This function can be used instead of #appendEscapedXML(const char*) in contexts |
53 | | * where only a temporary string is needed. |
54 | | * |
55 | | * @sa appendEscapedXML(const char*) |
56 | | */ |
57 | | static RVNGString escapeXML(const char *s); |
58 | | |
59 | | const char *cstr() const; |
60 | | |
61 | | /** Return the number of UTF-8 characters. |
62 | | * |
63 | | * @sa size() |
64 | | */ |
65 | | int len() const; |
66 | | /** Return the size in bytes of the data buffer. |
67 | | * |
68 | | * This is equivalent to <code>strlen(str.cstr())</code> |
69 | | * |
70 | | * @sa len() |
71 | | */ |
72 | | unsigned long size() const; |
73 | | |
74 | | bool empty() const; |
75 | | |
76 | | void sprintf(const char *format, ...) REVENGE_ATTRIBUTE_PRINTF(2, 3); |
77 | | void append(const RVNGString &s); |
78 | | void append(const char *s); |
79 | | void append(const char c); |
80 | | |
81 | | /** Append the content of @a s as escaped XML. |
82 | | |
83 | | @sa escapeXML(const RVNGString&) |
84 | | */ |
85 | | void appendEscapedXML(const RVNGString &s); |
86 | | |
87 | | /** Append the content of @a s as escaped XML. |
88 | | |
89 | | @sa escapeXML(const char*) |
90 | | */ |
91 | | void appendEscapedXML(const char *s); |
92 | | |
93 | | void clear(); |
94 | | RVNGString &operator=(const RVNGString &str); |
95 | | RVNGString &operator=(const char *s); |
96 | | |
97 | | // Comparison |
98 | | bool operator==(const char *s) const; |
99 | | bool operator==(const RVNGString &str) const; |
100 | | inline bool operator!=(const char *s) const |
101 | 1.33M | { |
102 | 1.33M | return !operator==(s); |
103 | 1.33M | } |
104 | | inline bool operator!=(const RVNGString &str) const |
105 | 10.8M | { |
106 | 10.8M | return !operator==(str); |
107 | 10.8M | } |
108 | | bool operator<(const char *s) const; |
109 | | bool operator<(const RVNGString &str) const; |
110 | | inline bool operator<=(const char *s) const |
111 | 0 | { |
112 | 0 | return operator==(s) || operator<(s); |
113 | 0 | } |
114 | | inline bool operator<=(const RVNGString &str) const |
115 | 2.06M | { |
116 | 2.06M | return operator==(str) || operator<(str); |
117 | 2.06M | } |
118 | | inline bool operator>=(const char *s) const |
119 | 0 | { |
120 | 0 | return !operator<(s); |
121 | 0 | } |
122 | | inline bool operator>=(const RVNGString &str) const |
123 | 0 | { |
124 | 0 | return !operator<(str); |
125 | 0 | } |
126 | | inline bool operator>(const char *s) const |
127 | 0 | { |
128 | 0 | return !operator<=(s); |
129 | 0 | } |
130 | | inline bool operator>(const RVNGString &str) const |
131 | 2.06M | { |
132 | 2.06M | return !operator<=(str); |
133 | 2.06M | } |
134 | | |
135 | | class REVENGE_API Iter |
136 | | { |
137 | | public: |
138 | | Iter(const RVNGString &str); |
139 | | virtual ~Iter(); |
140 | | void rewind(); |
141 | | bool next(); |
142 | | bool last(); |
143 | | const char *operator()() const; |
144 | | private: |
145 | | Iter(const Iter &); |
146 | | Iter &operator=(const Iter &); |
147 | | RVNGStringImpl *m_stringImpl; |
148 | | int m_pos; |
149 | | mutable char *m_curChar; |
150 | | }; |
151 | | |
152 | | private: |
153 | | RVNGStringImpl *m_stringImpl; |
154 | | }; |
155 | | |
156 | | } |
157 | | |
158 | | #endif |
159 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |