Home · All Classes · Main Classes · Deprecated |
implements language-sensitive text searching More...
Public Member Functions | |
MStringSearch (const QString &pattern, const QString &text, const MLocale &locale, MBreakIterator::Type breakIteratorType=MBreakIterator::CharacterIterator) | |
virtual | ~MStringSearch () |
QString | errorString () const |
void | setLocale (const MLocale &locale) |
void | setText (const QString &text) |
QString | text () const |
void | setPattern (const QString &pattern) |
QString | pattern () const |
void | setCollatorStrength (MLocale::CollatorStrength collatorStrength) |
MLocale::CollatorStrength | collatorStrength () const |
void | setAlternateHandlingShifted (bool isShifted) |
bool | alternateHandlingShifted () const |
int | first () |
int | last () |
int | next () |
int | previous () |
int | offset () const |
void | setOffset (int offset) |
int | matchedStart () const |
int | matchedLength () const |
QString | matchedText () const |
implements language-sensitive text searching
By default, MStringSearch tries to be very lenient, i.e. by default it ignores accent differences, case differences, white space and punctuation and matches substrings anywhere in the text. But there are options to select stricter matching as well.
Examples:
In English locale, the search pattern “aa” matches by default all uppercase and lowercase variants and accent variants of “aa”, i.e. it matches “Aa”, “aÁ”, ...:
QString pattern("aa"); QString text("Aaland Åland Ááland"); MLocale locale("en_US"); int start, length; QString match; MStringSearch stringSearch(pattern, text, locale); if (stringSearch.first() != -1) { start = stringSearch.matchedStart(); // now contains “0” length = stringSearch.matchedLength(); // now contains “2” match = stringSearch.matchedText(); // now contains “Aa” } if (stringSearch.last() != -1) { start = stringSearch.matchedStart(); // now contains “13” length = stringSearch.matchedLength(); // now contains “2” match = stringSearch.matchedText(); // now contains “Áá” }
In Danish locale, “aa” is considered as a character on its own with only a tertiary difference to “å”, therefore searching for “aa” matches “aa”, “Aa”, “aA”, “å”, and “Å”. But it does not match “Áá”
QString pattern("aa"); QString text("Aaland Åland Ááland"); MLocale locale("da_DK"); int start, length; QString match; MStringSearch stringSearch(pattern, text, locale); if (stringSearch.first() != -1) { start = stringSearch.matchedStart(); // now contains “0” length = stringSearch.matchedLength(); // now contains “2” match = stringSearch.matchedText(); // now contains “Aa” } if (stringSearch.last() != -1) { start = stringSearch.matchedStart(); // now contains “7” length = stringSearch.matchedLength(); // now contains “1” match = stringSearch.matchedText(); // now contains “Å” }
In a Chinese locale which uses pinyin sorting, e.g. “zh_CN”, “zh_SG”, “zh_CN=pinyin”, “zh_TW=pinyin”, ... Chinese characters can be matched via their pinyin transcription.
For example “liu” will match “liu”, “líu”, “liǔ”, “刘”, “柳”, .. and all other Chinese characters which have a pinyin transcription of “liu” (any tone). But if the pattern contains Chinese, it will only match Chinese characters exactly, e.g. the pattern “刘” will only match “刘”, it will not match “líu”, “liǔ”, “柳”, ...
Mixed input will only match the Chinese exactly, i.e. the pattern “liu 刘” will match “liu 刘”, “liu刘”, “líu刘”, ... but will not match “liu 柳”.
ML10N::MStringSearch::MStringSearch | ( | const QString & | pattern, | |
const QString & | text, | |||
const MLocale & | locale, | |||
MBreakIterator::Type | breakIteratorType = MBreakIterator::CharacterIterator | |||
) |
constructs a MStringSearch
pattern,: | the search string to search for | |
text,: | the text in which the search string is searched | |
locale,: | the locale which determines the language-specific rules | |
breakIteratorType,: | the break iterator type to use |
The default for the break iterator type is MBreakIterator::CharacterIterator. Possible choices for the break iterator type are:
ML10N::MStringSearch::~MStringSearch | ( | ) | [virtual] |
destructor for MStringSearch
bool ML10N::MStringSearch::alternateHandlingShifted | ( | ) | const |
gets whether alternate characters are handled shifted or not
MLocale::CollatorStrength ML10N::MStringSearch::collatorStrength | ( | ) | const |
gets the strength of the collator currently used for searching
QString ML10N::MStringSearch::errorString | ( | ) | const |
int ML10N::MStringSearch::first | ( | ) |
returns the first index at which the search pattern matches in the text returns “-1” if there is no match.
If there is a match, matchedStart(), matchedLength(), and matchedText() can be used to find out what was matched.
int ML10N::MStringSearch::last | ( | ) |
returns the last index at which the search pattern matches in the text returns “-1” if there is no match.
If there is a match, matchedStart(), matchedLength(), and matchedText() can be used to find out what was matched.
int ML10N::MStringSearch::matchedLength | ( | ) | const |
returns the start index of a match found by a previous command
Returns the length of the text that was matched by the most recent call to first(), last(), next(), previous().
int ML10N::MStringSearch::matchedStart | ( | ) | const |
returns the start index of a match found by a previous command
Returns the start index of the text that was matched by the most recent call to first(), last(), next(), previous().
QString ML10N::MStringSearch::matchedText | ( | ) | const |
returns the start index of a match found by a previous command
Returns the text that was matched by the most recent call to first(), last(), next(), previous().
int ML10N::MStringSearch::next | ( | ) |
moves to the next match
Returns the index of the next point at which the text matches the search pattern, starting from the current position.
The iterator is adjusted so that its current index (as returned by offset()) is the match position if one was found.
Returns “-1” if there no next match is found.
If there is a match, matchedStart(), matchedLength(), and matchedText() can be used to find out what was matched.
int ML10N::MStringSearch::offset | ( | ) | const |
returns the current search index position
QString ML10N::MStringSearch::pattern | ( | ) | const |
get the string which is searched for
int ML10N::MStringSearch::previous | ( | ) |
moves to the previous < match
Returns the index of the previous point at which the string text matches the search pattern, starting at the current position.
The iterator is adjusted so that its current index (as returned by offset()) is the match position if one was found.
Returns “-1” if there no previous match is found.
If there is a match, matchedStart(), matchedLength(), and matchedText() can be used to find out what was matched.
void ML10N::MStringSearch::setAlternateHandlingShifted | ( | bool | isShifted | ) |
sets whether the alternate characters are handled shifted or not
The default is true.
“true”, i.e. “shifted” basically means that white space and punctuation is ignore when matching.
void ML10N::MStringSearch::setCollatorStrength | ( | MLocale::CollatorStrength | collatorStrength | ) |
set the strength of the collator used for searching
The default strength of MStringSearch is MLocale::CollatorStrengthPrimary. Therefore, accent differences and case differences are ignored by default.
Accent differences usually have secondary strength and case differences usually have tertiary strength. Therefore, setting secondary strengths would not ignore accent differences anymore but still ignore case differences, setting tertiary strength would neither ignore accent differences nor case differences.
void ML10N::MStringSearch::setLocale | ( | const MLocale & | locale | ) |
sets the locale used for the language-sensitive text searching
void ML10N::MStringSearch::setOffset | ( | int | offset | ) |
sets the current search index position
void ML10N::MStringSearch::setPattern | ( | const QString & | pattern | ) |
sets the string to search in the text
void ML10N::MStringSearch::setText | ( | const QString & | text | ) |
sets text in which the pattern is searched
QString ML10N::MStringSearch::text | ( | ) | const |
get the text in which the pattern is searched
Copyright © 2010 Nokia Corporation | MeeGo Touch |