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