khtml Library API Documentation

dom_string.cpp

00001 00022 #include "dom/dom_string.h" 00023 #include "xml/dom_stringimpl.h" 00024 00025 00026 using namespace DOM; 00027 00028 00029 DOMString::DOMString(const QChar *str, uint len) 00030 { 00031 impl = new DOMStringImpl( str, len ); 00032 impl->ref(); 00033 } 00034 00035 DOMString::DOMString(const QString &str) 00036 { 00037 if (str.isNull()) { 00038 impl = 0; 00039 return; 00040 } 00041 00042 impl = new DOMStringImpl( str.unicode(), str.length() ); 00043 impl->ref(); 00044 } 00045 00046 DOMString::DOMString(const char *str) 00047 { 00048 if (!str) { 00049 impl = 0; 00050 return; 00051 } 00052 00053 impl = new DOMStringImpl( str ); 00054 impl->ref(); 00055 } 00056 00057 DOMString::DOMString(DOMStringImpl *i) 00058 { 00059 impl = i; 00060 if(impl) impl->ref(); 00061 } 00062 00063 DOMString::DOMString(const DOMString &other) 00064 { 00065 impl = other.impl; 00066 if(impl) impl->ref(); 00067 } 00068 00069 DOMString::~DOMString() 00070 { 00071 if(impl) impl->deref(); 00072 } 00073 00074 DOMString &DOMString::operator =(const DOMString &other) 00075 { 00076 if ( impl != other.impl ) { 00077 if(impl) impl->deref(); 00078 impl = other.impl; 00079 if(impl) impl->ref(); 00080 } 00081 return *this; 00082 } 00083 00084 DOMString &DOMString::operator += (const DOMString &str) 00085 { 00086 if(!impl) 00087 { 00088 // ### FIXME!!! 00089 impl = str.impl; 00090 impl->ref(); 00091 return *this; 00092 } 00093 if(str.impl) 00094 { 00095 DOMStringImpl *i = impl->copy(); 00096 impl->deref(); 00097 impl = i; 00098 impl->ref(); 00099 impl->append(str.impl); 00100 } 00101 return *this; 00102 } 00103 00104 DOMString DOMString::operator + (const DOMString &str) 00105 { 00106 if(!impl) return str.copy(); 00107 if(str.impl) 00108 { 00109 DOMString s = copy(); 00110 s += str; 00111 return s; 00112 } 00113 00114 return copy(); 00115 } 00116 00117 void DOMString::insert(DOMString str, uint pos) 00118 { 00119 if(!impl) 00120 { 00121 impl = str.impl->copy(); 00122 impl->ref(); 00123 } 00124 else 00125 impl->insert(str.impl, pos); 00126 } 00127 00128 00129 const QChar &DOMString::operator [](unsigned int i) const 00130 { 00131 static const QChar nullChar = 0; 00132 00133 if(!impl || i >= impl->l ) return nullChar; 00134 00135 return *(impl->s+i); 00136 } 00137 00138 int DOMString::find(const QChar c, int start) const 00139 { 00140 unsigned int l = start; 00141 if(!impl || l >= impl->l ) return -1; 00142 while( l < impl->l ) 00143 { 00144 if( *(impl->s+l) == c ) return l; 00145 l++; 00146 } 00147 return -1; 00148 } 00149 00150 uint DOMString::length() const 00151 { 00152 if(!impl) return 0; 00153 return impl->l; 00154 } 00155 00156 void DOMString::truncate( unsigned int len ) 00157 { 00158 if(impl) impl->truncate(len); 00159 } 00160 00161 void DOMString::remove(unsigned int pos, int len) 00162 { 00163 if(impl) impl->remove(pos, len); 00164 } 00165 00166 DOMString DOMString::split(unsigned int pos) 00167 { 00168 if(!impl) return DOMString(); 00169 return impl->split(pos); 00170 } 00171 00172 DOMString DOMString::lower() const 00173 { 00174 if(!impl) return DOMString(); 00175 return impl->lower(); 00176 } 00177 00178 DOMString DOMString::upper() const 00179 { 00180 if(!impl) return DOMString(); 00181 return impl->upper(); 00182 } 00183 00184 bool DOMString::percentage(int &_percentage) const 00185 { 00186 if(!impl || !impl->l) return false; 00187 00188 if ( *(impl->s+impl->l-1) != QChar('%')) 00189 return false; 00190 00191 _percentage = QConstString(impl->s, impl->l-1).string().toInt(); 00192 return true; 00193 } 00194 00195 QChar *DOMString::unicode() const 00196 { 00197 if(!impl) return 0; 00198 return impl->s; 00199 } 00200 00201 QString DOMString::string() const 00202 { 00203 if(!impl) return QString::null; 00204 00205 return QString(impl->s, impl->l); 00206 } 00207 00208 int DOMString::toInt() const 00209 { 00210 if(!impl) return 0; 00211 00212 return impl->toInt(); 00213 } 00214 00215 DOMString DOMString::copy() const 00216 { 00217 if(!impl) return DOMString(); 00218 return impl->copy(); 00219 } 00220 00221 // ------------------------------------------------------------------------ 00222 00223 bool DOM::strcasecmp( const DOMString &as, const DOMString &bs ) 00224 { 00225 if ( as.length() != bs.length() ) return true; 00226 00227 const QChar *a = as.unicode(); 00228 const QChar *b = bs.unicode(); 00229 if ( a == b ) return false; 00230 if ( !( a && b ) ) return true; 00231 int l = as.length(); 00232 while ( l-- ) { 00233 if ( *a != *b && a->lower() != b->lower() ) return true; 00234 a++,b++; 00235 } 00236 return false; 00237 } 00238 00239 bool DOM::strcasecmp( const DOMString &as, const char* bs ) 00240 { 00241 const QChar *a = as.unicode(); 00242 int l = as.length(); 00243 if ( !bs ) return ( l != 0 ); 00244 while ( l-- ) { 00245 if ( a->latin1() != *bs ) { 00246 char cc = ( ( *bs >= 'A' ) && ( *bs <= 'Z' ) ) ? ( ( *bs ) + 'a' - 'A' ) : ( *bs ); 00247 if ( a->lower().latin1() != cc ) return true; 00248 } 00249 a++, bs++; 00250 } 00251 return ( *bs != '\0' ); 00252 } 00253 00254 bool DOMString::isEmpty() const 00255 { 00256 return (!impl || impl->l == 0); 00257 } 00258 00259 //----------------------------------------------------------------------------- 00260 00261 bool DOM::operator==( const DOMString &a, const DOMString &b ) 00262 { 00263 unsigned int l = a.length(); 00264 00265 if( l != b.length() ) return false; 00266 00267 if(!memcmp(a.unicode(), b.unicode(), l*sizeof(QChar))) 00268 return true; 00269 return false; 00270 } 00271 00272 bool DOM::operator==( const DOMString &a, const QString &b ) 00273 { 00274 unsigned int l = a.length(); 00275 00276 if( l != b.length() ) return false; 00277 00278 if(!memcmp(a.unicode(), b.unicode(), l*sizeof(QChar))) 00279 return true; 00280 return false; 00281 } 00282 00283 bool DOM::operator==( const DOMString &a, const char *b ) 00284 { 00285 DOMStringImpl* aimpl = a.impl; 00286 if ( !b ) return !aimpl; 00287 00288 if ( aimpl ) { 00289 int alen = aimpl->l; 00290 const QChar *aptr = aimpl->s; 00291 while ( alen-- ) { 00292 unsigned char c = *b++; 00293 if ( !c || ( *aptr++ ).unicode() != c ) 00294 return false; 00295 } 00296 } 00297 00298 return !*b; 00299 } 00300
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 16 17:23:44 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003