22 #include "dom/dom_string.h"
23 #include "xml/dom_stringimpl.h"
31 impl =
new DOMStringImpl( str, len );
42 impl =
new DOMStringImpl( str.unicode(), str.length() );
53 impl =
new DOMStringImpl( str );
69 DOMString::~DOMString()
71 if(impl) impl->deref();
76 if ( impl != other.impl ) {
77 if(impl) impl->deref();
96 DOMStringImpl *i = impl->copy();
100 impl->append(str.impl);
107 if(!impl)
return str.copy();
118 void DOMString::insert(
DOMString str, uint pos)
122 impl = str.impl->copy();
126 impl->insert(str.impl, pos);
132 static const TQChar nullChar = 0;
134 if(!impl || i >= impl->l )
return nullChar;
139 int DOMString::find(
const TQChar c,
int start)
const
141 unsigned int l = start;
142 if(!impl || l >= impl->l )
return -1;
145 if( *(impl->s+l) == c )
return l;
151 uint DOMString::length()
const
157 void DOMString::truncate(
unsigned int len )
159 if(impl) impl->truncate(len);
162 void DOMString::remove(
unsigned int pos,
int len)
164 if(impl) impl->remove(pos, len);
170 return impl->split(pos);
176 return impl->lower();
182 return impl->upper();
185 bool DOMString::percentage(
int &_percentage)
const
187 if(!impl || !impl->l)
return false;
189 if ( *(impl->s+impl->l-1) != TQChar(
'%'))
192 _percentage = TQConstString(impl->s, impl->l-1).string().toInt();
196 TQChar *DOMString::unicode()
const
199 return impl->unicode();
202 TQString DOMString::string()
const
204 if(!impl)
return TQString::null;
206 return impl->string();
209 int DOMString::toInt()
const
213 return impl->toInt();
226 if ( as.length() != bs.length() )
return true;
228 const TQChar *a = as.unicode();
229 const TQChar *b = bs.unicode();
230 if ( a == b )
return false;
231 if ( !( a && b ) )
return true;
234 if ( *a != *b && a->lower() != b->lower() )
return true;
240 bool DOM::strcasecmp(
const DOMString &as,
const char* bs )
242 const TQChar *a = as.unicode();
244 if ( !bs )
return ( l != 0 );
246 if ( a->latin1() != *bs ) {
247 char cc = ( ( *bs >=
'A' ) && ( *bs <=
'Z' ) ) ? ( ( *bs ) +
'a' -
'A' ) : ( *bs );
248 if ( a->lower().latin1() != cc )
return true;
252 return ( *bs !=
'\0' );
255 bool DOMString::isEmpty()
const
257 return (!impl || impl->l == 0);
264 unsigned int l = a.length();
266 if( l != b.length() )
return false;
268 if(!memcmp(a.unicode(), b.unicode(), l*
sizeof(TQChar)))
273 bool DOM::operator==(
const DOMString &a,
const TQString &b )
275 unsigned int l = a.length();
277 if( l != b.length() )
return false;
279 if(!memcmp(a.unicode(), b.unicode(), l*
sizeof(TQChar)))
284 bool DOM::operator==(
const DOMString &a,
const char *b )
286 DOMStringImpl* aimpl = a.impl;
287 if ( !b )
return !aimpl;
291 const TQChar *aptr = aimpl->s;
293 unsigned char c = *b++;
294 if ( !c || ( *aptr++ ).unicode() != c )
This class implements the basic string we use in the DOM.
DOMString()
default constructor.
const TQChar & operator[](unsigned int i) const
The character at position i of the DOMString.
DOMString & operator+=(const DOMString &str)
append str to this string
DOMString upper() const
Returns an uppercase version of the string.
DOMString split(unsigned int pos)
Splits the string into two.
DOMString lower() const
Returns a lowercase version of the string.
DOMString operator+(const DOMString &str)
add two DOMString's
The Document Object Model (DOM) is divided into two parts, the COREDOM core DOM, specifying some core...