dom_stringimpl.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _DOM_DOMStringImpl_h_
00025 #define _DOM_DOMStringImpl_h_
00026
00027 #include <qstring.h>
00028
00029 #include "dom/dom_misc.h"
00030 #include "misc/khtmllayout.h"
00031 #include "misc/shared.h"
00032
00033 #define QT_ALLOC_QCHAR_VEC( N ) (QChar*) new char[ sizeof(QChar)*( N ) ]
00034 #define QT_DELETE_QCHAR_VEC( P ) delete[] ((char*)( P ))
00035
00036 namespace DOM {
00037
00038 class DOMStringImpl : public khtml::Shared<DOMStringImpl>
00039 {
00040 protected:
00041 DOMStringImpl() { s = 0, l = 0; }
00042 public:
00043 DOMStringImpl(const QChar *str, unsigned int len) {
00044 bool havestr = str && len;
00045 s = QT_ALLOC_QCHAR_VEC( havestr ? len : 1 );
00046 if(str && len) {
00047 memcpy( s, str, len * sizeof(QChar) );
00048 l = len;
00049 } else {
00050
00051 s[0] = 0x0;
00052 l = 0;
00053 }
00054 }
00055
00056 DOMStringImpl(const char *str);
00057 DOMStringImpl(const QChar &ch) {
00058 s = QT_ALLOC_QCHAR_VEC( 1 );
00059 s[0] = ch;
00060 l = 1;
00061 }
00062 ~DOMStringImpl() {
00063 if(s) QT_DELETE_QCHAR_VEC(s);
00064 }
00065
00066 void append(DOMStringImpl *str);
00067 void insert(DOMStringImpl *str, unsigned int pos);
00068 void truncate(int len);
00069 void remove(unsigned int pos, int len=1);
00070 DOMStringImpl *split(unsigned int pos);
00071 DOMStringImpl *copy() const {
00072 return new DOMStringImpl(s,l);
00073 };
00074
00075 DOMStringImpl *substring(unsigned int pos, unsigned int len);
00076
00077 const QChar &operator [] (int pos)
00078 { return *(s+pos); }
00079
00080 khtml::Length toLength() const;
00081
00082
00083 int toInt(bool* ok = 0) const;
00084
00085 khtml::Length* toLengthArray(int& len) const;
00086 bool isLower() const;
00087 DOMStringImpl *lower() const;
00088 DOMStringImpl *upper() const;
00089 DOMStringImpl *capitalize();
00090
00091 unsigned int l;
00092 QChar *s;
00093 };
00094
00095 }
00096 #endif
This file is part of the documentation for kdelibs Version 3.1.5.