summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-03-03 05:20:17 (GMT)
committerAndrew den Exter <andrew.den-exter@nokia.com>2011-03-30 00:35:10 (GMT)
commit84413a25bc025f099a075387fb6ab8449d9ef217 (patch)
tree1b13a4beb5cfe6faccad0a3def7a0f05c39947c2 /src/corelib
parentf0c6b3eefdf342bbb71e9409ea050da3c92ac861 (diff)
downloadQt-84413a25bc025f099a075387fb6ab8449d9ef217.zip
Qt-84413a25bc025f099a075387fb6ab8449d9ef217.tar.gz
Qt-84413a25bc025f099a075387fb6ab8449d9ef217.tar.bz2
Return correct boundaries reasons from QTextBoundaryFinder.
The next character after a boundary is at pos, not pos + 1. Also consider whether the previous and next character are whitespace in combination when determing word boudaries otherwise positions between whitespace characters will return both StartWord and EndWord. And since there's no need to look ahead one character don't shortcut` the regular logic for the boundary before the last character. Change-Id: I2efbf3947066767945f96bf8456ef518d2149191 Task-number: QTBUG-11365 Reviewed-by: Denis Dzyubenko Reviewed-by: Ritt Konstantin
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qtextboundaryfinder.cpp30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/corelib/tools/qtextboundaryfinder.cpp b/src/corelib/tools/qtextboundaryfinder.cpp
index c2bb094..34bc406 100644
--- a/src/corelib/tools/qtextboundaryfinder.cpp
+++ b/src/corelib/tools/qtextboundaryfinder.cpp
@@ -457,33 +457,23 @@ QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons() cons
return NotAtBoundary;
return StartWord;
}
- if (pos >= length - 1) {
+ if (pos == length) {
if (d->attributes[length-1].whiteSpace)
return NotAtBoundary;
return EndWord;
}
- BoundaryReasons answer;
- const bool nextIsSpace = d->attributes[pos + 1].whiteSpace;
+ const bool nextIsSpace = d->attributes[pos].whiteSpace;
const bool prevIsSpace = d->attributes[pos - 1].whiteSpace;
- if (d->attributes[pos].whiteSpace)
- answer = EndWord;
- else if (!prevIsSpace) {
- answer = StartWord;
- answer |= EndWord;
- }
-
- if (prevIsSpace)
- answer |= StartWord;
- if (nextIsSpace)
- answer |= EndWord;
- if (answer == 0) {
- answer = StartWord;
- answer |= EndWord;
- }
-
- return answer;
+ if (prevIsSpace && !nextIsSpace)
+ return StartWord;
+ else if (!prevIsSpace && nextIsSpace)
+ return EndWord;
+ else if (!prevIsSpace && !nextIsSpace)
+ return BoundaryReasons(StartWord | EndWord);
+ else
+ return NotAtBoundary;
}
QT_END_NAMESPACE