|
1 /* |
|
2 * Copyright (c) 2005-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: Virtual phonebook engine utils |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "VPbkEngUtils.h" |
|
20 |
|
21 namespace VPbkEngUtils { |
|
22 |
|
23 // FUNCTIONS |
|
24 |
|
25 void ExpandL(HBufC*& aBuffer, TInt aLength) |
|
26 { |
|
27 if (!aBuffer) |
|
28 { |
|
29 aBuffer = HBufC::NewL(aLength); |
|
30 } |
|
31 TPtr bufPtr(aBuffer->Des()); |
|
32 const TInt maxLength = bufPtr.MaxLength(); |
|
33 if (maxLength < aLength) |
|
34 { |
|
35 aBuffer = aBuffer->ReAllocL(Max(2*maxLength, aLength)); |
|
36 } |
|
37 } |
|
38 |
|
39 const TDesC& ReverseL(HBufC*& aBuffer, const TDesC& aText) |
|
40 { |
|
41 const TInt length = aText.Length(); |
|
42 ExpandL(aBuffer, length); |
|
43 TPtr bufPtr(aBuffer->Des()); |
|
44 bufPtr.Zero(); |
|
45 for (TInt i = length-1; i >= 0; --i) |
|
46 { |
|
47 bufPtr.Append(aText[i]); |
|
48 } |
|
49 return *aBuffer; |
|
50 } |
|
51 |
|
52 /** |
|
53 * Counts and returns the number of decimal digit characters in aText. |
|
54 */ |
|
55 TInt CountDigits(const TDesC& aText) |
|
56 { |
|
57 TInt result = 0; |
|
58 const TInt length = aText.Length(); |
|
59 for (TInt textPos = 0; textPos < length; ++textPos) |
|
60 { |
|
61 const TInt numVal = TChar(aText[textPos]).GetNumericValue(); |
|
62 if (numVal >= 0 && numVal <= 9) |
|
63 { |
|
64 ++result; |
|
65 } |
|
66 } |
|
67 return result; |
|
68 } |
|
69 |
|
70 } // namespace VPbkEngUtils |
|
71 |