| class CTulAddressStringTokenizer : public CBase |
Address String Tokenizer API offers methods for parsing phone numbers and e-mail, URL and URI addresses from the given text. The API consists of the CTulAddressStringTokenizer class.
Usage:
#include <tuladdressstringtokenizer.h>
// SFoundItem instance
CTulAddressStringTokenizer::SFoundItem item;
// Some text
TBufC<256> strSomeText(_L("Mail to [email protected] or call 040 1234567.
You can also tune in to audio feed at rtsp://someplace.com/somefeed.ra."));
// First the user has to create an instance of CTulAddressStringTokenizer by using the
// factory method NewL(). The method takes two parameters. The first
// parameter defines the text to be searched from and the second parameter
// tells what exactly is being looked for.
CTulAddressStringTokenizer singleSearch = CTulAddressStringTokenizer::NewL(strSomeText,
CTulAddressStringTokenizer::EFindItemSearchMailAddressBin);
// The passed text is parsed in construction, and found items can be fetched
// by using the ItemArray() method. It returns a constant array containing
// all the found items. The interface also offers helper functions for
// handling the item array by itself.
// Get count of found items.
TInt count(singleSearch->ItemCount());
// Get currently selected item ([email protected]) to the result1 variable.
singleSearch->Item(item);
TPtrC16 result1(strSomeText.Mid(item.iStartPos, item.iLength));
// Deallocate memory
delete singleSearch;
// Create an instance of CTulAddressStringTokenizer and look for all possible
// things (cases work as binary mask).
CTulAddressStringTokenizer* multiSearch = CTulAddressStringTokenizer::NewL(strSomeText,
(CTulAddressStringTokenizer::EFindItemSearchPhoneNumberBin |
CTulAddressStringTokenizer::EFindItemSearchURLBin |
CTulAddressStringTokenizer::EFindItemSearchMailAddressBin |
CTulAddressStringTokenizer::EFindItemSearchScheme));
// Get count of found items.
TInt count2(multiSearch->ItemCount());
// Get currently selected item to the result2 variable.
multiSearch->Item(item);
// Debug print all items and their type.
for( TInt i=0; i<count2; i++)
{
TPtrC16 result2(strSomeText.Mid(item.iStartPos, item.iLength));
RDebug::Print(_L("Found type %d item:"), item.iItemType);
RDebug::Print(_L("%S"), &result2);
multiSearch->NextItem(item);
}
// Deallocate memory
delete multiSearch;
| Public Member Functions | |
|---|---|
| ~CTulAddressStringTokenizer() | |
| IMPORT_C TInt | DoNewSearchL(const TDesC &, TInt) |
| IMPORT_C TInt | DoNewSearchL(const TDesC &, TInt, TInt) |
| IMPORT_C TBool | Item(SFoundItem &) |
| IMPORT_C const CArrayFixFlat< SFoundItem > * | ItemArray() |
| IMPORT_C TInt | ItemCount() |
| IMPORT_C CTulAddressStringTokenizer * | NewL(const TDesC &, TInt) |
| IMPORT_C CTulAddressStringTokenizer * | NewL(const TDesC &, TInt, TInt) |
| IMPORT_C TBool | NextItem(SFoundItem &) |
| IMPORT_C TInt | Position() |
| IMPORT_C TBool | PrevItem(SFoundItem &) |
| IMPORT_C void | ResetPosition() |
| Private Member Functions | |
|---|---|
| CTulAddressStringTokenizer() | |
| CTulAddressStringTokenizer(const CTulAddressStringTokenizer &) | |
| void | AddItemL(TInt, TInt, TTokenizerSearchCase) |
| void | ConstructL(const TDesC &, TInt, TInt) |
| TBool | IsValidEmailChar(const TChar &) |
| TBool | IsValidEmailHostChar(const TChar &) |
| TBool | IsValidPhoneNumberChar(const TChar &) |
| TBool | IsValidUrlChar(const TChar &) |
| TBool | ParseUrlL(const TDesC &, const TPtrC &, TInt) |
| void | PerformSearchL(const TDesC &, TInt) |
| TBool | SearchGenericUriL(const TDesC &) |
| TBool | SearchMailAddressL(const TDesC &) |
| TBool | SearchPhoneNumberL(const TDesC &) |
| TBool | SearchUrlL(const TDesC &, TBool) |
| CTulAddressStringTokenizer & | operator=(const CTulAddressStringTokenizer &) |
| Public Member Enumerations | |
|---|---|
| enum | TTokenizerSearchCase { EFindItemSearchPhoneNumberBin = 4, EFindItemSearchMailAddressBin = 8, EFindItemSearchURLBin = 16, EFindItemSearchScheme = 32 } |
| Private Attributes | |
|---|---|
| CArrayFixFlat< SFoundItem > * | iFoundItems |
| TInt | iMinNumbers |
| TInt | iPosition |
| CTulAddressStringTokenizer | ( | const CTulAddressStringTokenizer & | ) | [private] |
| const CTulAddressStringTokenizer & |
| void | AddItemL | ( | TInt | aStartPos, |
| TInt | aLength, | |||
| TTokenizerSearchCase | aType | |||
| ) | [private] | |||
| TInt aStartPos | |
| TInt aLength | |
| TTokenizerSearchCase aType |
| void | ConstructL | ( | const TDesC & | aText, |
| TInt | aSearchCases, | |||
| TInt | aMinNumbers | |||
| ) | [private] | |||
| IMPORT_C TInt | DoNewSearchL | ( | const TDesC & | aText, |
| TInt | aSearchCases, | |||
| TInt | aMinNumbers | |||
| ) | ||||
| TBool | IsValidEmailChar | ( | const TChar & | charac | ) | [private, static] |
| const TChar & charac |
| TBool | IsValidEmailHostChar | ( | const TChar & | charac | ) | [private, static] |
| const TChar & charac |
| TBool | IsValidPhoneNumberChar | ( | const TChar & | charac | ) | [private, static] |
| const TChar & charac |
| TBool | IsValidUrlChar | ( | const TChar & | charac | ) | [private, static] |
| const TChar & charac |
| IMPORT_C CTulAddressStringTokenizer * | NewL | ( | const TDesC & | aText, |
| TInt | aSearchCases | |||
| ) | [static] | |||
| IMPORT_C CTulAddressStringTokenizer * | NewL | ( | const TDesC & | aText, |
| TInt | aSearchCases, | |||
| TInt | aMinNumbers | |||
| ) | [static] | |||
| TBool | ParseUrlL | ( | const TDesC & | aType, |
| const TPtrC & | aTokenPtr, | |||
| TInt | aTextOffset | |||
| ) | [private] | |||
| void | PerformSearchL | ( | const TDesC & | aText, |
| TInt | aSearchCases | |||
| ) | [private] | |||
| TBool | SearchGenericUriL | ( | const TDesC & | aText | ) | [private] |
| const TDesC & aText |
| TBool | SearchMailAddressL | ( | const TDesC & | aText | ) | [private] |
| const TDesC & aText |
| TBool | SearchPhoneNumberL | ( | const TDesC & | aText | ) | [private] |
| const TDesC & aText |
| TBool | SearchUrlL | ( | const TDesC & | aText, |
| TBool | aFindFixedSchemas | |||
| ) | [private] | |||
| CTulAddressStringTokenizer & | operator= | ( | const CTulAddressStringTokenizer & | ) | [private] |
| const CTulAddressStringTokenizer & |
Enumeration to define the search case. Multiple enumerations can be used as binary mask.
| EFindItemSearchPhoneNumberBin = 4 | |
| EFindItemSearchMailAddressBin = 8 | |
| EFindItemSearchURLBin = 16 | |
| EFindItemSearchScheme = 32 |