dom_stringimpl.h Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# 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  * Copyright (C) 2003 Dirk Mueller (mueller@kde.org)
    00006  *
    00007  * This library is free software; you can redistribute it and/or
    00008  * modify it under the terms of the GNU Library General Public
    00009  * License as published by the Free Software Foundation; either
    00010  * version 2 of the License, or (at your option) any later version.
    00011  *
    00012  * This library is distributed in the hope that it will be useful,
    00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  * Library General Public License for more details.
    00016  *
    00017  * You should have received a copy of the GNU Library General Public License
    00018  * along with this library; see the file COPYING.LIB.  If not, write to
    00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020  * Boston, MA 02111-1307, USA.
    00021  *
    00022  * $Id: dom_stringimpl.h,v 1.26.2.2 2003/05/18 12:34:41 mueller Exp $
    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             // crash protection
    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     // ignores trailing garbage, unlike QString
    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.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:48 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001