inline bool isWordCharacter(const QChar& c) { // The Qt docs say for word characters: // \w - Matches a word character (QChar::isLetterOrNumber(), QChar::isMark(), or '_'). // see also: http://doc.trolltech.com/qregexp.html return c.isLetterOrNumber() || c.isMark() || c.unicode() == '_'; }
bool Tokenizer::isWordChar(const QChar& c) { // this method exists because some languages have non-letter category charaters // mixed with their letter character to make words (like hindi) // NOTE: this has to be extended then languages give problems, // just add a category in the following test return (c.isLetter() || c.isMark()); }
CmdState YModeInsert::deleteWordBefore(const YCommandArgs &args) { YCursor cur = args.view->getLinePositionCursor(); YBuffer* mBuffer = args.view->buffer(); if(cur.x() == 0 && cur.y() > 0 && args.view->getLocalStringOption("backspace").contains("eol")) { mBuffer->action()->mergeNextLine(args.view, cur.y() - 1); //mBuffer->action()->deleteChar( mView, *mView->getLinePositionCursor(), 1 ); see bug #158 } else { QString line = mBuffer->textline(cur.y()); QChar tmp; bool isWord; int x = cur.x(); // delete whitespace characters preceding current word while(x > 0 && line[x - 1].isSpace()) { --x; } // delete a word or set of not-word not-whitespace characters if(x > 0) { tmp = line[x - 1]; isWord = tmp.isLetterOrNumber() || tmp == '_' || tmp.isMark(); // delete word behind the cursor (if there is one) if(isWord) while(isWord && --x > 0) { tmp = line[x - 1]; isWord = (tmp.isLetterOrNumber() || tmp == '_' || tmp.isMark()); } // otherwise, delete all not-word and not-whitespace // characters behind the cursor else while(!isWord && !tmp.isSpace() && --x > 0) { tmp = line[x - 1]; isWord = (tmp.isLetterOrNumber() || tmp == '_' || tmp.isMark()); } } //do it mBuffer->action()->deleteChar(args.view, x, cur.y(), cur.x() - x); } return CmdOk; }
QString WordFixFormattedStringVisitor::fixWord(const QString &content, const QString &word, const QString &fix) { QString result = content; const int wordLength = word.length(); const int fixLength = fix.length(); int pos = 0; while ((pos = result.indexOf(word, pos)) != -1) { bool beginsWord = (pos == 0); if (!beginsWord) { const QChar ch(result.at(pos - 1)); beginsWord = !ch.isLetterOrNumber() && !ch.isMark() && ch != QLatin1Char('_'); if (!beginsWord) { pos += wordLength; continue; } } bool endsWord = (pos + wordLength == result.length()); if (!endsWord) { const QChar ch(result.at(pos + wordLength)); endsWord = !ch.isLetterOrNumber() && !ch.isMark() && ch != QLatin1Char('_'); if (!endsWord) { pos += wordLength; continue; } } result.replace(pos, wordLength, fix); pos += fixLength; } return result; }
static bool to8bit(const QChar ch, QCString *rstr) { bool converted = FALSE; if( ch.isMark() ) return TRUE; // ignore marks for conversion if ( ch.row() ) { if ( ch.row() == 0x05 ) { if ( ch.cell() > 0x91 ) converted = TRUE; // 0x0591 - 0x05cf: Hebrew punctuation... dropped if ( ch.cell() >= 0xD0 ) *rstr += (char)unicode_to_heb_05[ch.cell()- 0xD0]; } else if ( ch.row() == 0x20 ) { if ( ch.cell() == 0x3E ) { *rstr += (char)0xAF; converted = TRUE; } else if ( ch.cell() == 0x17 ) { *rstr += (char)0xCF; converted = TRUE; } } else { converted = FALSE; } } else { if ( ch.cell() < 0x80 ) { *rstr += (char)ch.cell(); converted = TRUE; } else if( ch.cell() < 0xA0 ) { *rstr += (char)unicode_to_heb_00[ch.cell() - 0x80]; converted = TRUE; } } if(converted) return TRUE; // couldn't convert the char... lets try its decomposition QString d = ch.decomposition(); if(d.isNull()) return FALSE; int l = d.length(); for (int i=0; i<l; i++) { const QChar ch = d[i]; if(to8bit(ch, rstr)) converted = TRUE; } return converted; }
// Return the range containing the word left of the cursor KTextEditor::Range KateWordCompletionModel::completionRange(KTextEditor::View* view, const KTextEditor::Cursor &position) { int line = position.line(); int col = position.column(); KTextEditor::Document *doc = view->document(); while ( col > 0 ) { QChar c = ( doc->character( KTextEditor::Cursor( line, col-1 ) ) ); if ( c.isLetterOrNumber() || c.isMark() || c == '_' ) { col--; continue; } break; } return KTextEditor::Range( KTextEditor::Cursor( line, col ), position ); }
inline bool isWordCharacter(const QChar &c) { // http://pcre.org/pcre.txt say for word characters: // \w any character that matches \p{L} or \p{N}, plus underscore return c.isLetterOrNumber() || c.isMark() || c.unicode() == '_'; }
static inline bool isSentenceSeparator(const QChar &character) { return character.isMark() || character.isPunct() || character.category() == QChar::Separator_Paragraph; }
static inline bool isWordSeparator(const QChar character) { return character.isSpace() || character.isMark() || character.isPunct() || character.isSymbol(); }