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; }
size_t BasicTextInput::findWordRight() const { size_t newPos = m_cursorPos; while(newPos < m_text.size() && isWordSeparator(m_text[newPos])) { newPos++; } while(newPos < m_text.size() && !isWordSeparator(m_text[newPos])) { newPos++; } return newPos; }
size_t BasicTextInput::findWordLeft() const { size_t newPos = m_cursorPos; while(newPos > 0 && isWordSeparator(m_text[newPos - 1])) { newPos--; } while(newPos > 0 && !isWordSeparator(m_text[newPos - 1])) { newPos--; } return newPos; }