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

📄 qstring.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program 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 General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/// Don't define it while compiling this module, or USERS of Qt will// not be able to link.#ifdef QT_NO_CAST_ASCII#undef QT_NO_CAST_ASCII#endif#include "qstring.h"#include "qregexp.h"#include "qdatastream.h"#ifndef QT_NO_TEXTCODEC#include "qtextcodec.h"#endif#include "qunicodetables_p.h"#include <limits.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <locale.h>#if defined(Q_WS_WIN)#include "qt_windows.h"#endif#if !defined( QT_NO_COMPONENT ) && !defined( QT_LITE_COMPONENT )#include "qcleanuphandler.h"#endif#ifndef LLONG_MAX#define LLONG_MAX Q_INT64_C(9223372036854775807)#endif#ifndef LLONG_MIN#define LLONG_MIN (-LLONG_MAX - Q_INT64_C(1))#endif#ifndef ULLONG_MAX#define ULLONG_MAX Q_UINT64_C(18446744073709551615)#endifstatic int ucstrcmp( const QString &as, const QString &bs ){    const QChar *a = as.unicode();    const QChar *b = bs.unicode();    if ( a == b )	return 0;    if ( a == 0 )	return 1;    if ( b == 0 )	return -1;    int l=QMIN(as.length(),bs.length());    while ( l-- && *a == *b )	a++,b++;    if ( l==-1 )	return ( as.length()-bs.length() );    return a->unicode() - b->unicode();}static int ucstrncmp( const QChar *a, const QChar *b, int l ){    while ( l-- && *a == *b )	a++,b++;    if ( l==-1 )	return 0;    return a->unicode() - b->unicode();}static int ucstrnicmp( const QChar *a, const QChar *b, int l ){    while ( l-- && ::lower( *a ) == ::lower( *b ) )	a++,b++;    if ( l==-1 )	return 0;    return ::lower( *a ).unicode() - ::lower( *b ).unicode();}static uint computeNewMax( uint len ){    uint newMax = 4;    while ( newMax < len )	newMax *= 2;    // try to save some memory    if ( newMax >= 1024 * 1024 && len <= newMax - (newMax >> 2) )	newMax -= newMax >> 2;    return newMax;}/*!    \class QCharRef qstring.h    \reentrant    \brief The QCharRef class is a helper class for QString.    \ingroup text    When you get an object of type QCharRef, if you can assign to it,    the assignment will apply to the character in the string from    which you got the reference. That is its whole purpose in life.    The QCharRef becomes invalid once modifications are made to the    string: if you want to keep the character, copy it into a QChar.    Most of the QChar member functions also exist in QCharRef.    However, they are not explicitly documented here.    \sa QString::operator[]() QString::at() QChar*//*!    \class QChar qstring.h    \reentrant    \brief The QChar class provides a lightweight Unicode character.    \ingroup text    Unicode characters are (so far) 16-bit entities without any markup    or structure. This class represents such an entity. It is    lightweight, so it can be used everywhere. Most compilers treat it    like a "short int".  (In a few years it may be necessary to make    QChar 32-bit when more than 65536 Unicode code points have been    defined and come into use.)    QChar provides a full complement of testing/classification    functions, converting to and from other formats, converting from    composed to decomposed Unicode, and trying to compare and    case-convert if you ask it to.    The classification functions include functions like those in    ctype.h, but operating on the full range of Unicode characters.    They all return TRUE if the character is a certain type of    character; otherwise they return FALSE. These classification    functions are isNull() (returns TRUE if the character is U+0000),    isPrint() (TRUE if the character is any sort of printable    character, including whitespace), isPunct() (any sort of    punctation), isMark() (Unicode Mark), isLetter (a letter),    isNumber() (any sort of numeric character), isLetterOrNumber(),    and isDigit() (decimal digits). All of these are wrappers around    category() which return the Unicode-defined category of each    character.    QChar further provides direction(), which indicates the "natural"    writing direction of this character. The joining() function    indicates how the character joins with its neighbors (needed    mostly for Arabic) and finally mirrored(), which indicates whether    the character needs to be mirrored when it is printed in its    "unnatural" writing direction.    Composed Unicode characters (like &aring;) can be converted to    decomposed Unicode ("a" followed by "ring above") by using    decomposition().    In Unicode, comparison is not necessarily possible and case    conversion is very difficult at best. Unicode, covering the    "entire" world, also includes most of the world's case and sorting    problems. Qt tries, but not very hard: operator==() and friends    will do comparison based purely on the numeric Unicode value (code    point) of the characters, and upper() and lower() will do case    changes when the character has a well-defined upper/lower-case    equivalent. There is no provision for locale-dependent case    folding rules or comparison; these functions are meant to be fast    so they can be used unambiguously in data structures. (See    QString::localeAwareCompare() though.)    The conversion functions include unicode() (to a scalar), latin1()    (to scalar, but converts all non-Latin-1 characters to 0), row()    (gives the Unicode row), cell() (gives the Unicode cell),    digitValue() (gives the integer value of any of the numerous digit    characters), and a host of constructors.    More information can be found in the document \link unicode.html    About Unicode. \endlink    \sa QString QCharRef*//*!    \enum QChar::Category    This enum maps the Unicode character categories.    The following characters are normative in Unicode:    \value Mark_NonSpacing  Unicode class name Mn    \value Mark_SpacingCombining  Unicode class name Mc    \value Mark_Enclosing  Unicode class name Me    \value Number_DecimalDigit  Unicode class name Nd    \value Number_Letter  Unicode class name Nl    \value Number_Other  Unicode class name No    \value Separator_Space  Unicode class name Zs    \value Separator_Line  Unicode class name Zl    \value Separator_Paragraph  Unicode class name Zp    \value Other_Control  Unicode class name Cc    \value Other_Format  Unicode class name Cf    \value Other_Surrogate  Unicode class name Cs    \value Other_PrivateUse  Unicode class name Co    \value Other_NotAssigned  Unicode class name Cn    The following categories are informative in Unicode:    \value Letter_Uppercase  Unicode class name Lu    \value Letter_Lowercase  Unicode class name Ll    \value Letter_Titlecase  Unicode class name Lt    \value Letter_Modifier  Unicode class name Lm    \value Letter_Other Unicode class name Lo    \value Punctuation_Connector  Unicode class name Pc    \value Punctuation_Dash  Unicode class name Pd    \value Punctuation_Open  Unicode class name Ps    \value Punctuation_Close  Unicode class name Pe    \value Punctuation_InitialQuote  Unicode class name Pi    \value Punctuation_FinalQuote  Unicode class name Pf    \value Punctuation_Other  Unicode class name Po    \value Symbol_Math  Unicode class name Sm    \value Symbol_Currency  Unicode class name Sc    \value Symbol_Modifier  Unicode class name Sk    \value Symbol_Other  Unicode class name So    There are two categories that are specific to Qt:    \value NoCategory  used when Qt is dazed and confused and cannot    make sense of anything.    \value Punctuation_Dask  old typo alias for Punctuation_Dash*//*!    \enum QChar::Direction    This enum type defines the Unicode direction attributes. See \link    http://www.unicode.org/ the Unicode Standard\endlink for a    description of the values.    In order to conform to C/C++ naming conventions "Dir" is prepended    to the codes used in the Unicode Standard.*//*!    \enum QChar::Decomposition    This enum type defines the Unicode decomposition attributes. See    \link http://www.unicode.org/ the Unicode Standard\endlink for a    description of the values.*//*!    \enum QChar::Joining    This enum type defines the Unicode joining attributes. See \link    http://www.unicode.org/ the Unicode Standard\endlink for a    description of the values.*//*!    \enum QChar::CombiningClass    This enum type defines names for some of the Unicode combining    classes. See \link http://www.unicode.org/ the Unicode    Standard\endlink for a description of the values.*//*!    \fn void QChar::setCell( uchar cell )    \internal*//*!    \fn void QChar::setRow( uchar row )    \internal*//*!    \fn QChar::QChar()    Constructs a null QChar (one that isNull()).*//*!    \fn QChar::QChar( char c )    Constructs a QChar corresponding to ASCII/Latin-1 character \a c.*//*!    \fn QChar::QChar( uchar c )    Constructs a QChar corresponding to ASCII/Latin-1 character \a c.*//*!    \fn QChar::QChar( uchar c, uchar r )    Constructs a QChar for Unicode cell \a c in row \a r.*//*!    \fn QChar::QChar( const QChar& c )    Constructs a copy of \a c. This is a deep copy, if such a    lightweight object can be said to have deep copies.*//*!    \fn QChar::QChar( ushort rc )    Constructs a QChar for the character with Unicode code point \a rc.*//*!    \fn QChar::QChar( short rc )    Constructs a QChar for the character with Unicode code point \a rc.*//*!    \fn QChar::QChar( uint rc )    Constructs a QChar for the character with Unicode code point \a rc.*//*!    \fn QChar::QChar( int rc )    Constructs a QChar for the character with Unicode code point \a rc.*//*!    \fn bool  QChar::networkOrdered ()    \obsolete    Returns TRUE if this character is in network byte order (MSB    first); otherwise returns FALSE. This is platform dependent.*//*!    \fn bool QChar::isNull() const    Returns TRUE if the character is the Unicode character 0x0000    (ASCII NUL); otherwise returns FALSE.*//*!    \fn uchar QChar::cell () const    Returns the cell (least significant byte) of the Unicode    character.*//*!    \fn uchar QChar::row () const    Returns the row (most significant byte) of the Unicode character.*//*!    Returns TRUE if the character is a printable character; otherwise    returns FALSE. This is any character not of category Cc or Cn.    Note that this gives no indication of whether the character is    available in a particular \link QFont font\endlink.*/bool QChar::isPrint() const{    Category c = ::category( *this );    return !(c == Other_Control || c == Other_NotAssigned);}/*!    Returns TRUE if the character is a separator character    (Separator_* categories); otherwise returns FALSE.*/bool QChar::isSpace() const{    return ::isSpace( *this );}/*!    Returns TRUE if the character is a mark (Mark_* categories);    otherwise returns FALSE.*/bool QChar::isMark() const{    Category c = ::category( *this );    return c >= Mark_NonSpacing && c <= Mark_Enclosing;}/*!    Returns TRUE if the character is a punctuation mark (Punctuation_*    categories); otherwise returns FALSE.*/bool QChar::isPunct() const{    Category c = ::category( *this );    return (c >= Punctuation_Connector && c <= Punctuation_Other);}/*!    Returns TRUE if the character is a letter (Letter_* categories);    otherwise returns FALSE.*/bool QChar::isLetter() const{    Category c = ::category( *this );    return (c >= Letter_Uppercase && c <= Letter_Other);}/*!    Returns TRUE if the character is a number (of any sort - Number_*    categories); otherwise returns FALSE.    \sa isDigit()*/bool QChar::isNumber() const{    Category c = ::category( *this );    return c >= Number_DecimalDigit && c <= Number_Other;}/*!    Returns TRUE if the character is a letter or number (Letter_* or    Number_* categories); otherwise returns FALSE.*/bool QChar::isLetterOrNumber() const{    Category c = ::category( *this );    return (c >= Letter_Uppercase && c <= Letter_Other)	|| (c >= Number_DecimalDigit && c <= Number_Other);}/*!    Returns TRUE if the character is a decimal digit    (Number_DecimalDigit); otherwise returns FALSE.*/bool QChar::isDigit() const{    return (::category( *this ) == Number_DecimalDigit);}/*!    Returns TRUE if the character is a symbol (Symbol_* categories);    otherwise returns FALSE.*/bool QChar::isSymbol() const{    Category c = ::category( *this );    return c >= Symbol_Math && c <= Symbol_Other;}/*!    Returns the numeric value of the digit, or -1 if the character is    not a digit.*/

⌨️ 快捷键说明

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