KHtml

dom_string.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright 1999 Lars Knoll ([email protected])
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 #ifndef _DOM_DOMString_h_
23 #define _DOM_DOMString_h_
24 
25 #include <khtml_export.h>
26 #include "khtml_debug.h"
27 #include <QString>
28 #include <limits.h>
29 
30 namespace DOM
31 {
32 
33 class DOMStringImpl;
34 
44 class KHTML_EXPORT DOMString
45 {
46  friend class CharacterDataImpl;
47  friend KHTML_EXPORT bool operator==(const DOMString &a, const char *b);
48 public:
52  DOMString() : impl(nullptr) {}
53 
54  DOMString(const QChar *str, uint len);
55  DOMString(const QString &);
56  DOMString(const char *str);
60  DOMString(const char *str, uint len);
61  DOMString(DOMStringImpl *i);
62 
63  virtual ~DOMString();
64 
65  // assign and copy
66  DOMString(const DOMString &str);
67  DOMString &operator =(const DOMString &str);
68 
72  DOMString &operator += (const DOMString &str);
76  DOMString operator + (const DOMString &str);
77 
78  void insert(DOMString str, uint pos);
79 
84  const QChar &operator [](unsigned int i) const;
85 
86  int find(const QChar c, int start = 0) const;
87  int reverseFind(const QChar c, int start = -1) const;
88 
89  DOMString substring(unsigned pos, unsigned len = UINT_MAX) const;
90 
91  uint length() const;
92  void truncate(unsigned int len);
93  void remove(unsigned int pos, int len = 1);
97  DOMString split(unsigned int pos);
98 
102  DOMString lower() const;
106  DOMString upper() const;
107 
108  QChar *unicode() const;
109  // for WebCore API compatibility
110  inline QChar *characters() const
111  {
112  return unicode();
113  }
114  QString string() const;
115 
116  int toInt() const;
117  int toInt(bool *ok) const;
118  float toFloat(bool *ok = nullptr) const;
119  bool percentage(int &_percentage) const;
120 
121  static DOMString number(float f);
122 
123  DOMString copy() const;
124 
125  bool isNull() const
126  {
127  return (impl == nullptr);
128  }
129  bool isEmpty() const;
130 
131  bool endsWith(const DOMString &str) const;
132  bool startsWith(const DOMString &str) const;
133 
139  DOMString trimSpaces() const;
140 
145  DOMStringImpl *implementation() const
146  {
147  return impl;
148  }
149 
150  static DOMString format(const char *format, ...)
151 #if defined(__GNUC__)
152  __attribute__((format(printf, 1, 2)))
153 #endif
154  ;
155 
156 protected:
157  DOMStringImpl *impl;
158 };
159 
160 inline QDebug operator<<(QDebug stream, const DOMString &string)
161 {
162  return (stream << (string.implementation() ? string.string() : QString::fromLatin1("null")));
163 }
164 
165 KHTML_EXPORT bool operator==(const DOMString &a, const DOMString &b);
166 KHTML_EXPORT bool operator==(const DOMString &a, const QString &b);
167 KHTML_EXPORT bool operator==(const DOMString &a, const char *b);
168 inline bool operator!=(const DOMString &a, const DOMString &b)
169 {
170  return !(a == b);
171 }
172 inline bool operator!=(const DOMString &a, const QString &b)
173 {
174  return !(a == b);
175 }
176 inline bool operator!=(const DOMString &a, const char *b)
177 {
178  return !(a == b);
179 }
180 inline bool strcmp(const DOMString &a, const DOMString &b)
181 {
182  return a != b;
183 }
184 
185 // returns false when equal, true otherwise (ignoring case)
186 KHTML_EXPORT bool strcasecmp(const DOMString &a, const DOMString &b);
187 KHTML_EXPORT bool strcasecmp(const DOMString &a, const char *b);
188 
189 }
190 #endif
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
DOMString()
default constructor.
Definition: dom_string.h:52
This library provides a full-featured HTML parser and widget.
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
DOMStringImpl * implementation() const
Definition: dom_string.h:145
QString fromLatin1(const char *str, int size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 22:46:16 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.