|
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: A class for converting characters and checking if the data is |
|
15 * too long. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CPSU2CHARCONV_H |
|
21 #define CPSU2CHARCONV_H |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 #include <charconv.h> |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 class RFs; |
|
30 class CCnvCharacterSetConverter; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 class CPsu2CharConv : public CBase |
|
34 { |
|
35 public: |
|
36 |
|
37 /** |
|
38 * Two-phased constructor. |
|
39 * |
|
40 * @param aFs an open file system session |
|
41 * @param aCharacterSet The character set to use. See charconv.h. |
|
42 * @return a new instance of this class |
|
43 */ |
|
44 static CPsu2CharConv* NewL( RFs& aFs, const TUint aChacterSet ); |
|
45 |
|
46 /** |
|
47 * Two-phased constructor. |
|
48 * |
|
49 * @param aFs an open file system session |
|
50 * @param aCharacterSet The character set to use. See charconv.h. |
|
51 * @return a new instance of this class |
|
52 */ |
|
53 static CPsu2CharConv* NewLC( RFs& aFs, const TUint aChacterSet ); |
|
54 |
|
55 /** |
|
56 * Destructor. |
|
57 */ |
|
58 ~CPsu2CharConv(); |
|
59 |
|
60 public: // Data structures |
|
61 |
|
62 /// Used for indicating contact field validity |
|
63 /// from (U)SIM store point of view |
|
64 enum TPsu2FieldValidity |
|
65 { |
|
66 /// It's OK to add the field to the entry |
|
67 EOk, |
|
68 /// The data is too long for this field type |
|
69 ETooLong |
|
70 }; |
|
71 |
|
72 public: // Interface |
|
73 |
|
74 void SetDownGradeLf( CCnvCharacterSetConverter:: |
|
75 TDowngradeForExoticLineTerminatingCharacters aDowngrade ); |
|
76 |
|
77 /** |
|
78 * Checks contact field validity. |
|
79 * |
|
80 * @param aData The data to be saved to the field. |
|
81 * @param aMaxLength Maximum length of the field. |
|
82 * @param aValidity Contains the validity value afterwards. |
|
83 * @return A pointer to the given data. The length depends |
|
84 * on aValidity. If ETooLong, the pointer points to |
|
85 * the aData but the length is cut. Can be used to add |
|
86 * the data to the entry without problems. In other cases |
|
87 * the pointer points to the given aData and |
|
88 * the length is same. |
|
89 */ |
|
90 TPtrC CheckFieldValidityL( |
|
91 const TDesC& aData, |
|
92 TInt aMaxLength, |
|
93 TPsu2FieldValidity& aValidity ); |
|
94 |
|
95 /** |
|
96 * Checks unicode descriptor data length with the current character set |
|
97 * so that conversion from unicode to 8-bit descriptor will not exceed |
|
98 * the given maximum length. Returns either the given descriptor or a |
|
99 * truncated descriptor that can be converted to an 8-bit descriptor |
|
100 * with the given maximum length. |
|
101 * |
|
102 * @param aData The data to be saved to the field. |
|
103 * @param aMaxLength Maximum allowed length of the field for the |
|
104 * converted data. |
|
105 * @param aUnconvertedCount On return, contains the count of |
|
106 * characters that could not be converted. |
|
107 * @return A pointer to the given data. The pointer points to the |
|
108 * aData but the length is truncated to the length that allows |
|
109 * making the conversion so that the result length does not |
|
110 * exceed aMaxLength that was given as a parameter. |
|
111 */ |
|
112 TPtrC CheckFieldLengthL( |
|
113 const TDesC& aData, |
|
114 TInt aMaxLength, |
|
115 TInt& aUnconvertedCount ); |
|
116 |
|
117 /** |
|
118 * To check if the text includes unicode characters. |
|
119 * @param aText The text to be checked. |
|
120 * @return ETrue if the text included unicode characters. |
|
121 * EFalse otherwise. |
|
122 */ |
|
123 TBool IsUnicodeL( const TDesC& aText ); |
|
124 |
|
125 private: // Construction |
|
126 |
|
127 /** |
|
128 * Constructor. |
|
129 */ |
|
130 CPsu2CharConv( RFs& aFs, const TUint aChacterSet ); |
|
131 |
|
132 /** |
|
133 * By default Symbian 2nd phase constructor is private. |
|
134 */ |
|
135 void ConstructL(); |
|
136 |
|
137 /** |
|
138 * Checks some special cases to need if extra space needs to be |
|
139 * reserved for the data when saving to (U)SIM. |
|
140 * @param aData The data to be saved to (U)SIM. |
|
141 * @param aConvertedLength The length of the conversion. The function |
|
142 * increases this if any extra space needs to be reserved. |
|
143 */ |
|
144 void ReviseLength( |
|
145 const TDesC& aData, TInt& aConvertedLength ); |
|
146 |
|
147 private: // Data |
|
148 /// A file system session for characted converter |
|
149 RFs iFs; |
|
150 /// Own: Symbian's character converter |
|
151 CCnvCharacterSetConverter* iConverter; |
|
152 /// Character set identier as given to the constructors |
|
153 TUint iCharacterSetIdentifier; |
|
154 }; |
|
155 |
|
156 #endif // CPSU2CHARCONV_H |
|
157 |
|
158 // End of File |