diff options
Diffstat (limited to 'qtools/qstring.cpp')
-rw-r--r-- | qtools/qstring.cpp | 95 |
1 files changed, 73 insertions, 22 deletions
diff --git a/qtools/qstring.cpp b/qtools/qstring.cpp index d831cb1..698efcf 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 |