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 #ifndef _DOM_DOMStringImpl_h_
00024 #define _DOM_DOMStringImpl_h_
00025
00026 #include <stdlib.h>
00027
00028 #include <qstring.h>
00029
00030 #include "dom/dom_misc.h"
00031 #include "misc/khtmllayout.h"
00032 #include "misc/shared.h"
00033
00034 #define QT_ALLOC_QCHAR_VEC( N ) (QChar*) new char[ sizeof(QChar)*( N ) ]
00035 #define QT_DELETE_QCHAR_VEC( P ) delete[] ((char*)( P ))
00036
00037 namespace DOM {
00038
00039 class DOMStringImpl : public khtml::Shared<DOMStringImpl>
00040 {
00041 protected:
00042 DOMStringImpl() { s = 0, l = 0; }
00043 public:
00044 DOMStringImpl(const QChar *str, unsigned int len) {
00045 bool havestr = str && len;
00046 s = QT_ALLOC_QCHAR_VEC( havestr ? len : 1 );
00047 if(str && len) {
00048 memcpy( s, str, len * sizeof(QChar) );
00049 l = len;
00050 } else {
00051
00052 s[0] = 0x0;
00053 l = 0;
00054 }
00055 }
00056
00057 DOMStringImpl(const char *str);
00058 DOMStringImpl(const QChar &ch) {
00059 s = QT_ALLOC_QCHAR_VEC( 1 );
00060 s[0] = ch;
00061 l = 1;
00062 }
00063 ~DOMStringImpl() {
00064 if(s) QT_DELETE_QCHAR_VEC(s);
00065 }
00066
00067 void append(DOMStringImpl *str);
00068 void insert(DOMStringImpl *str, unsigned int pos);
00069 void truncate(int len);
00070 void remove(unsigned int pos, int len=1);
00071 DOMStringImpl *split(unsigned int pos);
00072 DOMStringImpl *copy() const {
00073 return new DOMStringImpl(s,l);
00074 };
00075
00076 DOMStringImpl *substring(unsigned int pos, unsigned int len);
00077
00078 const QChar &operator [] (int pos)
00079 { return *(s+pos); }
00080
00081 khtml::Length toLength() const;
00082
00083
00084 int toInt() const {
00085 return strtol(QConstString(s, l).string().latin1(), 0, 10);
00086 }
00087
00088 int toInt(bool* ok) const {
00089 int len = l;
00090 while(len > 0 && !s[len-1].isDigit())
00091 len--;
00092
00093 return QConstString(s,len).string().toInt(ok);
00094 };
00095
00096 khtml::Length* toLengthArray(int& len) const;
00097 bool isLower() const;
00098 DOMStringImpl *lower() const;
00099 DOMStringImpl *upper() const;
00100 DOMStringImpl *capitalize();
00101
00102 unsigned int l;
00103 QChar *s;
00104 };
00105
00106 };
00107 #endif
This file is part of the documentation for kdelibs Version 3.1.0.