|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-CE7C84A5-D2E6-5151-BBC7-6AF9C8A0D978" xml:lang="en"><title>Address |
|
13 string tokenizer overview</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <section id="GUID-3380A468-D7C1-478B-81F7-C7B25CA2AF87"><title>Purpose</title> <p>The |
|
15 Address String Tokenizer offers methods for parsing phone numbers, email addresses, |
|
16 URL and URI addresses from given text. It provides an interface for applications |
|
17 that, for example, want to create/use their own GUI for displaying found items. </p> </section> |
|
18 <section id="GUID-0A0412D0-A818-42C3-8288-D857FF3FB9AC"><title>Architectural |
|
19 Relationships</title> <p>All functionality is implemented in the <xref href="GUID-D35F2DD5-09A3-366C-8384-46FEB6B7DB18.dita"><apiname>CTulAddressStringTokenizer</apiname></xref> class. |
|
20 The interface can be accessed through the <codeph>tuladdressstringtokenizer.h </codeph> file. |
|
21 The binaries are linked to the <codeph>etul.lib</codeph> (Text Utilities - |
|
22 part of Egul component) library. </p> <fig id="GUID-831D95A9-EDD6-5351-83CD-F9246B88E821"> |
|
23 <title> Subsystem dependencies </title> |
|
24 <image href="GUID-2BF99BD2-5DB5-5DF6-8F82-22DD2E818584_d0e16066_href.png" placement="inline"/> |
|
25 </fig> </section> |
|
26 <section id="GUID-B712EDB6-0AAD-4E3F-9694-5EABECD3AA1D"><title>Description</title> <p><b>Usage</b> </p> <p>In |
|
27 order to use the Address String Tokenizer, the user has to create an instance |
|
28 of <xref href="GUID-D35F2DD5-09A3-366C-8384-46FEB6B7DB18.dita"><apiname>CTulAddressStringTokenizer</apiname></xref> by |
|
29 using the factory method <xref href="GUID-D35F2DD5-09A3-366C-8384-46FEB6B7DB18.dita"><apiname>CTulAddressStringTokenizer::NewL()</apiname></xref>. </p> <p>For |
|
30 example: </p> <codeblock id="GUID-59957EA3-0C1D-5A35-87A0-8DCB0D01D840" xml:space="preserve">CTulAddressStringTokenizer* addressStringTokenizer = CTulAddressStringTokenizer::NewL(text, searchCase);</codeblock> <p>The method takes two parameters of type <codeph>TDesC&</codeph> and <xref href="GUID-D35F2DD5-09A3-366C-8384-46FEB6B7DB18.dita"><apiname>TTokenizerSearchCase</apiname></xref> which is |
|
31 defined in <codeph>tuladdressstringtokenizer.h</codeph>. </p> <p>The first |
|
32 parameter defines the text to be searched from. </p> <p>The second parameter |
|
33 tells what exactly is being looked for. It is an enum which describes the |
|
34 type of text being searched for. The types available are phone number, email |
|
35 address, fixed start URL or generic URI. </p> <p>The passed text is parsed |
|
36 in construction, and found items can be fetched using the <xref href="GUID-D35F2DD5-09A3-366C-8384-46FEB6B7DB18.dita"><apiname>ItemArray()</apiname></xref> method. <xref href="GUID-D35F2DD5-09A3-366C-8384-46FEB6B7DB18.dita"><apiname>ItemArray()</apiname></xref> returns a constant |
|
37 array containing all the found items. </p> <p>The interface also offers helper |
|
38 functions for handling the item array by itself. </p> <p>For more information |
|
39 on individual methods, please see the reference API for <xref href="GUID-D35F2DD5-09A3-366C-8384-46FEB6B7DB18.dita"><apiname>CTulAddressStringTokenizer</apiname></xref>. </p> <p><b>Example</b> </p> <p>This sample code explains a few simple use cases that |
|
40 search for items from a text string: </p> <codeblock id="GUID-2B5E70DF-6757-5803-B7BA-052EA4932EEF" xml:space="preserve">// Some text |
|
41 TBufC<256> strSomeText(_L("Mail to me@someplace.com or call 040 1234567. |
|
42 You can also tune in to audio feed at rtsp://someplace.com/somefeed.ra.")); |
|
43 |
|
44 // SFoundItem instance |
|
45 CTulAddressStringTokenizer::SFoundItem item; |
|
46 |
|
47 // Create an instance of CTulAddressStringTokenizer and search for URLs. |
|
48 CTulAddressStringTokenizer* singleSearch = CTulAddressStringTokenizer::NewL |
|
49 (strSomeText, CTulAddressStringTokenizer::EFindItemSearchScheme); |
|
50 |
|
51 // Get count of found items |
|
52 TInt count(singleSearch->ItemCount()); |
|
53 |
|
54 // Get currently selected item (rtsp://someplace.com/somefeed.ra) to the result |
|
55 // variable |
|
56 singleSearch->Item(item); |
|
57 TPtrC16 result(strSomeText.Mid(item.iStartPos, item.iLength)); |
|
58 |
|
59 // Deallocate memory |
|
60 delete singleSearch; |
|
61 |
|
62 // Look for all possible things (cases work as binary mask) |
|
63 CTulAddressStringTokenizer* multiSearch = CTulAddressStringTokenizer::NewL |
|
64 (strSomeText, (CTulAddressStringTokenizer:: TTokenizerSearchCase) |
|
65 (CTulAddressStringTokenizer::EFindItemSearchPhoneNumberBin | |
|
66 CTulAddressStringTokenizer::EFindItemSearchURLBin | |
|
67 CTulAddressStringTokenizer::EFindItemSearchMailAddressBin | |
|
68 CTulAddressStringTokenizer::EFindItemSearchScheme)); |
|
69 |
|
70 // Debug print all items and their type |
|
71 count = multiSearch->ItemCount(); |
|
72 multiSearch->Item(item); |
|
73 |
|
74 for(TInt i=0; i<count; i++) |
|
75 { |
|
76 result.Set(strSomeText.Mid(item.iStartPos, item.iLength)); |
|
77 RDebug::Print(_L("Found type %d item:"), item.iItemType); |
|
78 RDebug::Print(_L("%S"), &result) |
|
79 multiSearch->NextItem(item); |
|
80 } |
|
81 |
|
82 // Deallocate memory |
|
83 delete multiSearch; |
|
84 </codeblock> <p><b>Sequence Diagram</b> </p> <fig id="GUID-8BF3A74A-9E14-57C4-A0E5-105A0230BFA1"> |
|
85 <title> Sequence of events for CTulAddressStringTokenizer</title> |
|
86 <image href="GUID-F27A92CB-1C02-562B-A93D-57675C53BFEB_d0e16157_href.png" placement="inline"/> |
|
87 </fig> </section> |
|
88 </conbody></concept> |