2 * This file is part of the DOM implementation for KDE.
4 * (C) 1999 Lars Knoll (knoll@kde.org)
5 * Copyright (C) 2004 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #ifndef _DOM_DOMString_h_
24 #define _DOM_DOMString_h_
27 #include <xml/dom_stringimpl.h>
38 * This class implements the basic string we use in the DOM. We do not use
39 * QString for 2 reasons: Memory overhead, and the missing explicit sharing
40 * of strings we need for the DOM.
42 * All DOMStrings are explicitly shared (they behave like pointers), meaning
43 * that modifications to one instance will also modify all others. If you
44 * wish to get a DOMString that is independent, use @ref copy().
48 friend class CharacterDataImpl;
49 friend bool operator==( const DOMString &a, const char *b );
50 friend bool operator==( const DOMString &a, const DOMString &b );
53 * default constructor. Gives an empty DOMString
55 DOMString() : impl(0) { }
57 DOMString(const QChar *str, uint len);
58 DOMString(const QString &);
59 DOMString(const char *str);
60 DOMString(DOMStringImpl *i);
61 ~DOMString() { if(impl) impl->deref(); }
65 DOMString(const DOMString &str);
66 DOMString &operator =(const DOMString &str);
69 * append str to this string
71 DOMString &operator += (const DOMString &str);
73 void insert(DOMString str, uint pos);
76 * The character at position i of the DOMString. If i >= length(), the
77 * character returned will be 0.
79 const QChar &operator [](unsigned int i) const;
81 int find(const QChar c, int start = 0) const;
84 void truncate( unsigned int len );
85 void remove(unsigned int pos, int len=1);
87 DOMString substring(unsigned int pos, unsigned int len);
90 * Splits the string into two. The original string gets truncated to pos, and the rest is returned.
92 DOMString split(unsigned int pos);
95 * Returns a lowercase version of the string
97 DOMString lower() const;
99 * Returns an uppercase version of the string
101 DOMString upper() const;
103 QChar *unicode() const;
104 QString string() const;
107 khtml::Length* toLengthArray(int& len) const;
108 bool percentage(int &_percentage) const;
110 DOMString copy() const;
112 bool isNull() const { return (impl == 0); }
113 bool isEmpty() const;
116 * @internal get a handle to the imlementation of the DOMString
119 DOMStringImpl *implementation() const { return impl; }
122 DOMString(NSString *);
123 operator NSString *() const;
127 // For debugging only, leaks memory.
128 const char *ascii() const;
135 DOMString operator + (const DOMString &a, const DOMString &b);
136 bool operator==( const DOMString &a, const QString &b );
137 bool operator==( const DOMString &a, const char *b );
138 inline bool operator==( const QString &b, const DOMString &a ) { return a == b; }
139 inline bool operator==( const char *b, const DOMString &a ) { return a == b; }
140 inline bool operator!=( const DOMString &a, const DOMString &b ) { return !(a==b); }
141 inline bool operator!=( const DOMString &a, const QString &b ) { return !(a==b); }
142 inline bool operator!=( const DOMString &a, const char *b ) { return !(a==b); }
143 inline bool operator!=( const QString &b, const DOMString &a ) { return !(a==b); }
144 inline bool operator!=( const char *b, const DOMString &a ) { return !(a==b); }
145 inline bool strcmp( const DOMString &a, const DOMString &b ) { return a != b; }
147 // returns false when equal, true otherwise (ignoring case)
148 bool strcasecmp( const DOMString &a, const DOMString &b );
149 bool strcasecmp( const DOMString& a, const char* b );