Qt 4.8
Classes | Macros | Functions
qstring.cpp File Reference
#include "qstringlist.h"
#include "qregexp.h"
#include "qunicodetables_p.h"
#include <qtextcodec.h>
#include <private/qutfcodec_p.h>
#include "qsimd_p.h"
#include <qdatastream.h>
#include <qlist.h>
#include "qlocale.h"
#include "qlocale_p.h"
#include "qstringmatcher.h"
#include "qvarlengtharray.h"
#include "qtools_p.h"
#include "qhash.h"
#include "qdebug.h"
#include "qendian.h"
#include "qmutex.h"
#include <private/qcore_mac_p.h>
#include <private/qfunctions_p.h>
#include <windows.h>
#include <winnls.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "qchar.cpp"
#include "qstringmatcher.cpp"
#include "qt_windows.h"

Go to the source code of this file.

Classes

struct  ArgEscapeData
 
struct  QStringCapture
 
class  qt_section_chunk
 

Macros

#define CSTR_EQUAL   2
 
#define CSTR_GREATER_THAN   3
 
#define CSTR_LESS_THAN   1
 
#define LLONG_MAX   qint64_C(9223372036854775807)
 
#define LLONG_MIN   (-LLONG_MAX - qint64_C(1))
 
#define QT_MAX_FLOAT   3.4028234663852886e+38
 Returns the string converted to a float value. More...
 
#define REHASH(a)
 
#define ULLONG_MAX   quint64_C(18446744073709551615)
 

Functions

static ArgEscapeData findArgEscapes (const QString &s)
 
static int findChar (const QChar *str, int len, QChar ch, int from, Qt::CaseSensitivity cs)
 Returns the index position of the first occurrence of the character ch in the string given by str and len, searching forward from index position from. More...
 
static int getEscape (const QChar *uc, int *pos, int len, int maxNumber=999)
 
static bool isStringRightToLeft (const ushort *p, const ushort *end)
 
static int lastIndexOfHelper (const ushort *haystack, int from, const ushort *needle, int sl, Qt::CaseSensitivity cs)
 
QDataStreamoperator<< (QDataStream &out, const QString &str)
 
QDataStreamoperator>> (QDataStream &in, QString &str)
 
