• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdehtml
 

tdehtml

  • tdehtml
  • dom
dom_string.cpp
1 
22 #include "dom/dom_string.h"
23 #include "xml/dom_stringimpl.h"
24 
25 
26 using namespace DOM;
27 
28 
29 DOMString::DOMString(const TQChar *str, uint len)
30 {
31  impl = new DOMStringImpl( str, len );
32  impl->ref();
33 }
34 
35 DOMString::DOMString(const TQString &str)
36 {
37  if (str.isNull()) {
38  impl = 0;
39  return;
40  }
41 
42  impl = new DOMStringImpl( str.unicode(), str.length() );
43  impl->ref();
44 }
45 
46 DOMString::DOMString(const char *str)
47 {
48  if (!str) {
49  impl = 0;
50  return;
51  }
52 
53  impl = new DOMStringImpl( str );
54  impl->ref();
55 }
56 
57 DOMString::DOMString(DOMStringImpl *i)
58 {
59  impl = i;
60  if(impl) impl->ref();
61 }
62 
63 DOMString::DOMString(const DOMString &other)
64 {
65  impl = other.impl;
66  if(impl) impl->ref();
67 }
68 
69 DOMString::~DOMString()
70 {
71  if(impl) impl->deref();
72 }
73 
74 DOMString &DOMString::operator =(const DOMString &other)
75 {
76  if ( impl != other.impl ) {
77  if(impl) impl->deref();
78  impl = other.impl;
79  if(impl) impl->ref();
80  }
81  return *this;
82 }
83 
84 DOMString &DOMString::operator += (const DOMString &str)
85 {
86  if(!impl)
87  {
88  // ### FIXME!!!
89  impl = str.impl;
90  if (impl)
91  impl->ref();
92  return *this;
93  }
94  if(str.impl)
95  {
96  DOMStringImpl *i = impl->copy();
97  impl->deref();
98  impl = i;
99  impl->ref();
100  impl->append(str.impl);
101  }
102  return *this;
103 }
104 
105 DOMString DOMString::operator + (const DOMString &str)
106 {
107  if(!impl) return str.copy();
108  if(str.impl)
109  {
110  DOMString s = copy();
111  s += str;
112  return s;
113  }
114 
115  return copy();
116 }
117 
118 void DOMString::insert(DOMString str, uint pos)
119 {
120  if(!impl)
121  {
122  impl = str.impl->copy();
123  impl->ref();
124  }
125  else
126  impl->insert(str.impl, pos);
127 }
128 
129 
130 const TQChar &DOMString::operator [](unsigned int i) const
131 {
132  static const TQChar nullChar = 0;
133 
134  if(!impl || i >= impl->l ) return nullChar;
135 
136  return *(impl->s+i);
137 }
138 
139 int DOMString::find(const TQChar c, int start) const
140 {
141  unsigned int l = start;
142  if(!impl || l >= impl->l ) return -1;
143  while( l < impl->l )
144  {
145  if( *(impl->s+l) == c ) return l;
146  l++;
147  }
148  return -1;
149 }
150 
151 uint DOMString::length() const
152 {
153  if(!impl) return 0;
154  return impl->l;
155 }
156 
157 void DOMString::truncate( unsigned int len )
158 {
159  if(impl) impl->truncate(len);
160 }
161 
162 void DOMString::remove(unsigned int pos, int len)
163 {
164  if(impl) impl->remove(pos, len);
165 }
166 
167 DOMString DOMString::split(unsigned int pos)
168 {
169  if(!impl) return DOMString();
170  return impl->split(pos);
171 }
172 
173 DOMString DOMString::lower() const
174 {
175  if(!impl) return DOMString();
176  return impl->lower();
177 }
178 
179 DOMString DOMString::upper() const
180 {
181  if(!impl) return DOMString();
182  return impl->upper();
183 }
184 
185 bool DOMString::percentage(int &_percentage) const
186 {
187  if(!impl || !impl->l) return false;
188 
189  if ( *(impl->s+impl->l-1) != TQChar('%'))
190  return false;
191 
192  _percentage = TQConstString(impl->s, impl->l-1).string().toInt();
193  return true;
194 }
195 
196 TQChar *DOMString::unicode() const
197 {
198  if(!impl) return 0;
199  return impl->unicode();
200 }
201 
202 TQString DOMString::string() const
203 {
204  if(!impl) return TQString::null;
205 
206  return impl->string();
207 }
208 
209 int DOMString::toInt() const
210 {
211  if(!impl) return 0;
212 
213  return impl->toInt();
214 }
215 
216 DOMString DOMString::copy() const
217 {
218  if(!impl) return DOMString();
219  return impl->copy();
220 }
221 
222 // ------------------------------------------------------------------------
223 
224 bool DOM::strcasecmp( const DOMString &as, const DOMString &bs )
225 {
226  if ( as.length() != bs.length() ) return true;
227 
228  const TQChar *a = as.unicode();
229  const TQChar *b = bs.unicode();
230  if ( a == b ) return false;
231  if ( !( a && b ) ) return true;
232  int l = as.length();
233  while ( l-- ) {
234  if ( *a != *b && a->lower() != b->lower() ) return true;
235  a++,b++;
236  }
237  return false;
238 }
239 
240 bool DOM::strcasecmp( const DOMString &as, const char* bs )
241 {
242  const TQChar *a = as.unicode();
243  int l = as.length();
244  if ( !bs ) return ( l != 0 );
245  while ( l-- ) {
246  if ( a->latin1() != *bs ) {
247  char cc = ( ( *bs >= 'A' ) && ( *bs <= 'Z' ) ) ? ( ( *bs ) + 'a' - 'A' ) : ( *bs );
248  if ( a->lower().latin1() != cc ) return true;
249  }
250  a++, bs++;
251  }
252  return ( *bs != '\0' );
253 }
254 
255 bool DOMString::isEmpty() const
256 {
257  return (!impl || impl->l == 0);
258 }
259 
260 //-----------------------------------------------------------------------------
261 
262 bool DOM::operator==( const DOMString &a, const DOMString &b )
263 {
264  unsigned int l = a.length();
265 
266  if( l != b.length() ) return false;
267 
268  if(!memcmp(a.unicode(), b.unicode(), l*sizeof(TQChar)))
269  return true;
270  return false;
271 }
272 
273 bool DOM::operator==( const DOMString &a, const TQString &b )
274 {
275  unsigned int l = a.length();
276 
277  if( l != b.length() ) return false;
278 
279  if(!memcmp(a.unicode(), b.unicode(), l*sizeof(TQChar)))
280  return true;
281  return false;
282 }
283 
284 bool DOM::operator==( const DOMString &a, const char *b )
285 {
286  DOMStringImpl* aimpl = a.impl;
287  if ( !b ) return !aimpl;
288 
289  if ( aimpl ) {
290  int alen = aimpl->l;
291  const TQChar *aptr = aimpl->s;
292  while ( alen-- ) {
293  unsigned char c = *b++;
294  if ( !c || ( *aptr++ ).unicode() != c )
295  return false;
296  }
297  }
298 
299  return !*b;
300 }
DOM::DOMString::lower
DOMString lower() const
Returns a lowercase version of the string.
Definition: dom_string.cpp:173
DOM::DOMString::split
DOMString split(unsigned int pos)
Splits the string into two.
Definition: dom_string.cpp:167
DOM::DOMString::operator+
DOMString operator+(const DOMString &str)
add two DOMString's
Definition: dom_string.cpp:105
DOM::DOMString
This class implements the basic string we use in the DOM.
Definition: dom_string.h:43
DOM::DOMString::operator[]
const TQChar & operator[](unsigned int i) const
The character at position i of the DOMString.
Definition: dom_string.cpp:130
DOM::DOMString::DOMString
DOMString()
default constructor.
Definition: dom_string.h:51
DOM::DOMString::operator+=
DOMString & operator+=(const DOMString &str)
append str to this string
Definition: dom_string.cpp:84
DOM
The Document Object Model (DOM) is divided into two parts, the COREDOM core DOM, specifying some core...
Definition: design.h:56
DOM::DOMString::upper
DOMString upper() const
Returns an uppercase version of the string.
Definition: dom_string.cpp:179

tdehtml

Skip menu "tdehtml"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdehtml

Skip menu "tdehtml"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdehtml by doxygen 1.8.8
This website is maintained by Timothy Pearson.