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 * Splits the string into two. The original string gets truncated to pos, and the rest is returned.
89 DOMString split(unsigned int pos);
92 * Returns a lowercase version of the string
94 DOMString lower() const;
96 * Returns an uppercase version of the string
98 DOMString upper() const;
100 QChar *unicode() const;
101 QString string() const;
104 khtml::Length* toLengthArray(int& len) const;
105 bool percentage(int &_percentage) const;
107 DOMString copy() const;
109 bool isNull() const { return (impl == 0); }
110 bool isEmpty() const;
113 * @internal get a handle to the imlementation of the DOMString
116 DOMStringImpl *implementation() const { return impl; }
119 DOMString(NSString *);
120 operator NSString *() const;
124 // For debugging only, leaks memory.
125 const char *ascii() const;
132 DOMString operator + (const DOMString &a, const DOMString &b);
133 bool operator==( const DOMString &a, const QString &b );
134 bool operator==( const DOMString &a, const char *b );
135 inline bool operator==( const QString &b, const DOMString &a ) { return a == b; }
136 inline bool operator==( const char *b, const DOMString &a ) { return a == b; }
137 inline bool operator!=( const DOMString &a, const DOMString &b ) { return !(a==b); }
138 inline bool operator!=( const DOMString &a, const QString &b ) { return !(a==b); }
139 inline bool operator!=( const DOMString &a, const char *b ) { return !(a==b); }
140 inline bool operator!=( const QString &b, const DOMString &a ) { return !(a==b); }
141 inline bool operator!=( const char *b, const DOMString &a ) { return !(a==b); }
142 inline bool strcmp( const DOMString &a, const DOMString &b ) { return a != b; }
144 // returns false when equal, true otherwise (ignoring case)
145 bool strcasecmp( const DOMString &a, const DOMString &b );
146 bool strcasecmp( const DOMString& a, const char* b );