summaryrefslogtreecommitdiffstats
path: root/qtools
diff options
context:
space:
mode:
authorDimitri van Heesch <dimitri@stack.nl>2017-12-28 09:13:43 (GMT)
committerDimitri van Heesch <dimitri@stack.nl>2017-12-28 09:13:43 (GMT)
commit989de07559a112c398da0bf3e7a1112ed5c8dbd7 (patch)
tree07e79b6c76dec9c20f6c0df3c6662d73dcade4ef /qtools
parent9538bfd15c99aceb619f426b30c87004c4820370 (diff)
parent3977359bd3fb5527a237c2c0cdb61407f2d85464 (diff)
downloadDoxygen-989de07559a112c398da0bf3e7a1112ed5c8dbd7.zip
Doxygen-989de07559a112c398da0bf3e7a1112ed5c8dbd7.tar.gz
Doxygen-989de07559a112c398da0bf3e7a1112ed5c8dbd7.tar.bz2
Merge branch 'master' of https://github.com/ahoogol/doxygen into ahoogol-master
Diffstat (limited to 'qtools')
-rw-r--r--qtools/qstring.cpp95
-rw-r--r--qtools/qstring.h37
2 files changed, 108 insertions, 24 deletions
diff --git a/qtools/qstring.cpp b/qtools/qstring.cpp
index e04a852..30bb05b 100644
--- a/qtools/qstring.cpp
+++ b/qtools/qstring.cpp
@@ -11614,32 +11614,83 @@ static inline bool is_neutral(unsigned short dir) {
#endif
/*!
- This function returns the basic directionality of the string (QChar::DirR for
- right to left and QChar::DirL for left to right). Useful to find the right
- alignment.
- */
-QChar::Direction QString::basicDirection()
+This function returns the directionality of the string.
+
+\returns a value of DirLTR, DirRTL, DirMixed or DirNeutral that indicates
+if the entire text represented by this text is unidirectional,
+and which direction, or if it is mixed-directional or all characters are neutral.
+*/
+QString::Direction QString::direction() const
{
#ifndef QT_NO_UNICODETABLES
- // find base direction
- unsigned int pos = 0;
- while ((pos < length()) &&
- (at(pos) != RLE) &&
- (at(pos) != LRE) &&
- (at(pos) != RLO) &&
- (at(pos) != LRO) &&
- (at(pos).direction() > 1) &&
- (at(pos).direction() != QChar::DirAL)) // not R and not L
- pos++;
-
- if ((at(pos).direction() == QChar::DirR) ||
- (at(pos).direction() == QChar::DirAL) ||
- (at(pos) == RLE) ||
- (at(pos) == RLO))
- return QChar::DirR;
+ // find direction
+ unsigned char resultDir = DirNeutral;
+ for (unsigned int pos = 0; pos < length(); pos++)
+ {
+ if ((at(pos) != RLE) &&
+ (at(pos) != LRE) &&
+ (at(pos) != RLO) &&
+ (at(pos) != LRO) &&
+ (at(pos).direction() > 1) &&
+ (at(pos).direction() != QChar::DirAL)) // not R and not L
+ continue;
+
+ if ((at(pos).direction() == QChar::DirR) ||
+ (at(pos).direction() == QChar::DirAL) ||
+ (at(pos) == RLE) ||
+ (at(pos) == RLO))
+ resultDir |= DirRTL;
+ else
+ resultDir |= DirLTR;
+ if (resultDir == DirMixed)
+ return DirMixed;
+ }
+ return static_cast<Direction>(resultDir);
+#else
+ return DirLTR;
#endif
+}
+
+/*!
+This function returns the basic directionality of the string. Useful to find the right
+alignment.
- return QChar::DirL;
+The base direction is derived from the first character in the string
+with bidirectional character type L, R, or AL.
+If the first such character has type L, DirLTR is returned.
+If the first such character has type R or AL, DirRTL is returned.
+If the string does not contain any character of these types, then DirNeutral is returned.
+This is a lightweight function for use when only the base direction is needed and
+no further bidi processing of the text is needed.
+
+\returns DirRTL, DirLTR or DirNeutral
+*/
+QString::Direction QString::basicDirection() const
+{
+#ifndef QT_NO_UNICODETABLES
+ // find base direction
+ unsigned int pos = 0;
+ while ((pos < length()) &&
+ (at(pos) != RLE) &&
+ (at(pos) != LRE) &&
+ (at(pos) != RLO) &&
+ (at(pos) != LRO) &&
+ (at(pos).direction() > 1) &&
+ (at(pos).direction() != QChar::DirAL)) // not R and not L
+ pos++;
+
+ if (pos == length())
+ return DirNeutral;
+
+ if ((at(pos).direction() == QChar::DirR) ||
+ (at(pos).direction() == QChar::DirAL) ||
+ (at(pos) == RLE) ||
+ (at(pos) == RLO))
+ return DirRTL;
+ return DirLTR;
+#else
+ return DirLTR;
+#endif
}
#ifndef QT_NO_UNICODETABLES
diff --git a/qtools/qstring.h b/qtools/qstring.h
index df3873d..5fcff29 100644
--- a/qtools/qstring.h
+++ b/qtools/qstring.h
@@ -369,6 +369,38 @@ public:
QString &operator=( QChar c );
QString &operator=( char c );
+ enum Direction
+ {
+ /// No strongly directional text.
+ /*!
+ * As return value for direction() or baseDirection(), it means that the source string
+ * is missing or empty, or contains neither left-to-right nor right-to-left characters.
+ */
+ DirNeutral = 0x0,
+ /// Left-to-right text.
+ /*!
+ * - As return value for direction(), it means that the source string
+ * contains no right-to-left characters.
+ * - As return value for basicDirection(), it means that the first strong character
+ * of the source string has a left-to-right direction.
+ */
+ DirLTR = 0b01,
+ /// Right-to-left text.
+ /*!
+ * - As return value for direction(), it means that the source string
+ * contains no left-to-right characters.
+ * - As return value for basicDirection(), it means that the first strong character
+ * of the source string has a right-to-left direction.
+ */
+ DirRTL = 0b10,
+ /// Mixed-directional text
+ /*!
+ * As return value for direction(), it means that the source string
+ * contains both left-to-right and right-to-left characters.
+ */
+ DirMixed = 0b11
+ };
+
//QT_STATIC_CONST QString null;
//bool isNull() const;
@@ -535,8 +567,9 @@ public:
#endif
// new functions for BiDi
void compose();
- QChar::Direction basicDirection();
- QString visual(int index = 0, int len = -1);
+ QString::Direction direction() const;
+ QString::Direction basicDirection() const;
+ QString visual(int index = 0, int len = -1);
#ifndef QT_NO_COMPAT
const char* data() const { return latin1(); }