khtml Library API Documentation

dom_stringimpl.h

00001 /*
00002  * This file is part of the DOM implementation for KDE.
00003  *
00004  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  *
00021  * $Id: dom_stringimpl.h,v 1.26 2002/09/25 02:17:45 mueller Exp $
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         // crash protection
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     // ignores trailing garbage, unlike QString
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
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:36 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001