epoc32/include/tuladdressstringtokenizer.h
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tuladdressstringtokenizer.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,165 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* 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
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +#ifndef __TULADDRESSSTRINGTOKENIZER_H__
    1.24 +#define __TULADDRESSSTRINGTOKENIZER_H__
    1.25 +
    1.26 +#include <e32base.h>
    1.27 +
    1.28 +/**
    1.29 +Address String Tokenizer API offers methods for parsing phone numbers and e-mail, 
    1.30 +URL and URI addresses from the given text. The API consists of the 
    1.31 +CTulAddressStringTokenizer class.
    1.32 +
    1.33 +Usage:
    1.34 +
    1.35 +@code
    1.36 + #include <tuladdressstringtokenizer.h>
    1.37 +
    1.38 + // SFoundItem instance
    1.39 + CTulAddressStringTokenizer::SFoundItem item;
    1.40 +
    1.41 + // Some text
    1.42 + TBufC<256> strSomeText(_L("Mail to me@someplace.com or call 040 1234567. 
    1.43 + You can also tune in to audio feed at rtsp://someplace.com/somefeed.ra."));
    1.44 +	
    1.45 + // First the user has to create an instance of CTulAddressStringTokenizer by using the
    1.46 + // factory method NewL(). The method takes two parameters. The first 
    1.47 + // parameter defines the text to be searched from and the second parameter 
    1.48 + // tells what exactly is being looked for.
    1.49 + CTulAddressStringTokenizer singleSearch = CTulAddressStringTokenizer::NewL(strSomeText, 
    1.50 +                  CTulAddressStringTokenizer::EFindItemSearchMailAddressBin);
    1.51 +
    1.52 + // The passed text is parsed in construction, and found items can be fetched 
    1.53 + // by using the ItemArray() method. It returns a constant array containing 
    1.54 + // all the found items. The interface also offers helper functions for 
    1.55 + // handling the item array by itself. 
    1.56 +
    1.57 + // Get count of found items.
    1.58 + TInt count(singleSearch->ItemCount());
    1.59 +
    1.60 + // Get currently selected item (me@someplace.com) to the result1 variable.
    1.61 + singleSearch->Item(item);
    1.62 + TPtrC16 result1(strSomeText.Mid(item.iStartPos, item.iLength));
    1.63 +
    1.64 + // Deallocate memory
    1.65 + delete singleSearch;
    1.66 +
    1.67 + // Create an instance of CTulAddressStringTokenizer and look for all possible 
    1.68 + // things (cases work as binary mask).
    1.69 + CTulAddressStringTokenizer* multiSearch = CTulAddressStringTokenizer::NewL(strSomeText,
    1.70 +                  (CTulAddressStringTokenizer::EFindItemSearchPhoneNumberBin |           
    1.71 +                  CTulAddressStringTokenizer::EFindItemSearchURLBin | 
    1.72 +                  CTulAddressStringTokenizer::EFindItemSearchMailAddressBin | 
    1.73 +                  CTulAddressStringTokenizer::EFindItemSearchScheme));
    1.74 +
    1.75 + // Get count of found items.
    1.76 + TInt count2(multiSearch->ItemCount());
    1.77 +
    1.78 + // Get currently selected item to the result2 variable.
    1.79 + multiSearch->Item(item);
    1.80 +
    1.81 + // Debug print all items and their type.
    1.82 + for( TInt i=0; i<count2; i++)
    1.83 +     {
    1.84 +     TPtrC16 result2(strSomeText.Mid(item.iStartPos, item.iLength));
    1.85 +     RDebug::Print(_L("Found type %d item:"), item.iItemType);
    1.86 +     RDebug::Print(_L("%S"), &result2);
    1.87 +     multiSearch->NextItem(item);
    1.88 +     }
    1.89 +
    1.90 + // Deallocate memory
    1.91 + delete multiSearch;
    1.92 +@endcode
    1.93 +
    1.94 +@publishedAll
    1.95 +@released
    1.96 +*/
    1.97 +
    1.98 +class CTulAddressStringTokenizer : public CBase
    1.99 +    {
   1.100 +public:
   1.101 +#define TFindItemSearchCase TTokenizerSearchCase	// For source compatibility with S60 only
   1.102 +    /**
   1.103 +    Enumeration to define the search case. 
   1.104 +    Multiple enumerations can be used as binary mask.
   1.105 +    */
   1.106 +    enum TTokenizerSearchCase
   1.107 +        {
   1.108 +        // Searches phone numbers.
   1.109 +		EFindItemSearchPhoneNumberBin = 4, 
   1.110 +        // Searches mail addresses.
   1.111 +        EFindItemSearchMailAddressBin = 8,
   1.112 +        // Searches fixed start URLs ("http://", "https://", "rtsp://"), "www.", "wap." and IPv4 addresses.
   1.113 +        EFindItemSearchURLBin  = 16,
   1.114 +        // Searches for all URIs containing a scheme.
   1.115 +        EFindItemSearchScheme  = 32
   1.116 +        };
   1.117 +
   1.118 +    // Struct to contain a found item.
   1.119 +    struct SFoundItem
   1.120 +        {
   1.121 +        TInt iStartPos;	// Start position of the found item.
   1.122 +        TInt iLength;	// Length of the found item (characters).
   1.123 +        TTokenizerSearchCase iItemType;		// Search case of the found item
   1.124 +		};
   1.125 +
   1.126 +public:  // Constructors and destructor
   1.127 +    IMPORT_C static CTulAddressStringTokenizer* NewL( const TDesC& aText, TInt aSearchCases );
   1.128 +    IMPORT_C static CTulAddressStringTokenizer* NewL( const TDesC& aText,  TInt aSearchCases, TInt aMinNumbers );
   1.129 +    IMPORT_C ~CTulAddressStringTokenizer();
   1.130 +public:
   1.131 +	IMPORT_C TInt ItemCount() const;
   1.132 +    IMPORT_C TBool Item( SFoundItem& aItem ) const;
   1.133 +    IMPORT_C TBool NextItem( SFoundItem& aItem );
   1.134 +    IMPORT_C TBool PrevItem( SFoundItem& aItem );
   1.135 +    IMPORT_C const CArrayFixFlat<SFoundItem>* ItemArray() const;
   1.136 +	IMPORT_C TInt Position() const;	
   1.137 +    IMPORT_C void ResetPosition();
   1.138 +    IMPORT_C TInt DoNewSearchL( const TDesC& aText, TInt aSearchCases);
   1.139 +    IMPORT_C TInt DoNewSearchL( const TDesC& aText, TInt aSearchCases,  TInt aMinNumbers );
   1.140 +private:
   1.141 +    CTulAddressStringTokenizer();
   1.142 +    void AddItemL( TInt aStartPos, TInt aLength, TTokenizerSearchCase aType );
   1.143 +
   1.144 +    TBool SearchPhoneNumberL( const TDesC& aText );
   1.145 +    TBool SearchMailAddressL( const TDesC& aText );  
   1.146 +    TBool SearchGenericUriL( const TDesC& aText );
   1.147 +    TBool SearchUrlL( const TDesC& aText, TBool aFindFixedSchemas );
   1.148 +    TBool ParseUrlL( const TDesC& aType, const TPtrC& aTokenPtr, TInt aTextOffset );
   1.149 +
   1.150 +    static TBool IsValidEmailChar(const TChar& charac); // Login part of the e-mail address
   1.151 +    static TBool IsValidEmailHostChar(const TChar& charac); // Host part of the e-mail address
   1.152 +    static TBool IsValidPhoneNumberChar(const TChar& charac); // Phone number
   1.153 +    static TBool IsValidUrlChar( const TChar& charac); // URL
   1.154 +
   1.155 +    void ConstructL( const TDesC& aText, TInt aSearchCases, TInt aMinNumbers );
   1.156 +	void PerformSearchL( const TDesC& aText, TInt aSearchCases );
   1.157 +    
   1.158 +    CTulAddressStringTokenizer( const CTulAddressStringTokenizer& );	// Prohibit copy constructor
   1.159 +    CTulAddressStringTokenizer& operator= ( const CTulAddressStringTokenizer& );  // Prohibit assigment operator
   1.160 +private:
   1.161 +    CArrayFixFlat<SFoundItem>* iFoundItems;		// Array of all found items.
   1.162 +    TInt iPosition;		// Engine's position in the iFoundItems.
   1.163 +    TInt iMinNumbers;	// Minimum count of numbers in a phone number
   1.164 +    };
   1.165 +
   1.166 +
   1.167 +#endif      // __TULADDRESSSTRINGTOKENIZER_H__
   1.168 +