|
1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Utility class for splitting find string into separate words |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "CPbk2FindStringSplitter.h" |
|
21 #include <MPbk2ContactNameFormatter.h> |
|
22 #include <badesca.h> |
|
23 |
|
24 |
|
25 //---------------------------------------------------------------------------- |
|
26 // CPbk2FindStringSplitter::CPbk2FindStringSplitter |
|
27 //---------------------------------------------------------------------------- |
|
28 // |
|
29 inline CPbk2FindStringSplitter::CPbk2FindStringSplitter( |
|
30 MPbk2ContactNameFormatter& aNameFormatter ): |
|
31 iNameFormatter( aNameFormatter ) |
|
32 { |
|
33 } |
|
34 |
|
35 |
|
36 //---------------------------------------------------------------------------- |
|
37 // CPbk2FindStringSplitter::~CPbk2FindStringSplitter |
|
38 //---------------------------------------------------------------------------- |
|
39 // |
|
40 CPbk2FindStringSplitter::~CPbk2FindStringSplitter() |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 //---------------------------------------------------------------------------- |
|
46 // CPbk2FindStringSplitter::NewL |
|
47 //---------------------------------------------------------------------------- |
|
48 // |
|
49 CPbk2FindStringSplitter* CPbk2FindStringSplitter::NewL( |
|
50 MPbk2ContactNameFormatter& aNameFormatter ) |
|
51 { |
|
52 CPbk2FindStringSplitter* self = new ( ELeave ) CPbk2FindStringSplitter( |
|
53 aNameFormatter ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 //---------------------------------------------------------------------------- |
|
62 // CPbk2FindStringSplitter::ConstructL |
|
63 //---------------------------------------------------------------------------- |
|
64 // |
|
65 void CPbk2FindStringSplitter::ConstructL() |
|
66 { |
|
67 } |
|
68 |
|
69 //---------------------------------------------------------------------------- |
|
70 // CPbk2FindStringSplitter::SplitTextIntoArrayL |
|
71 //---------------------------------------------------------------------------- |
|
72 // |
|
73 MDesCArray* CPbk2FindStringSplitter::SplitTextIntoArrayL( const TDesC& aText ) |
|
74 { |
|
75 const TInt KGranularity = 2; |
|
76 CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( KGranularity ); |
|
77 const TInt textLength = aText.Length(); |
|
78 for ( TInt beg = 0; beg < textLength; ++beg ) |
|
79 { |
|
80 // Skip separators before next word |
|
81 if ( !iNameFormatter.IsFindSeparatorChar( aText[beg] ) ) |
|
82 { |
|
83 // Scan the end of the word |
|
84 TInt end = beg; |
|
85 for (; end < textLength && |
|
86 !iNameFormatter.IsFindSeparatorChar( aText[end] ); |
|
87 ++end ) |
|
88 { |
|
89 } |
|
90 const TInt len = end - beg; |
|
91 // Append found word to the array |
|
92 array->AppendL( aText.Mid( beg,len ) ); |
|
93 // Scan for next word |
|
94 beg = end; |
|
95 } |
|
96 } |
|
97 return array; |
|
98 } |