⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ustring.h

📁 khtml在gtk上的移植版本
💻 H
📖 第 1 页 / 共 2 页
字号:
// -*- c-basic-offset: 2 -*-/* *  This file is part of the KDE libraries *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org) *  Copyright (C) 2003 Apple Computer, Inc. * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Library General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Library General Public License for more details. * *  You should have received a copy of the GNU Library General Public License *  along with this library; see the file COPYING.LIB.  If not, write to *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330, *  Boston, MA 02111-1307, USA. * */#ifndef _KJS_USTRING_H_#define _KJS_USTRING_H_#if APPLE_CHANGES#include <sys/types.h>#ifndef KWQ_UNSIGNED_TYPES_DEFINED#define KWQ_UNSIGNED_TYPES_DEFINEDtypedef unsigned char uchar;typedef unsigned long ulong;#endif#endif#include <stdint.h>/** * @internal */namespace DOM {  class DOMString;};class KJScript;class QString;class QConstString;namespace KJS {  class UCharReference;  class UString;  /**   * @short Unicode character.   *   * UChar represents a 16 bit Unicode character. It's internal data   * representation is compatible to XChar2b and QChar. It's therefore   * possible to exchange data with X and Qt with shallow copies.   */  struct UChar {    /**     * Construct a character with uninitialized value.         */    UChar();    /**     * Construct a character with the value denoted by the arguments.     * @param h higher byte     * @param l lower byte     */    UChar(unsigned char h , unsigned char l);    /**     * Construct a character with the given value.     * @param u 16 bit Unicode value     */    UChar(char u);    UChar(unsigned char u);    UChar(unsigned short u);    UChar(const UCharReference &c);    /**     * @return The higher byte of the character.     */    unsigned char high() const { return uc >> 8; }    /**     * @return The lower byte of the character.     */    unsigned char low() const { return uc; }    /**     * @return the 16 bit Unicode value of the character     */    unsigned short unicode() const { return uc; }  public:    /**     * @return The character converted to lower case.     */    UChar toLower() const;    /**     * @return The character converted to upper case.     */    UChar toUpper() const;    unsigned short uc;#if !KWIQ  };#else  } Q_PACKED;#endif  inline UChar::UChar() { }  inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { }  inline UChar::UChar(char u) : uc((unsigned char)u) { }  inline UChar::UChar(unsigned char u) : uc(u) { }  inline UChar::UChar(unsigned short u) : uc(u) { }  /**   * @short Dynamic reference to a string character.   *   * UCharReference is the dynamic counterpart of @ref UChar. It's used when   * characters retrieved via index from a @ref UString are used in an   * assignment expression (and therefore can't be treated as being const):   * <pre>   * UString s("hello world");   * s[0] = 'H';   * </pre>   *   * If that sounds confusing your best bet is to simply forget about the   * existance of this class and treat is as being identical to @ref UChar.   */  class UCharReference {    friend class UString;    UCharReference(UString *s, unsigned int off) : str(s), offset(off) { }  public:    /**     * Set the referenced character to c.     */    UCharReference& operator=(UChar c);    /**     * Same operator as above except the argument that it takes.     */    UCharReference& operator=(char c) { return operator=(UChar(c)); }    /**     * @return Unicode value.     */    unsigned short unicode() const { return ref().uc; }    /**     * @return Lower byte.     */    unsigned char low() const { return ref().uc; }    /**     * @return Higher byte.     */    unsigned char high() const { return ref().uc >> 8; }    /**     * @return Character converted to lower case.     */    UChar toLower() const { return ref().toLower(); }    /**     * @return Character converted to upper case.     */    UChar toUpper() const  { return ref().toUpper(); }  private:    // not implemented, can only be constructed from UString    UCharReference();    UChar& ref() const;    UString *str;    int offset;  };  inline UChar::UChar(const UCharReference &c) : uc(c.unicode()) { }  /**   * @short 8 bit char based string class   */  class CString {  public:    CString() : data(0), length(0) { }    CString(const char *c);    CString(const char *c, int len);    CString(const CString &);    ~CString();    CString &append(const CString &);    CString &operator=(const char *c);    CString &operator=(const CString &);    CString &operator+=(const CString &c) { return append(c); }    int size() const { return length; }    const char *c_str() const { return data; }  private:    char *data;    int length;  };  /**   * @short Unicode string class   */  class UString {    friend bool operator==(const UString&, const UString&);    friend class UCharReference;    friend class Identifier;    friend class PropertyMap;    friend class PropertyMapHashTableEntry;    /**     * @internal     */    struct Rep {      friend class UString;      friend bool operator==(const UString&, const UString&);            static Rep *create(UChar *d, int l);      static Rep *create(Rep *base, int offset, int length);      void destroy();            UChar *data() const { return baseString ? (baseString->buf + baseString->preCapacity + offset) : (buf + preCapacity + offset); }      int size() const { return len; }            unsigned hash() const { if (_hash == 0) _hash = computeHash(data(), len); return _hash; }      static unsigned computeHash(const UChar *, int length);      static unsigned computeHash(const char *);      void ref() { ++rc; }      void deref() { if (--rc == 0) destroy(); }      // unshared data      int offset;      int len;      int rc;      mutable unsigned _hash;      bool isIdentifier;      UString::Rep *baseString;      // potentially shared data      UChar *buf;      int usedCapacity;      int capacity;      int usedPreCapacity;      int preCapacity;            static Rep null;      static Rep empty;    };  public:    /**     * Constructs a null string.     */    UString();    /**     * Constructs a string from the single character c.     */    explicit UString(char c);    /**     * Constructs a string from a classical zero determined char string.     */    UString(const char *c);    /**     * Constructs a string from an array of Unicode characters of the specified     * length.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -