src/corelib/tools/qstring.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 19 fcece45ef507
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtCore module of the Qt Toolkit.
     7 ** This file is part of the QtCore module of the Qt Toolkit.
     8 **
     8 **
   883     \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdWString()
   883     \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdWString()
   884 */
   884 */
   885 QString QString::fromWCharArray(const wchar_t *string, int size)
   885 QString QString::fromWCharArray(const wchar_t *string, int size)
   886 {
   886 {
   887     if (sizeof(wchar_t) == sizeof(QChar)) {
   887     if (sizeof(wchar_t) == sizeof(QChar)) {
   888         return fromUtf16((ushort *)string, size);
   888         return fromUtf16((const ushort *)string, size);
   889     } else {
   889     } else {
   890         return fromUcs4((uint *)string, size);
   890         return fromUcs4((uint *)string, size);
   891     }
   891     }
   892 }
   892 }
   893 
   893 
  3855     of the Unicode string \a unicode (ISO-10646-UTF-16 encoded).
  3855     of the Unicode string \a unicode (ISO-10646-UTF-16 encoded).
  3856 
  3856 
  3857     If \a size is -1 (default), \a unicode must be terminated
  3857     If \a size is -1 (default), \a unicode must be terminated
  3858     with a 0.
  3858     with a 0.
  3859 
  3859 
       
  3860     This function checks for a Byte Order Mark (BOM). If it is missing,
       
  3861     host byte order is assumed.
       
  3862 
       
  3863     This function is comparatively slow.
       
  3864     Use QString(const ushort *, int) if possible.
       
  3865 
  3860     QString makes a deep copy of the Unicode data.
  3866     QString makes a deep copy of the Unicode data.
  3861 
  3867 
  3862     \sa utf16(), setUtf16()
  3868     \sa utf16(), setUtf16()
  3863 */
  3869 */
  3864 QString QString::fromUtf16(const ushort *unicode, int size)
  3870 QString QString::fromUtf16(const ushort *unicode, int size)
  3920     Resizes the string to \a size characters and copies \a unicode
  3926     Resizes the string to \a size characters and copies \a unicode
  3921     into the string.
  3927     into the string.
  3922 
  3928 
  3923     If \a unicode is 0, nothing is copied, but the string is still
  3929     If \a unicode is 0, nothing is copied, but the string is still
  3924     resized to \a size.
  3930     resized to \a size.
       
  3931 
       
  3932     Note that unlike fromUtf16(), this function does not consider BOMs and
       
  3933     possibly differing byte ordering.
  3925 
  3934 
  3926     \sa utf16(), setUnicode()
  3935     \sa utf16(), setUnicode()
  3927 */
  3936 */
  3928 
  3937 
  3929 /*!
  3938 /*!
  4666 /*!
  4675 /*!
  4667     \fn const ushort *QString::utf16() const
  4676     \fn const ushort *QString::utf16() const
  4668 
  4677 
  4669     Returns the QString as a '\\0\'-terminated array of unsigned
  4678     Returns the QString as a '\\0\'-terminated array of unsigned
  4670     shorts. The result remains valid until the string is modified.
  4679     shorts. The result remains valid until the string is modified.
       
  4680 
       
  4681     The returned string is in host byte order.
  4671 
  4682 
  4672     \sa unicode()
  4683     \sa unicode()
  4673 */
  4684 */
  4674 
  4685 
  4675 const ushort *QString::utf16() const
  4686 const ushort *QString::utf16() const
  7738 QString QStringRef::toString() const {
  7749 QString QStringRef::toString() const {
  7739     if (!m_string)
  7750     if (!m_string)
  7740         return QString();
  7751         return QString();
  7741     if (m_size && m_position == 0 && m_size == m_string->size())
  7752     if (m_size && m_position == 0 && m_size == m_string->size())
  7742         return *m_string;
  7753         return *m_string;
  7743     return QString::fromUtf16(reinterpret_cast<const ushort*>(m_string->unicode() + m_position), m_size);
  7754     return QString(m_string->unicode() + m_position, m_size);
  7744 }
  7755 }
  7745 
  7756 
  7746 
  7757 
  7747 /*! \relates QStringRef
  7758 /*! \relates QStringRef
  7748 
  7759