int qFindString (const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
 
int qFindStringBoyerMoore (const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
 
bool qIsDigit (char ch)
 
bool qIsUpper (char ch)
 
static bool qMemEquals (const quint16 *a, const quint16 *b, int length)
 
static bool qt_ends_with (const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
 
static bool qt_ends_with (const QChar *haystack, int haystackLen, const QLatin1String &needle, Qt::CaseSensitivity cs)
 
static int qt_find_latin1_string (const QChar *hay, int size, const QLatin1String &needle, int from, Qt::CaseSensitivity cs)
 
static int qt_last_index_of (const QChar *haystack, int haystackLen, const QChar &needle, int from, Qt::CaseSensitivity cs)
 
static bool qt_starts_with (const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
 
static bool qt_starts_with (const QChar *haystack, int haystackLen, const QLatin1String &needle, Qt::CaseSensitivity cs)
 
static int qt_string_count (const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
 
static int qt_string_count (const QChar *haystack, int haystackLen, const QChar &needle, Qt::CaseSensitivity cs)
 
void qt_string_normalize (QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, int from)
 
char qToLower (char ch)
 
static QString replaceArgEscapes (const QString &s, const ArgEscapeData &d, int field_width, const QString &arg, const QString &larg, const QChar &fillChar=QLatin1Char(' '))
 
static QByteArray toLatin1_helper (const QChar *data, int length)
 
template<typename T >
int toUcs4_helper (const unsigned short *uc, int length, T *out)
 
static int ucstrcmp (const QChar *a, int alen, const QChar *b, int blen)
 
static int ucstricmp (const ushort *a, const ushort *ae, const ushort *b, const ushort *be)
 
static int ucstricmp (const ushort *a, const ushort *ae, const uchar *b)
 
static int ucstrncmp (const QChar *a, const QChar *b, int l)
 
static int ucstrnicmp (const ushort *a, const ushort *b, int l)
 

Macro Definition Documentation

◆ CSTR_EQUAL

#define CSTR_EQUAL   2

Definition at line 5180 of file qstring.cpp.

◆ CSTR_GREATER_THAN

#define CSTR_GREATER_THAN   3

Definition at line 5181 of file qstring.cpp.

Referenced by QString::localeAwareCompare_helper().

◆ CSTR_LESS_THAN

#define CSTR_LESS_THAN   1

Definition at line 5179 of file qstring.cpp.

Referenced by QString::localeAwareCompare_helper().

◆ LLONG_MAX

#define LLONG_MAX   qint64_C(9223372036854775807)

Definition at line 91 of file qstring.cpp.

◆ LLONG_MIN

#define LLONG_MIN   (-LLONG_MAX - qint64_C(1))

Definition at line 94 of file qstring.cpp.

◆ QT_MAX_FLOAT

#define QT_MAX_FLOAT   3.4028234663852886e+38

Returns the string converted to a float value.

If a conversion error occurs, *{ok} is set to false; otherwise {ok} is set to true. Returns 0.0 if the conversion fails.

Example:

QString str1 = "1234.56";
str1.toFloat(); // returns 1234.56
bool ok;
QString str2 = "R2D2";
str2.toFloat(&ok); // returns 0.0, sets ok to false
See also
number(), toDouble(), toInt()

Definition at line 6255 of file qstring.cpp.

Referenced by QString::toFloat().

◆ REHASH

#define REHASH (   a)
Value:
if (sl_minus_1 < (int)sizeof(int) * CHAR_BIT) \
hashHaystack -= (a) << sl_minus_1; \
hashHaystack <<= 1
long ASN1_INTEGER_get ASN1_INTEGER * a

Definition at line 357 of file qstring.cpp.

Referenced by lastIndexOfHelper(), and qFindString().

◆ ULLONG_MAX

#define ULLONG_MAX   quint64_C(18446744073709551615)

Definition at line 97 of file qstring.cpp.

Function Documentation

◆ findArgEscapes()

static ArgEscapeData findArgEscapes ( const QString s)
static

Definition at line 6780 of file qstring.cpp.

Referenced by QString::arg().

6781 {
6782  const QChar *uc_begin = s.unicode();
6783  const QChar *uc_end = uc_begin + s.length();
6784 
6785  ArgEscapeData d;
6786 
6787  d.min_escape = INT_MAX;
6788  d.occurrences = 0;
6789  d.escape_len = 0;
6790  d.locale_occurrences = 0;
6791 
6792  const QChar *c = uc_begin;
6793  while (c != uc_end) {
6794  while (c != uc_end && c->unicode() != '%')
6795  ++c;
6796 
6797  if (c == uc_end)
6798  break;
6799  const QChar *escape_start = c;
6800  if (++c == uc_end)
6801  break;
6802 
6803  bool locale_arg = false;
6804  if (c->unicode() == 'L') {
6805  locale_arg = true;
6806  if (++c == uc_end)
6807  break;
6808  }
6809 
6810  if (c->digitValue() == -1)
6811  continue;
6812 
6813  int escape = c->digitValue();
6814  ++c;
6815 
6816  if (c != uc_end && c->digitValue() != -1) {
6817  escape = (10 * escape) + c->digitValue();
6818  ++c;
6819  }
6820 
6821  if (escape > d.min_escape)
6822  continue;
6823 
6824  if (escape < d.min_escape) {
6825  d.min_escape = escape;
6826  d.occurrences = 0;
6827  d.escape_len = 0;
6828  d.locale_occurrences = 0;
6829  }
6830 
6831  ++d.occurrences;
6832  if (locale_arg)
6833  ++d.locale_occurrences;
6834  d.escape_len += c - escape_start;
6835  }
6836  return d;
6837 }
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
int digitValue() const
Returns the numeric value of the digit, or -1 if the character is not a digit.
Definition: qchar.cpp:817
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
int locale_occurrences
Definition: qstring.cpp:6775
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...
#define INT_MAX

◆ findChar()

static int findChar ( const QChar str,
int  len,
QChar  ch,
int  from,
Qt::CaseSensitivity  cs 
)
static

Returns the index position of the first occurrence of the character ch in the string given by str and len, searching forward from index position from.

Warning
This function is not part of the public interface.

Returns -1 if ch could not be found.

Definition at line 333 of file qstring.cpp.

Referenced by QString::indexOf(), QStringRef::indexOf(), and qFindString().

335 {
336  const ushort *s = (const ushort *)str;
337  ushort c = ch.unicode();
338  if (from < 0)
339  from = qMax(from + len, 0);
340  if (from < len) {
341  const ushort *n = s + from - 1;
342  const ushort *e = s + len;
343  if (cs == Qt::CaseSensitive) {
344  while (++n != e)
345  if (*n == c)
346  return n - s;
347  } else {
348  c = foldCase(c);
349  while (++n != e)
350  if (foldCase(*n) == c)
351  return n - s;
352  }
353  }
354  return -1;
355 }
unsigned char c[8]
Definition: qnumeric_p.h:62
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995

◆ getEscape()

static int getEscape ( const QChar uc,
int *  pos,
int  len,
int  maxNumber = 999 
)
static

Definition at line 7408 of file qstring.cpp.

Referenced by QString::multiArg().

7409 {
7410  int i = *pos;
7411  ++i;
7412  if (i < len && uc[i] == QLatin1Char('L'))
7413  ++i;
7414  if (i < len) {
7415  int escape = uc[i].unicode() - '0';
7416  if (uint(escape) >= 10U)
7417  return -1;
7418  ++i;
7419  while (i < len) {
7420  int digit = uc[i].unicode() - '0';
7421  if (uint(digit) >= 10U)
7422  break;
7423  escape = (escape * 10) + digit;
7424  ++i;
7425  }
7426  if (escape <= maxNumber) {
7427  *pos = i;
7428  return escape;
7429  }
7430  }
7431  return -1;
7432 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
unsigned int uint
Definition: qglobal.h:996
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isStringRightToLeft()

static bool isStringRightToLeft ( const ushort p,
const ushort end 
)
static

Definition at line 7487 of file qstring.cpp.

Referenced by QString::isRightToLeft(), and QString::updateProperties().

7488 {
7489  bool righttoleft = false;
7490  while (p < end) {
7491  switch(QChar::direction(*p))
7492  {
7493  case QChar::DirL:
7494  goto end;
7495  case QChar::DirR:
7496  case QChar::DirAL:
7497  righttoleft = true;
7498  goto end;
7499  default:
7500  break;
7501  }
7502  ++p;
7503  }
7504  end:
7505  return righttoleft;
7506 }
Direction direction() const
Returns the character&#39;s direction.
Definition: qchar.cpp:889
static const KeyPair *const end

◆ lastIndexOfHelper()

static int lastIndexOfHelper ( const ushort haystack,
int  from,
const ushort needle,
int  sl,
Qt::CaseSensitivity  cs 
)
static

Definition at line 2863 of file qstring.cpp.

Referenced by QString::lastIndexOf(), and QStringRef::lastIndexOf().

2864 {
2865  /*
2866  See indexOf() for explanations.
2867  */
2868 
2869  const ushort *end = haystack;
2870  haystack += from;
2871  const int sl_minus_1 = sl-1;
2872  const ushort *n = needle+sl_minus_1;
2873  const ushort *h = haystack+sl_minus_1;
2874  int hashNeedle = 0, hashHaystack = 0, idx;
2875 
2876  if (cs == Qt::CaseSensitive) {
2877  for (idx = 0; idx < sl; ++idx) {
2878  hashNeedle = ((hashNeedle<<1) + *(n-idx));
2879  hashHaystack = ((hashHaystack<<1) + *(h-idx));
2880  }
2881  hashHaystack -= *haystack;
2882 
2883  while (haystack >= end) {
2884  hashHaystack += *haystack;
2885  if (hashHaystack == hashNeedle
2886  && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
2887  return haystack - end;
2888  --haystack;
2889  REHASH(haystack[sl]);
2890  }
2891  } else {
2892  for (idx = 0; idx < sl; ++idx) {
2893  hashNeedle = ((hashNeedle<<1) + foldCase(n-idx, needle));
2894  hashHaystack = ((hashHaystack<<1) + foldCase(h-idx, end));
2895  }
2896  hashHaystack -= foldCase(haystack, end);
2897 
2898  while (haystack >= end) {
2899  hashHaystack += foldCase(haystack, end);
2900  if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
2901  return haystack - end;
2902  --haystack;
2903  REHASH(foldCase(haystack + sl, end));
2904  }
2905  }
2906  return -1;
2907 }
static int ucstrnicmp(const ushort *a, const ushort *b, int l)
Definition: qstring.cpp:221
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static int ucstrncmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:201
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
#define REHASH(a)
Definition: qstring.cpp:357
unsigned short ushort
Definition: qglobal.h:995
static const KeyPair *const end

◆ operator<<()

QDataStream& operator<< ( QDataStream out,
const QString str 
)
related

Definition at line 8034 of file qstring.cpp.

8035 {
8036  if (out.version() == 1) {
8037  out << str.toLatin1();
8038  } else {
8039  if (!str.isNull() || out.version() < 3) {
8040  if ((out.byteOrder() == QDataStream::BigEndian) == (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
8041  out.writeBytes(reinterpret_cast<const char *>(str.unicode()), sizeof(QChar) * str.length());
8042  } else {
8043  QVarLengthArray<ushort> buffer(str.length());
8044  const ushort *data = reinterpret_cast<const ushort *>(str.constData());
8045  for (int i = 0; i < str.length(); i++) {
8046  buffer[i] = qbswap(*data);
8047  ++data;
8048  }
8049  out.writeBytes(reinterpret_cast<const char *>(buffer.data()), sizeof(ushort) * buffer.size());
8050  }
8051  } else {
8052  // write null marker
8053  out << (quint32)0xffffffff;
8054  }
8055  }
8056  return out;
8057 }
void qbswap(const T src, uchar *dest)
Definition: qendian.h:74
ByteOrder byteOrder() const
Returns the current byte order setting – either BigEndian or LittleEndian.
Definition: qdatastream.h:209
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
QDataStream & writeBytes(const char *, uint len)
Writes the length specifier len and the buffer s to the stream and returns a reference to the stream...
static const char * data(const QByteArray &arr)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
unsigned short ushort
Definition: qglobal.h:995
unsigned int quint32
Definition: qglobal.h:938
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ operator>>()

QDataStream& operator>> ( QDataStream in,
QString str 
)
related

Definition at line 8071 of file qstring.cpp.

8072 {
8073 #ifdef QT_QSTRING_UCS_4
8074 #if defined(Q_CC_GNU)
8075 #warning "operator>> not working properly"
8076 #endif
8077 #endif
8078 
8079  if (in.version() == 1) {
8080  QByteArray l;
8081  in >> l;
8082  str = QString::fromLatin1(l);
8083  } else {
8084  quint32 bytes = 0;
8085  in >> bytes; // read size of string
8086  if (bytes == 0xffffffff) { // null string
8087  str.clear();
8088  } else if (bytes > 0) { // not empty
8089  if (bytes & 0x1) {
8090  str.clear();
8092  return in;
8093  }
8094 
8095  const quint32 Step = 1024 * 1024;
8096  quint32 len = bytes / 2;
8097  quint32 allocated = 0;
8098 
8099  while (allocated < len) {
8100  int blockSize = qMin(Step, len - allocated);
8101  str.resize(allocated + blockSize);
8102  if (in.readRawData(reinterpret_cast<char *>(str.data()) + allocated * 2,
8103  blockSize * 2) != blockSize * 2) {
8104  str.clear();
8106  return in;
8107  }
8108  allocated += blockSize;
8109  }
8110 
8111  if ((in.byteOrder() == QDataStream::BigEndian)
8112  != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
8113  ushort *data = reinterpret_cast<ushort *>(str.data());
8114  while (len--) {
8115  *data = qbswap(*data);
8116  ++data;
8117  }
8118  }
8119  } else {
8120  str = QLatin1String("");
8121  }
8122  }
8123  return in;
8124 }
const int blockSize
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void qbswap(const T src, uchar *dest)
Definition: qendian.h:74
ByteOrder byteOrder() const
Returns the current byte order setting – either BigEndian or LittleEndian.
Definition: qdatastream.h:209
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setStatus(Status status)
Sets the status of the data stream to the status given.
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
int readRawData(char *, int len)
Reads at most len bytes from the stream into s and returns the number of bytes read.
static const char * data(const QByteArray &arr)
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
unsigned short ushort
Definition: qglobal.h:995
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
unsigned int quint32
Definition: qglobal.h:938
QFactoryLoader * l

◆ qFindString()

int qFindString ( const QChar haystack,
int  haystackLen,
int  from,
const QChar needle,
int  needleLen,
Qt::CaseSensitivity  cs 
)

Definition at line 2753 of file qstring.cpp.

Referenced by QString::indexOf(), QStringRef::indexOf(), QRegExpMatchState::match(), qt_find_latin1_string(), and qt_string_count().

2756 {
2757  const int l = haystackLen;
2758  const int sl = needleLen;
2759  if (from < 0)
2760  from += l;
2761  if (uint(sl + from) > (uint)l)
2762  return -1;
2763  if (!sl)
2764  return from;
2765  if (!l)
2766  return -1;
2767 
2768  if (sl == 1)
2769  return findChar(haystack0, haystackLen, needle0[0], from, cs);
2770 
2771  /*
2772  We use the Boyer-Moore algorithm in cases where the overhead
2773  for the skip table should pay off, otherwise we use a simple
2774  hash function.
2775  */
2776  if (l > 500 && sl > 5)
2777  return qFindStringBoyerMoore(haystack0, haystackLen, from,
2778  needle0, needleLen, cs);
2779 
2780  /*
2781  We use some hashing for efficiency's sake. Instead of
2782  comparing strings, we compare the hash value of str with that
2783  of a part of this QString. Only if that matches, we call
2784  ucstrncmp() or ucstrnicmp().
2785  */
2786  const ushort *needle = (const ushort *)needle0;
2787  const ushort *haystack = (const ushort *)haystack0 + from;
2788  const ushort *end = (const ushort *)haystack0 + (l-sl);
2789  const int sl_minus_1 = sl-1;
2790  int hashNeedle = 0, hashHaystack = 0, idx;
2791 
2792  if (cs == Qt::CaseSensitive) {
2793  for (idx = 0; idx < sl; ++idx) {
2794  hashNeedle = ((hashNeedle<<1) + needle[idx]);
2795  hashHaystack = ((hashHaystack<<1) + haystack[idx]);
2796  }
2797  hashHaystack -= haystack[sl_minus_1];
2798 
2799  while (haystack <= end) {
2800  hashHaystack += haystack[sl_minus_1];
2801  if (hashHaystack == hashNeedle
2802  && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
2803  return haystack - (const ushort *)haystack0;
2804 
2805  REHASH(*haystack);
2806  ++haystack;
2807  }
2808  } else {
2809  const ushort *haystack_start = (const ushort *)haystack0;
2810  for (idx = 0; idx < sl; ++idx) {
2811  hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle);
2812  hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start);
2813  }
2814  hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start);
2815 
2816  while (haystack <= end) {
2817  hashHaystack += foldCase(haystack + sl_minus_1, haystack_start);
2818  if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
2819  return haystack - (const ushort *)haystack0;
2820 
2821  REHASH(foldCase(haystack, haystack_start));
2822  ++haystack;
2823  }
2824  }
2825  return -1;
2826 }
static int ucstrnicmp(const ushort *a, const ushort *b, int l)
Definition: qstring.cpp:221
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static int ucstrncmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:201
unsigned int uint
Definition: qglobal.h:996
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
static int findChar(const QChar *str, int len, QChar ch, int from, Qt::CaseSensitivity cs)
Returns the index position of the first occurrence of the character ch in the string given by str and...
Definition: qstring.cpp:333
int qFindStringBoyerMoore(const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
#define REHASH(a)
Definition: qstring.cpp:357
unsigned short ushort
Definition: qglobal.h:995
QFactoryLoader * l
static const KeyPair *const end

◆ qFindStringBoyerMoore()

int qFindStringBoyerMoore ( const QChar haystack,
int  haystackLen,
int  haystackOffset,
const QChar needle,
int  needleLen,
Qt::CaseSensitivity  cs 
)
Warning
This function is not part of the public interface.

Definition at line 322 of file qstringmatcher.cpp.

Referenced by qFindString().

325 {
326  uchar skiptable[256];
327  bm_init_skiptable((const ushort *)needle, needleLen, skiptable, cs);
328  if (haystackOffset < 0)
329  haystackOffset = 0;
330  return bm_find((const ushort *)haystack, haystackLen, haystackOffset,
331  (const ushort *)needle, needleLen, skiptable, cs);
332 }
static void bm_init_skiptable(const ushort *uc, int len, uchar *skiptable, Qt::CaseSensitivity cs)
unsigned char uchar
Definition: qglobal.h:994
static int bm_find(const ushort *uc, uint l, int index, const ushort *puc, uint pl, const uchar *skiptable, Qt::CaseSensitivity cs)
unsigned short ushort
Definition: qglobal.h:995

◆ qIsDigit()

bool qIsDigit ( char  ch)
inline

Definition at line 367 of file qstring.cpp.

Referenced by QString::vsprintf().

368 {
369  return ch >= '0' && ch <= '9';
370 }

◆ qIsUpper()

bool qIsUpper ( char  ch)
inline

Definition at line 362 of file qstring.cpp.

Referenced by QString::arg(), QString::setNum(), and QString::vsprintf().

363 {
364  return ch >= 'A' && ch <= 'Z';
365 }

◆ qMemEquals()

static bool qMemEquals ( const quint16 a,
const quint16 b,
int  length 
)
static

Definition at line 273 of file qstring.cpp.

Referenced by QString::operator==(), QStringRef::operator==(), qt_ends_with(), and qt_starts_with().

274 {
275  if (a == b || !length)
276  return true;
277 
278  register union {
279  const quint16 *w;
280  const quint32 *d;
281  quintptr value;
282  } sa, sb;
283  sa.w = a;
284  sb.w = b;
285 
286  // check alignment
287  if ((sa.value & 2) == (sb.value & 2)) {
288  // both addresses have the same alignment
289  if (sa.value & 2) {
290  // both addresses are not aligned to 4-bytes boundaries
291  // compare the first character
292  if (*sa.w != *sb.w)
293  return false;
294  --length;
295  ++sa.w;
296  ++sb.w;
297 
298  // now both addresses are 4-bytes aligned
299  }
300 
301  // both addresses are 4-bytes aligned
302  // do a fast 32-bit comparison
303  register const quint32 *e = sa.d + (length >> 1);
304  for ( ; sa.d != e; ++sa.d, ++sb.d) {
305  if (*sa.d != *sb.d)
306  return false;
307  }
308 
309  // do we have a tail?
310  return (length & 1) ? *sa.w == *sb.w : true;
311  } else {
312  // one of the addresses isn't 4-byte aligned but the other is
313  register const quint16 *e = sa.w + length;
314  for ( ; sa.w != e; ++sa.w, ++sb.w) {
315  if (*sa.w != *sb.w)
316  return false;
317  }
318  }
319  return true;
320 }
double d
Definition: qnumeric_p.h:62
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
long ASN1_INTEGER_get ASN1_INTEGER * a
unsigned short quint16
Definition: qglobal.h:936
unsigned int quint32
Definition: qglobal.h:938

◆ qt_ends_with() [1/2]

static bool qt_ends_with ( const QChar haystack,
int  haystackLen,
const QChar needle,
int  needleLen,
Qt::CaseSensitivity  cs 
)
inlinestatic

Definition at line 9722 of file qstring.cpp.

Referenced by QString::endsWith(), and QStringRef::endsWith().

9724 {
9725  if (!haystack)
9726  return !needle;
9727  if (haystackLen == 0)
9728  return needleLen == 0;
9729  const int pos = haystackLen - needleLen;
9730  if (pos < 0)
9731  return false;
9732 
9733  const ushort *h = reinterpret_cast<const ushort*>(haystack);
9734  const ushort *n = reinterpret_cast<const ushort*>(needle);
9735 
9736  if (cs == Qt::CaseSensitive) {
9737  return qMemEquals(h + pos, n, needleLen);
9738  } else {
9739  uint last = 0;
9740  uint olast = 0;
9741  for (int i = 0; i < needleLen; i++)
9742  if (foldCase(h[pos+i], last) != foldCase(n[i], olast))
9743  return false;
9744  }
9745  return true;
9746 }
static bool qMemEquals(const quint16 *a, const quint16 *b, int length)
Definition: qstring.cpp:273
unsigned int uint
Definition: qglobal.h:996
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995

◆ qt_ends_with() [2/2]

static bool qt_ends_with ( const QChar haystack,
int  haystackLen,
const QLatin1String needle,
Qt::CaseSensitivity  cs 
)
inlinestatic

Definition at line 9749 of file qstring.cpp.

9751 {
9752  if (!haystack)
9753  return !needle.latin1();
9754  if (haystackLen == 0)
9755  return !needle.latin1() || *needle.latin1() == 0;
9756  const int slen = qstrlen(needle.latin1());
9757  int pos = haystackLen - slen;
9758  if (pos < 0)
9759  return false;
9760  const uchar *latin = reinterpret_cast<const uchar*>(needle.latin1());
9761  const ushort *data = reinterpret_cast<const ushort*>(haystack);
9762  if (cs == Qt::CaseSensitive) {
9763  for (int i = 0; i < slen; i++)
9764  if (data[pos+i] != latin[i])
9765  return false;
9766  } else {
9767  for (int i = 0; i < slen; i++)
9768  if (foldCase(data[pos+i]) != foldCase((ushort)latin[i]))
9769  return false;
9770  }
9771  return true;
9772 }
unsigned char uchar
Definition: qglobal.h:994
const char * latin1() const
Returns the Latin-1 string stored in this object.
Definition: qstring.h:661
static const char * data(const QByteArray &arr)
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995
uint qstrlen(const char *str)
Definition: qbytearray.h:79

◆ qt_find_latin1_string()

static int qt_find_latin1_string ( const QChar hay,
int  size,
const QLatin1String needle,
int  from,
Qt::CaseSensitivity  cs 
)
inlinestatic

Definition at line 9659 of file qstring.cpp.

Referenced by QString::indexOf(), and QStringRef::indexOf().

9662 {
9663  const char *latin1 = needle.latin1();
9664  int len = qstrlen(latin1);
9665  QVarLengthArray<ushort> s(len);
9666  for (int i = 0; i < len; ++i)
9667  s[i] = latin1[i];
9668 
9669  return qFindString(haystack, size, from,
9670  reinterpret_cast<const QChar*>(s.constData()), len, cs);
9671 }
int qFindString(const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:2753
const char * latin1() const
Returns the Latin-1 string stored in this object.
Definition: qstring.h:661
uint qstrlen(const char *str)
Definition: qbytearray.h:79

◆ qt_last_index_of()

static int qt_last_index_of ( const QChar haystack,
int  haystackLen,
const QChar needle,
int  from,
Qt::CaseSensitivity  cs 
)
inlinestatic

Definition at line 9595 of file qstring.cpp.

Referenced by QString::lastIndexOf(), and QStringRef::lastIndexOf().

9597 {
9598  ushort c = needle.unicode();
9599  if (from < 0)
9600  from += haystackLen;
9601  if (from < 0 || from >= haystackLen)
9602  return -1;
9603  if (from >= 0) {
9604  const ushort *b = reinterpret_cast<const ushort*>(haystack);
9605  const ushort *n = b + from;
9606  if (cs == Qt::CaseSensitive) {
9607  for (; n >= b; --n)
9608  if (*n == c)
9609  return n - b;
9610  } else {
9611  c = foldCase(c);
9612  for (; n >= b; --n)
9613  if (foldCase(*n) == c)
9614  return n - b;
9615  }
9616  }
9617  return -1;
9618 
9619 
9620 }
unsigned char c[8]
Definition: qnumeric_p.h:62
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995

◆ qt_starts_with() [1/2]

static bool qt_starts_with ( const QChar haystack,
int  haystackLen,
const QChar needle,
int  needleLen,
Qt::CaseSensitivity  cs 
)
inlinestatic

Definition at line 9673 of file qstring.cpp.

Referenced by QString::startsWith(), and QStringRef::startsWith().

9675 {
9676  if (!haystack)
9677  return !needle;
9678  if (haystackLen == 0)
9679  return needleLen == 0;
9680  if (needleLen > haystackLen)
9681  return false;
9682 
9683  const ushort *h = reinterpret_cast<const ushort*>(haystack);
9684  const ushort *n = reinterpret_cast<const ushort*>(needle);
9685 
9686  if (cs == Qt::CaseSensitive) {
9687  return qMemEquals(h, n, needleLen);
9688  } else {
9689  uint last = 0;
9690  uint olast = 0;
9691  for (int i = 0; i < needleLen; ++i)
9692  if (foldCase(h[i], last) != foldCase(n[i], olast))
9693  return false;
9694  }
9695  return true;
9696 }
static bool qMemEquals(const quint16 *a, const quint16 *b, int length)
Definition: qstring.cpp:273
unsigned int uint
Definition: qglobal.h:996
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995

◆ qt_starts_with() [2/2]

static bool qt_starts_with ( const QChar haystack,
int  haystackLen,
const QLatin1String needle,
Qt::CaseSensitivity  cs 
)
inlinestatic

Definition at line 9698 of file qstring.cpp.

9700 {
9701  if (!haystack)
9702  return !needle.latin1();
9703  if (haystackLen == 0)
9704  return !needle.latin1() || *needle.latin1() == 0;
9705  const int slen = qstrlen(needle.latin1());
9706  if (slen > haystackLen)
9707  return false;
9708  const ushort *data = reinterpret_cast<const ushort*>(haystack);
9709  const uchar *latin = reinterpret_cast<const uchar*>(needle.latin1());
9710  if (cs == Qt::CaseSensitive) {
9711  for (int i = 0; i < slen; ++i)
9712  if (data[i] != latin[i])
9713  return false;
9714  } else {
9715  for (int i = 0; i < slen; ++i)
9716  if (foldCase(data[i]) != foldCase((ushort)latin[i]))
9717  return false;
9718  }
9719  return true;
9720 }
unsigned char uchar
Definition: qglobal.h:994
const char * latin1() const
Returns the Latin-1 string stored in this object.
Definition: qstring.h:661
static const char * data(const QByteArray &arr)
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995
uint qstrlen(const char *str)
Definition: qbytearray.h:79

◆ qt_string_count() [1/2]

static int qt_string_count ( const QChar haystack,
int  haystackLen,
const QChar needle,
int  needleLen,
Qt::CaseSensitivity  cs 
)
inlinestatic

Definition at line 9622 of file qstring.cpp.

Referenced by QString::count(), and QStringRef::count().

9625 {
9626  int num = 0;
9627  int i = -1;
9628  if (haystackLen > 500 && needleLen > 5) {
9629  QStringMatcher matcher(needle, needleLen, cs);
9630  while ((i = matcher.indexIn(haystack, haystackLen, i + 1)) != -1)
9631  ++num;
9632  } else {
9633  while ((i = qFindString(haystack, haystackLen, i + 1, needle, needleLen, cs)) != -1)
9634  ++num;
9635  }
9636  return num;
9637 }
int qFindString(const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:2753
The QStringMatcher class holds a sequence of characters that can be quickly matched in a Unicode stri...

◆ qt_string_count() [2/2]

static int qt_string_count ( const QChar haystack,
int  haystackLen,
const QChar needle,
Qt::CaseSensitivity  cs 
)
inlinestatic

Definition at line 9639 of file qstring.cpp.

9641 {
9642  ushort c = ch.unicode();
9643  int num = 0;
9644  const ushort *b = reinterpret_cast<const ushort*>(unicode);
9645  const ushort *i = b + size;
9646  if (cs == Qt::CaseSensitive) {
9647  while (i != b)
9648  if (*--i == c)
9649  ++num;
9650  } else {
9651  c = foldCase(c);
9652  while (i != b)
9653  if (foldCase(*(--i)) == c)
9654  ++num;
9655  }
9656  return num;
9657 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995

◆ qt_string_normalize()

void qt_string_normalize ( QString data,
QString::NormalizationForm  mode,
QChar::UnicodeVersion  version,
int  from 
)

Definition at line 6710 of file qstring.cpp.

Referenced by QString::normalized(), qt_nameprep(), and QString::repeated().

6711 {
6712  bool simple = true;
6713  const QChar *p = data->constData();
6714  int len = data->length();
6715  for (int i = from; i < len; ++i) {
6716  if (p[i].unicode() >= 0x80) {
6717  simple = false;
6718  break;
6719  }
6720  }
6721  if (simple)
6722  return;
6723 
6724  if (version == QChar::Unicode_Unassigned) {
6725  version = UNICODE_DATA_VERSION;
6726  } else if (version != UNICODE_DATA_VERSION) {
6727  const QString &s = *data;
6728  QChar *d = 0;
6729  for (int i = 0; i < NumNormalizationCorrections; ++i) {
6731  if (n.version > version) {
6732  int pos = from;
6734  ushort ucs4High = QChar::highSurrogate(n.ucs4);
6735  ushort ucs4Low = QChar::lowSurrogate(n.ucs4);
6738  while (pos < s.length() - 1) {
6739  if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
6740  if (!d)
6741  d = data->data();
6742  d[pos] = QChar(oldHigh);
6743  d[++pos] = QChar(oldLow);
6744  }
6745  ++pos;
6746  }
6747  } else {
6748  while (pos < s.length()) {
6749  if (s.at(pos).unicode() == n.ucs4) {
6750  if (!d)
6751  d = data->data();
6752  d[pos] = QChar(n.old_mapping);
6753  }
6754  ++pos;
6755  }
6756  }
6757  }
6758  }
6759  }
6760  decomposeHelper(data, mode < QString::NormalizationForm_KD, version, from);
6761 
6762  canonicalOrderHelper(data, version, from);
6763 
6765  return;
6766 
6767  composeHelper(data, version, from);
6768 }
double d
Definition: qnumeric_p.h:62
#define UNICODE_DATA_VERSION
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
static ushort highSurrogate(uint ucs4)
Returns the high surrogate value of a ucs4 code point.
Definition: qchar.h:303
static ushort lowSurrogate(uint ucs4)
Returns the low surrogate value of a ucs4 code point.
Definition: qchar.h:306
static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion version, int from)
Definition: qchar.cpp:1698
static const NormalizationCorrection uc_normalization_corrections[]
static bool requiresSurrogates(uint ucs4)
Returns true if the UCS-4-encoded character specified by ucs4 can be split into the high and low part...
Definition: qchar.h:294
static const char * data(const QByteArray &arr)
unsigned short ushort
Definition: qglobal.h:995
static void composeHelper(QString *str, QChar::UnicodeVersion version, int from)
Definition: qchar.cpp:1776
static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, int from)
Definition: qchar.cpp:1821
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ qToLower()

char qToLower ( char  ch)
inline

Definition at line 372 of file qstring.cpp.

Referenced by QString::arg(), QString::setNum(), and QString::vsprintf().

373 {
374  if (ch >= 'A' && ch <= 'Z')
375  return ch - 'A' + 'a';
376  else
377  return ch;
378 }

◆ replaceArgEscapes()

static QString replaceArgEscapes ( const QString s,
const ArgEscapeData d,
int  field_width,
const QString arg,
const QString larg,
const QChar fillChar = QLatin1Char(' ') 
)
static

Definition at line 6839 of file qstring.cpp.

Referenced by QString::arg().

6841 {
6842  const QChar *uc_begin = s.unicode();
6843  const QChar *uc_end = uc_begin + s.length();
6844 
6845  int abs_field_width = qAbs(field_width);
6846  int result_len = s.length()
6847  - d.escape_len
6849  *qMax(abs_field_width, arg.length())
6850  + d.locale_occurrences
6851  *qMax(abs_field_width, larg.length());
6852 
6853  QString result(result_len, Qt::Uninitialized);
6854  QChar *result_buff = (QChar*) result.unicode();
6855 
6856  QChar *rc = result_buff;
6857  const QChar *c = uc_begin;
6858  int repl_cnt = 0;
6859  while (c != uc_end) {
6860  /* We don't have to check if we run off the end of the string with c,
6861  because as long as d.occurrences > 0 we KNOW there are valid escape
6862  sequences. */
6863 
6864  const QChar *text_start = c;
6865 
6866  while (c->unicode() != '%')
6867  ++c;
6868 
6869  const QChar *escape_start = c++;
6870 
6871  bool locale_arg = false;
6872  if (c->unicode() == 'L') {
6873  locale_arg = true;
6874  ++c;
6875  }
6876 
6877  int escape = c->digitValue();
6878  if (escape != -1) {
6879  if (c + 1 != uc_end && (c + 1)->digitValue() != -1) {
6880  escape = (10 * escape) + (c + 1)->digitValue();
6881  ++c;
6882  }
6883  }
6884 
6885  if (escape != d.min_escape) {
6886  memcpy(rc, text_start, (c - text_start)*sizeof(QChar));
6887  rc += c - text_start;
6888  }
6889  else {
6890  ++c;
6891 
6892  memcpy(rc, text_start, (escape_start - text_start)*sizeof(QChar));
6893  rc += escape_start - text_start;
6894 
6895  uint pad_chars;
6896  if (locale_arg)
6897  pad_chars = qMax(abs_field_width, larg.length()) - larg.length();
6898  else
6899  pad_chars = qMax(abs_field_width, arg.length()) - arg.length();
6900 
6901  if (field_width > 0) { // left padded
6902  for (uint i = 0; i < pad_chars; ++i)
6903  (rc++)->unicode() = fillChar.unicode();
6904  }
6905 
6906  if (locale_arg) {
6907  memcpy(rc, larg.unicode(), larg.length()*sizeof(QChar));
6908  rc += larg.length();
6909  }
6910  else {
6911  memcpy(rc, arg.unicode(), arg.length()*sizeof(QChar));
6912  rc += arg.length();
6913  }
6914 
6915  if (field_width < 0) { // right padded
6916  for (uint i = 0; i < pad_chars; ++i)
6917  (rc++)->unicode() = fillChar.unicode();
6918  }
6919 
6920  if (++repl_cnt == d.occurrences) {
6921  memcpy(rc, c, (uc_end - c)*sizeof(QChar));
6922  rc += uc_end - c;
6923  Q_ASSERT(rc - result_buff == result_len);
6924  c = uc_end;
6925  }
6926  }
6927  }
6928  Q_ASSERT(rc == result_buff + result_len);
6929 
6930  return result;
6931 }
unsigned char c[8]
Definition: qnumeric_p.h:62
int digitValue() const
Returns the numeric value of the digit, or -1 if the character is not a digit.
Definition: qchar.cpp:817
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
unsigned int uint
Definition: qglobal.h:996
int locale_occurrences
Definition: qstring.cpp:6775
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...

◆ toLatin1_helper()

static QByteArray toLatin1_helper ( const QChar data,
int  length 
)
static

Definition at line 3924 of file qstring.cpp.

Referenced by QString::toAscii(), QString::toLatin1(), and QStringRef::toLatin1().

3925 {
3926  QByteArray ba;
3927  if (length) {
3928  ba.resize(length);
3929  const ushort *src = reinterpret_cast<const ushort *>(data);
3930  uchar *dst = (uchar*) ba.data();
3931 #if defined(QT_ALWAYS_HAVE_SSE2)
3932  if (length >= 16) {
3933  const int chunkCount = length >> 4; // divided by 16
3934 
3935  for (int i = 0; i < chunkCount; ++i) {
3936  __m128i chunk1 = _mm_loadu_si128((__m128i*)src); // load
3937  chunk1 = mergeQuestionMarks(chunk1);
3938  src += 8;
3939 
3940  __m128i chunk2 = _mm_loadu_si128((__m128i*)src); // load
3941  chunk2 = mergeQuestionMarks(chunk2);
3942  src += 8;
3943 
3944  // pack the two vector to 16 x 8bits elements
3945  const __m128i result = _mm_packus_epi16(chunk1, chunk2);
3946 
3947  _mm_storeu_si128((__m128i*)dst, result); // store
3948  dst += 16;
3949  }
3950  length = length % 16;
3951  }
3952 #elif defined(QT_ALWAYS_HAVE_NEON)
3953  // Refer to the documentation of the SSE2 implementation
3954  // this use eactly the same method as for SSE except:
3955  // 1) neon has unsigned comparison
3956  // 2) packing is done to 64 bits (8 x 8bits component).
3957  if (length >= 16) {
3958  const int chunkCount = length >> 3; // divided by 8
3959  const uint16x8_t questionMark = vdupq_n_u16('?'); // set
3960  const uint16x8_t thresholdMask = vdupq_n_u16(0xff); // set
3961  for (int i = 0; i < chunkCount; ++i) {
3962  uint16x8_t chunk = vld1q_u16((uint16_t *)src); // load
3963  src += 8;
3964 
3965  const uint16x8_t offLimitMask = vcgtq_u16(chunk, thresholdMask); // chunk > thresholdMask
3966  const uint16x8_t offLimitQuestionMark = vandq_u16(offLimitMask, questionMark); // offLimitMask & questionMark
3967  const uint16x8_t correctBytes = vbicq_u16(chunk, offLimitMask); // !offLimitMask & chunk
3968  chunk = vorrq_u16(correctBytes, offLimitQuestionMark); // correctBytes | offLimitQuestionMark
3969  const uint8x8_t result = vmovn_u16(chunk); // narrowing move->packing
3970  vst1_u8(dst, result); // store
3971  dst += 8;
3972  }
3973  length = length % 8;
3974  }
3975 #endif
3976  while (length--) {
3977  *dst++ = (*src>0xff) ? '?' : (uchar) *src;
3978  ++src;
3979  }
3980  }
3981  return ba;
3982 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
unsigned char uchar
Definition: qglobal.h:994
static const char * data(const QByteArray &arr)
unsigned short ushort
Definition: qglobal.h:995
void resize(int size)
Sets the size of the byte array to size bytes.

◆ toUcs4_helper()

template<typename T >
int toUcs4_helper ( const unsigned short *  uc,
int  length,
T *  out 
)

Definition at line 1047 of file qstring.cpp.

1048 {
1049  int i = 0;
1050  for (; i < length; ++i) {
1051  uint u = uc[i];
1052  if (QChar::isHighSurrogate(u) && i < length-1) {
1053  ushort low = uc[i+1];
1054  if (QChar::isLowSurrogate(low)) {
1055  ++i;
1056  u = QChar::surrogateToUcs4(u, low);
1057  }
1058  }
1059  *out = T(u);
1060  ++out;
1061  }
1062  return i;
1063 }
bool isLowSurrogate() const
Returns true if the QChar is the low part of a utf16 surrogate (ie.
Definition: qchar.h:279
quint16 u
bool isHighSurrogate() const
Returns true if the QChar is the high part of a utf16 surrogate (ie.
Definition: qchar.h:276
unsigned int uint
Definition: qglobal.h:996
unsigned short ushort
Definition: qglobal.h:995
static uint surrogateToUcs4(ushort high, ushort low)
Converts a UTF16 surrogate pair with the given high and low values to its UCS-4 code point...
Definition: qchar.h:297

◆ ucstrcmp()

static int ucstrcmp ( const QChar a,
int  alen,
const QChar b,
int  blen 
)
static

Definition at line 211 of file qstring.cpp.

Referenced by QString::compare(), QString::compare_helper(), QString::localeAwareCompare_helper(), QString::operator<(), and QStringRef::operator<().

212 {
213  if (a == b && alen == blen)
214  return 0;
215  int l = qMin(alen, blen);
216  int cmp = ucstrncmp(a, b, l);
217  return cmp ? cmp : (alen-blen);
218 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static int ucstrncmp(const QChar *a, const QChar *b, int l)
Definition: qstring.cpp:201
static int cmp(const ushort *s1, const ushort *s2, size_t len)
QFactoryLoader * l

◆ ucstricmp() [1/2]

static int ucstricmp ( const ushort a,
const ushort ae,
const ushort b,
const ushort be 
)
static

Definition at line 141 of file qstring.cpp.

Referenced by QString::compare(), QString::compare_helper(), and ucstrnicmp().

142 {
143  if (a == b)
144  return (ae - be);
145  if (a == 0)
146  return 1;
147  if (b == 0)
148  return -1;
149 
150  const ushort *e = ae;
151  if (be - b < ae - a)
152  e = a + (be - b);
153 
154  uint alast = 0;
155  uint blast = 0;
156  while (a < e) {
157 // qDebug() << hex << alast << blast;
158 // qDebug() << hex << "*a=" << *a << "alast=" << alast << "folded=" << foldCase (*a, alast);
159 // qDebug() << hex << "*b=" << *b << "blast=" << blast << "folded=" << foldCase (*b, blast);
160  int diff = foldCase(*a, alast) - foldCase(*b, blast);
161  if ((diff))
162  return diff;
163  ++a;
164  ++b;
165  }
166  if (a == ae) {
167  if (b == be)
168  return 0;
169  return -1;
170  }
171  return 1;
172 }
long ASN1_INTEGER_get ASN1_INTEGER * a
unsigned int uint
Definition: qglobal.h:996
static Bigint * diff(Bigint *a, Bigint *b)
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995

◆ ucstricmp() [2/2]

static int ucstricmp ( const ushort a,
const ushort ae,
const uchar b 
)
static

Definition at line 175 of file qstring.cpp.

176 {
177  if (a == 0) {
178  if (b == 0)
179  return 0;
180  return 1;
181  }
182  if (b == 0)
183  return -1;
184 
185  while (a < ae && *b) {
186  int diff = foldCase(*a) - foldCase(*b);
187  if ((diff))
188  return diff;
189  ++a;
190  ++b;
191  }
192  if (a == ae) {
193  if (!*b)
194  return 0;
195  return -1;
196  }
197  return 1;
198 }
long ASN1_INTEGER_get ASN1_INTEGER * a
static Bigint * diff(Bigint *a, Bigint *b)
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380

◆ ucstrncmp()

static int ucstrncmp ( const QChar a,
const QChar b,
int  l 
)
static

Definition at line 201 of file qstring.cpp.

Referenced by lastIndexOfHelper(), qFindString(), and ucstrcmp().

202 {
203  while (l-- && *a == *b)
204  a++,b++;
205  if (l==-1)
206  return 0;
207  return a->unicode() - b->unicode();
208 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
QFactoryLoader * l

◆ ucstrnicmp()

static int ucstrnicmp ( const ushort a,
const ushort b,
int  l 
)
static

Definition at line 221 of file qstring.cpp.

Referenced by lastIndexOfHelper(), and qFindString().

222 {
223  return ucstricmp(a, a + l, b, b + l);
224 }
long ASN1_INTEGER_get ASN1_INTEGER * a
static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const ushort *be)
Definition: qstring.cpp:141
QFactoryLoader * l