KHtml
22 #include "dom/dom_string.h"
23 #include "xml/dom_stringimpl.h"
25 #include <wtf/Vector.h>
35 impl =
new DOMStringImpl(str, len);
57 impl =
new DOMStringImpl(str);
67 impl =
new DOMStringImpl(str, len);
87 DOMString::~DOMString()
96 if (impl != other.impl) {
119 DOMStringImpl *i = impl->copy();
123 impl->append(str.impl);
142 void DOMString::insert(
DOMString str, uint pos)
145 impl = str.impl->copy();
148 impl->insert(str.impl, pos);
154 static const QChar nullChar = 0;
156 if (!impl || i >= impl->l) {
160 return *(impl->s + i);
163 int DOMString::find(
const QChar c,
int start)
const
165 unsigned int l =
start;
166 if (!impl || l >= impl->l) {
169 while (l < impl->l) {
170 if (*(impl->s + l) == c) {
178 int DOMString::reverseFind(
const QChar c,
int start)
const
180 unsigned int l =
start;
181 if (!impl || l < -impl->l) {
186 if (*(impl->s + l) == c) {
197 DOMString DOMString::substring(
unsigned pos,
unsigned len)
const
199 return (impl) ? impl->substring(pos, len) :
DOMString();
202 uint DOMString::length()
const
210 void DOMString::truncate(
unsigned int len)
217 void DOMString::remove(
unsigned int pos,
int len)
220 impl->remove(pos, len);
229 return impl->split(pos);
237 return impl->lower();
245 return impl->upper();
248 bool DOMString::percentage(
int &_percentage)
const
250 if (!impl || !impl->l) {
254 if (*(impl->s + impl->l - 1) !=
QChar(
'%')) {
262 QChar *DOMString::unicode()
const
267 return impl->unicode();
270 QString DOMString::string()
const
276 return impl->string();
279 int DOMString::toInt()
const
285 return impl->toInt();
288 int DOMString::toInt(
bool *ok)
const
295 return impl->toInt(ok);
298 float DOMString::toFloat(
bool *ok)
const
306 return impl->toFloat(ok);
322 bool DOMString::endsWith(
const DOMString &str)
const
324 if (str.length() > length()) {
330 bool DOMString::startsWith(
const DOMString &str)
const
332 if (str.length() > length()) {
338 static inline bool isSpaceCharacter(
const ushort &c)
341 return ((c < 0x0021) &&
342 (c == 0x0020 || c == 0x0009 || c == 0x000A || c == 0x000C || c == 0x000D));
347 if (!impl || !impl->l) {
351 const QChar *s = impl->s;
352 unsigned int start = 0;
353 unsigned int end = impl->l - 1;
355 while ((
start <= end) && isSpaceCharacter(s[
start].unicode())) {
363 while (end && isSpaceCharacter(s[end].unicode())) {
367 const unsigned int len = end -
start + 1;
368 DOMStringImpl *out =
new DOMStringImpl(s +
start, len);
371 unsigned int newLen = 0;
372 for (
unsigned int k = 0; k < len; ++k) {
373 QChar ch = out->s[k];
375 out->s[newLen++] = ch;
390 bool DOM::strcasecmp(
const DOMString &as,
const char *bs)
392 const QChar *a = as.unicode();
399 char cc = ((*bs >=
'A') && (*bs <=
'Z')) ? ((*bs) +
'a' -
'A') : (*bs);
406 return (*bs !=
'\0');
409 bool DOMString::isEmpty()
const
411 return (!impl || impl->l == 0);
414 DOMString DOMString::format(
const char *format, ...)
417 va_start(args, format);
419 Vector<char, 256> buffer;
423 int result = _vscprintf(format, args);
426 int result = qvsnprintf(&ch, 1, format, args);
434 va_start(args, format);
445 unsigned len = result;
446 buffer.grow(len + 1);
449 qvsnprintf(buffer.data(), buffer.size(), format, args);
454 return new DOMStringImpl(buffer.data());
472 if (!memcmp(a.unicode(), b.
unicode(), l *
sizeof(
QChar))) {
478 bool DOM::operator==(
const DOMString &a,
const char *b)
480 DOMStringImpl *aimpl = a.impl;
487 const QChar *aptr = aimpl->s;
489 unsigned char c = *b++;
490 if (!c || (*aptr++).unicode() != c) {
DOMString()
default constructor.
bool isNull() const const
DOMString trimSpaces() const
Returns a string with Space Characters removed from the start and the end.
QString number(int n, int base)
QChar toLower() const const
DOMString & operator+=(const DOMString &str)
append str to this string
This library provides a full-featured HTML parser and widget.
const QChar * unicode() const const
Q_SCRIPTABLE Q_NOREPLY void start()
int toInt(bool *ok, int base) const const
DOMString upper() const
Returns an uppercase version of the string.
DOMString split(unsigned int pos)
Splits the string into two.
const QChar & operator[](unsigned int i) const
The character at position i of the DOMString.
This class implements the basic string we use in the DOM.
DOMString operator+(const DOMString &str)
add two DOMString's
QString fromRawData(const QChar *unicode, int size)
DOMString lower() const
Returns a lowercase version of the string.
char toLatin1() const const
DOMStringImpl * implementation() const
ushort unicode() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 28 2023 03:53:39 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.