williamr@2: /* williamr@2: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: #ifndef __TULADDRESSSTRINGTOKENIZER_H__ williamr@2: #define __TULADDRESSSTRINGTOKENIZER_H__ williamr@2: williamr@2: #include williamr@2: williamr@2: /** williamr@2: Address String Tokenizer API offers methods for parsing phone numbers and e-mail, williamr@2: URL and URI addresses from the given text. The API consists of the williamr@2: CTulAddressStringTokenizer class. williamr@2: williamr@2: Usage: williamr@2: williamr@2: @code williamr@2: #include williamr@2: williamr@2: // SFoundItem instance williamr@2: CTulAddressStringTokenizer::SFoundItem item; williamr@2: williamr@2: // Some text williamr@2: TBufC<256> strSomeText(_L("Mail to me@someplace.com or call 040 1234567. williamr@2: You can also tune in to audio feed at rtsp://someplace.com/somefeed.ra.")); williamr@2: williamr@2: // First the user has to create an instance of CTulAddressStringTokenizer by using the williamr@2: // factory method NewL(). The method takes two parameters. The first williamr@2: // parameter defines the text to be searched from and the second parameter williamr@2: // tells what exactly is being looked for. williamr@2: CTulAddressStringTokenizer singleSearch = CTulAddressStringTokenizer::NewL(strSomeText, williamr@2: CTulAddressStringTokenizer::EFindItemSearchMailAddressBin); williamr@2: williamr@2: // The passed text is parsed in construction, and found items can be fetched williamr@2: // by using the ItemArray() method. It returns a constant array containing williamr@2: // all the found items. The interface also offers helper functions for williamr@2: // handling the item array by itself. williamr@2: williamr@2: // Get count of found items. williamr@2: TInt count(singleSearch->ItemCount()); williamr@2: williamr@2: // Get currently selected item (me@someplace.com) to the result1 variable. williamr@2: singleSearch->Item(item); williamr@2: TPtrC16 result1(strSomeText.Mid(item.iStartPos, item.iLength)); williamr@2: williamr@2: // Deallocate memory williamr@2: delete singleSearch; williamr@2: williamr@2: // Create an instance of CTulAddressStringTokenizer and look for all possible williamr@2: // things (cases work as binary mask). williamr@2: CTulAddressStringTokenizer* multiSearch = CTulAddressStringTokenizer::NewL(strSomeText, williamr@2: (CTulAddressStringTokenizer::EFindItemSearchPhoneNumberBin | williamr@2: CTulAddressStringTokenizer::EFindItemSearchURLBin | williamr@2: CTulAddressStringTokenizer::EFindItemSearchMailAddressBin | williamr@2: CTulAddressStringTokenizer::EFindItemSearchScheme)); williamr@2: williamr@2: // Get count of found items. williamr@2: TInt count2(multiSearch->ItemCount()); williamr@2: williamr@2: // Get currently selected item to the result2 variable. williamr@2: multiSearch->Item(item); williamr@2: williamr@2: // Debug print all items and their type. williamr@2: for( TInt i=0; iNextItem(item); williamr@2: } williamr@2: williamr@2: // Deallocate memory williamr@2: delete multiSearch; williamr@2: @endcode williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: williamr@2: class CTulAddressStringTokenizer : public CBase williamr@2: { williamr@2: public: williamr@2: #define TFindItemSearchCase TTokenizerSearchCase // For source compatibility with S60 only williamr@2: /** williamr@2: Enumeration to define the search case. williamr@2: Multiple enumerations can be used as binary mask. williamr@2: */ williamr@2: enum TTokenizerSearchCase williamr@2: { williamr@2: // Searches phone numbers. williamr@2: EFindItemSearchPhoneNumberBin = 4, williamr@2: // Searches mail addresses. williamr@2: EFindItemSearchMailAddressBin = 8, williamr@2: // Searches fixed start URLs ("http://", "https://", "rtsp://"), "www.", "wap." and IPv4 addresses. williamr@2: EFindItemSearchURLBin = 16, williamr@2: // Searches for all URIs containing a scheme. williamr@2: EFindItemSearchScheme = 32 williamr@2: }; williamr@2: williamr@2: // Struct to contain a found item. williamr@2: struct SFoundItem williamr@2: { williamr@2: TInt iStartPos; // Start position of the found item. williamr@2: TInt iLength; // Length of the found item (characters). williamr@2: TTokenizerSearchCase iItemType; // Search case of the found item williamr@2: }; williamr@2: williamr@2: public: // Constructors and destructor williamr@2: IMPORT_C static CTulAddressStringTokenizer* NewL( const TDesC& aText, TInt aSearchCases ); williamr@2: IMPORT_C static CTulAddressStringTokenizer* NewL( const TDesC& aText, TInt aSearchCases, TInt aMinNumbers ); williamr@2: IMPORT_C ~CTulAddressStringTokenizer(); williamr@2: public: williamr@2: IMPORT_C TInt ItemCount() const; williamr@2: IMPORT_C TBool Item( SFoundItem& aItem ) const; williamr@2: IMPORT_C TBool NextItem( SFoundItem& aItem ); williamr@2: IMPORT_C TBool PrevItem( SFoundItem& aItem ); williamr@2: IMPORT_C const CArrayFixFlat* ItemArray() const; williamr@2: IMPORT_C TInt Position() const; williamr@2: IMPORT_C void ResetPosition(); williamr@2: IMPORT_C TInt DoNewSearchL( const TDesC& aText, TInt aSearchCases); williamr@2: IMPORT_C TInt DoNewSearchL( const TDesC& aText, TInt aSearchCases, TInt aMinNumbers ); williamr@2: private: williamr@2: CTulAddressStringTokenizer(); williamr@2: void AddItemL( TInt aStartPos, TInt aLength, TTokenizerSearchCase aType ); williamr@2: williamr@2: TBool SearchPhoneNumberL( const TDesC& aText ); williamr@2: TBool SearchMailAddressL( const TDesC& aText ); williamr@2: TBool SearchGenericUriL( const TDesC& aText ); williamr@2: TBool SearchUrlL( const TDesC& aText, TBool aFindFixedSchemas ); williamr@2: TBool ParseUrlL( const TDesC& aType, const TPtrC& aTokenPtr, TInt aTextOffset ); williamr@2: williamr@2: static TBool IsValidEmailChar(const TChar& charac); // Login part of the e-mail address williamr@2: static TBool IsValidEmailHostChar(const TChar& charac); // Host part of the e-mail address williamr@2: static TBool IsValidPhoneNumberChar(const TChar& charac); // Phone number williamr@2: static TBool IsValidUrlChar( const TChar& charac); // URL williamr@2: williamr@2: void ConstructL( const TDesC& aText, TInt aSearchCases, TInt aMinNumbers ); williamr@2: void PerformSearchL( const TDesC& aText, TInt aSearchCases ); williamr@2: williamr@2: CTulAddressStringTokenizer( const CTulAddressStringTokenizer& ); // Prohibit copy constructor williamr@2: CTulAddressStringTokenizer& operator= ( const CTulAddressStringTokenizer& ); // Prohibit assigment operator williamr@2: private: williamr@2: CArrayFixFlat* iFoundItems; // Array of all found items. williamr@2: TInt iPosition; // Engine's position in the iFoundItems. williamr@2: TInt iMinNumbers; // Minimum count of numbers in a phone number williamr@2: }; williamr@2: williamr@2: williamr@2: #endif // __TULADDRESSSTRINGTOKENIZER_H__ williamr@2: