TextBreaks::Positions TextBreaks::wordBreaks(const QString &text) { Positions breaks; if (text.isEmpty()) { return breaks; } int i=0; do { if (i == 0 || isWordSeparator(text[i])) { Position pos; // Seek past leading separators while (i < text.length() && isWordSeparator(text[i])) { i++; } pos.start = i; while (i < text.length() && !isWordSeparator(text[i])) { i++; } pos.length = i - pos.start; if (pos.length > 0) { breaks.append(pos); } } else { i++; } } while (i < text.length()); return breaks; }
TextBreaks::Positions TextBreaks::sentenceBreaks(const QString & text) { Positions breaks; if (text.isEmpty()) return breaks; int i=0; do { if (i == 0 || isSentenceSeparator(text[i])) { Position pos; while (i < text.length() && !text[i].isLetter()) { i++; } pos.start = i; do { i++; } while (i < text.length() && !isSentenceSeparator(text[i])); pos.length = i - pos.start; // null-terminated, hence more than 1 if (pos.length > 1) breaks.append(pos); } else { i++; } } while (i < text.length()); return breaks; }