From 17427887a2847acc74c61424e812aca0fea23226 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 5 Jun 2010 21:03:52 +0200 Subject: Fix QString::isRightToLeft() to conform with Unicode Bidi algorithm Rules P2 and P3 demand us to ignore the LRE/LRO/RLE/RLO characters for determining the paragraph direction. Task-Number: Part of QT-3292 --- src/corelib/tools/qstring.cpp | 20 +++++++++++--------- src/corelib/tools/qstring.h | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 1172a7b..1d5fab3 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -6916,20 +6916,23 @@ void QString::updateProperties() const p++; } - p = d->data; - d->righttoleft = false; + d->righttoleft = isRightToLeft(); + d->clean = true; +} + +bool QString::isRightToLeft() const +{ + ushort *p = d->data; + const ushort * const end = p + d->size; + bool righttoleft = false; while (p < end) { switch(QChar::direction(*p)) { case QChar::DirL: - case QChar::DirLRO: - case QChar::DirLRE: goto end; case QChar::DirR: case QChar::DirAL: - case QChar::DirRLO: - case QChar::DirRLE: - d->righttoleft = true; + righttoleft = true; goto end; default: break; @@ -6937,8 +6940,7 @@ void QString::updateProperties() const ++p; } end: - d->clean = true; - return; + return righttoleft; } /*! \fn bool QString::isSimpleText() const diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index a1c4e77..e52f59f 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -590,7 +590,7 @@ public: #endif bool isSimpleText() const { if (!d->clean) updateProperties(); return d->simpletext; } - bool isRightToLeft() const { if (!d->clean) updateProperties(); return d->righttoleft; } + bool isRightToLeft() const; QString(int size, Qt::Initialization); -- cgit v0.12