Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * 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
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #ifndef __TULADDRESSSTRINGTOKENIZER_H__
21 #define __TULADDRESSSTRINGTOKENIZER_H__
26 Address String Tokenizer API offers methods for parsing phone numbers and e-mail,
27 URL and URI addresses from the given text. The API consists of the
28 CTulAddressStringTokenizer class.
33 #include <tuladdressstringtokenizer.h>
35 // SFoundItem instance
36 CTulAddressStringTokenizer::SFoundItem item;
39 TBufC<256> strSomeText(_L("Mail to me@someplace.com or call 040 1234567.
40 You can also tune in to audio feed at rtsp://someplace.com/somefeed.ra."));
42 // First the user has to create an instance of CTulAddressStringTokenizer by using the
43 // factory method NewL(). The method takes two parameters. The first
44 // parameter defines the text to be searched from and the second parameter
45 // tells what exactly is being looked for.
46 CTulAddressStringTokenizer singleSearch = CTulAddressStringTokenizer::NewL(strSomeText,
47 CTulAddressStringTokenizer::EFindItemSearchMailAddressBin);
49 // The passed text is parsed in construction, and found items can be fetched
50 // by using the ItemArray() method. It returns a constant array containing
51 // all the found items. The interface also offers helper functions for
52 // handling the item array by itself.
54 // Get count of found items.
55 TInt count(singleSearch->ItemCount());
57 // Get currently selected item (me@someplace.com) to the result1 variable.
58 singleSearch->Item(item);
59 TPtrC16 result1(strSomeText.Mid(item.iStartPos, item.iLength));
64 // Create an instance of CTulAddressStringTokenizer and look for all possible
65 // things (cases work as binary mask).
66 CTulAddressStringTokenizer* multiSearch = CTulAddressStringTokenizer::NewL(strSomeText,
67 (CTulAddressStringTokenizer::EFindItemSearchPhoneNumberBin |
68 CTulAddressStringTokenizer::EFindItemSearchURLBin |
69 CTulAddressStringTokenizer::EFindItemSearchMailAddressBin |
70 CTulAddressStringTokenizer::EFindItemSearchScheme));
72 // Get count of found items.
73 TInt count2(multiSearch->ItemCount());
75 // Get currently selected item to the result2 variable.
76 multiSearch->Item(item);
78 // Debug print all items and their type.
79 for( TInt i=0; i<count2; i++)
81 TPtrC16 result2(strSomeText.Mid(item.iStartPos, item.iLength));
82 RDebug::Print(_L("Found type %d item:"), item.iItemType);
83 RDebug::Print(_L("%S"), &result2);
84 multiSearch->NextItem(item);
95 class CTulAddressStringTokenizer : public CBase
98 #define TFindItemSearchCase TTokenizerSearchCase // For source compatibility with S60 only
100 Enumeration to define the search case.
101 Multiple enumerations can be used as binary mask.
103 enum TTokenizerSearchCase
105 // Searches phone numbers.
106 EFindItemSearchPhoneNumberBin = 4,
107 // Searches mail addresses.
108 EFindItemSearchMailAddressBin = 8,
109 // Searches fixed start URLs ("http://", "https://", "rtsp://"), "www.", "wap." and IPv4 addresses.
110 EFindItemSearchURLBin = 16,
111 // Searches for all URIs containing a scheme.
112 EFindItemSearchScheme = 32
115 // Struct to contain a found item.
118 TInt iStartPos; // Start position of the found item.
119 TInt iLength; // Length of the found item (characters).
120 TTokenizerSearchCase iItemType; // Search case of the found item
123 public: // Constructors and destructor
124 IMPORT_C static CTulAddressStringTokenizer* NewL( const TDesC& aText, TInt aSearchCases );
125 IMPORT_C static CTulAddressStringTokenizer* NewL( const TDesC& aText, TInt aSearchCases, TInt aMinNumbers );
126 IMPORT_C ~CTulAddressStringTokenizer();
128 IMPORT_C TInt ItemCount() const;
129 IMPORT_C TBool Item( SFoundItem& aItem ) const;
130 IMPORT_C TBool NextItem( SFoundItem& aItem );
131 IMPORT_C TBool PrevItem( SFoundItem& aItem );
132 IMPORT_C const CArrayFixFlat<SFoundItem>* ItemArray() const;
133 IMPORT_C TInt Position() const;
134 IMPORT_C void ResetPosition();
135 IMPORT_C TInt DoNewSearchL( const TDesC& aText, TInt aSearchCases);
136 IMPORT_C TInt DoNewSearchL( const TDesC& aText, TInt aSearchCases, TInt aMinNumbers );
138 CTulAddressStringTokenizer();
139 void AddItemL( TInt aStartPos, TInt aLength, TTokenizerSearchCase aType );
141 TBool SearchPhoneNumberL( const TDesC& aText );
142 TBool SearchMailAddressL( const TDesC& aText );
143 TBool SearchGenericUriL( const TDesC& aText );
144 TBool SearchUrlL( const TDesC& aText, TBool aFindFixedSchemas );
145 TBool ParseUrlL( const TDesC& aType, const TPtrC& aTokenPtr, TInt aTextOffset );
147 static TBool IsValidEmailChar(const TChar& charac); // Login part of the e-mail address
148 static TBool IsValidEmailHostChar(const TChar& charac); // Host part of the e-mail address
149 static TBool IsValidPhoneNumberChar(const TChar& charac); // Phone number
150 static TBool IsValidUrlChar( const TChar& charac); // URL
152 void ConstructL( const TDesC& aText, TInt aSearchCases, TInt aMinNumbers );
153 void PerformSearchL( const TDesC& aText, TInt aSearchCases );
155 CTulAddressStringTokenizer( const CTulAddressStringTokenizer& ); // Prohibit copy constructor
156 CTulAddressStringTokenizer& operator= ( const CTulAddressStringTokenizer& ); // Prohibit assigment operator
158 CArrayFixFlat<SFoundItem>* iFoundItems; // Array of all found items.
159 TInt iPosition; // Engine's position in the iFoundItems.
160 TInt iMinNumbers; // Minimum count of numbers in a phone number
164 #endif // __TULADDRESSSTRINGTOKENIZER_H__