src/corelib/tools/qtextboundaryfinder.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
   129     language considers to be a word.
   129     language considers to be a word.
   130 
   130 
   131     Line break boundaries give possible places where a line break
   131     Line break boundaries give possible places where a line break
   132     might happen and sentence boundaries will show the beginning and
   132     might happen and sentence boundaries will show the beginning and
   133     end of whole sentences.
   133     end of whole sentences.
       
   134 
       
   135     The first position in a string is always a valid boundary and
       
   136     refers to the position before the first character. The last
       
   137     position at the length of the string is also valid and refers
       
   138     to the position after the last character.
   134 */
   139 */
   135 
   140 
   136 /*!
   141 /*!
   137     \enum QTextBoundaryFinder::BoundaryType
   142     \enum QTextBoundaryFinder::BoundaryType
   138 
   143 
   361     case Sentence:
   366     case Sentence:
   362         while (pos < length && !d->attributes[pos].sentenceBoundary)
   367         while (pos < length && !d->attributes[pos].sentenceBoundary)
   363             ++pos;
   368             ++pos;
   364         break;
   369         break;
   365     case Line:
   370     case Line:
   366         while (pos < length && d->attributes[pos].lineBreakType < HB_Break)
   371         Q_ASSERT(pos);
       
   372         while (pos < length && d->attributes[pos-1].lineBreakType < HB_Break)
   367             ++pos;
   373             ++pos;
   368         break;
   374         break;
   369     }
   375     }
   370 
   376 
   371     return pos;
   377     return pos;
   403     case Sentence:
   409     case Sentence:
   404         while (pos > 0 && !d->attributes[pos].sentenceBoundary)
   410         while (pos > 0 && !d->attributes[pos].sentenceBoundary)
   405             --pos;
   411             --pos;
   406         break;
   412         break;
   407     case Line:
   413     case Line:
   408         while (pos > 0 && d->attributes[pos].lineBreakType < HB_Break)
   414         while (pos > 0 && d->attributes[pos-1].lineBreakType < HB_Break)
   409             --pos;
   415             --pos;
   410         break;
   416         break;
   411     }
   417     }
   412 
   418 
   413     return pos;
   419     return pos;
   428     case Grapheme:
   434     case Grapheme:
   429         return d->attributes[pos].charStop;
   435         return d->attributes[pos].charStop;
   430     case Word:
   436     case Word:
   431         return d->attributes[pos].wordBoundary;
   437         return d->attributes[pos].wordBoundary;
   432     case Line:
   438     case Line:
   433         return d->attributes[pos].lineBreakType >= HB_Break;
   439         return (pos > 0) ? d->attributes[pos-1].lineBreakType >= HB_Break : true;
   434     case Sentence:
   440     case Sentence:
   435         return d->attributes[pos].sentenceBoundary;
   441         return d->attributes[pos].sentenceBoundary;
   436     }
   442     }
   437     return false;
   443     return false;
   438 }
   444 }