40
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2008 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: Provides formatting (grouping) for plain phone numbers
|
|
15 |
*
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
#ifndef C_NUMBER_GROUPING_H
|
|
21 |
#define C_NUMBER_GROUPING_H
|
|
22 |
|
|
23 |
// #define __TEST_AS_EXE__ // put this in if you want all the test code to run and swap the mmps...
|
|
24 |
|
|
25 |
#include "NumberGroupingStd.h"
|
|
26 |
|
|
27 |
class TResourceReader;
|
|
28 |
class CRegularExpression;
|
|
29 |
class CPNGNumberGroupingExtension;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* Engine class to format plain phone numbers by inserting grouping separators.
|
|
33 |
* Both unformatted and formatted buffers are maintained by this class.
|
|
34 |
* A reversed formatted buffer is also available to assist the client in performing wrapping.
|
|
35 |
*
|
|
36 |
* @lib NumberGrouping.lib
|
|
37 |
*/
|
|
38 |
NONSHARABLE_CLASS(CPNGNumberGrouping) : public CBase
|
|
39 |
{
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Central Repository key values for KNumberGrouping key in NumberGroupingCRKeys.h
|
|
43 |
*/
|
|
44 |
public:
|
|
45 |
enum TNumberGroupingCRValues
|
|
46 |
{
|
|
47 |
/** Number grouping disabled */
|
|
48 |
ENumberGroupingDisabled = 0,
|
|
49 |
/** Number grouping enabled (USA) */
|
|
50 |
ENumberGroupingEnabled = 1
|
|
51 |
};
|
|
52 |
|
|
53 |
public:
|
|
54 |
IMPORT_C static CPNGNumberGrouping* NewL(TInt aMaxLength = 0, TBool aReversed = EFalse);
|
|
55 |
IMPORT_C static CPNGNumberGrouping* NewLC(TInt aMaxLength = 0, TBool aReversed = EFalse);
|
|
56 |
IMPORT_C ~CPNGNumberGrouping();
|
|
57 |
|
|
58 |
IMPORT_C TInt Insert(TInt aIndex, TText aChar);
|
|
59 |
IMPORT_C TInt Delete(TInt aIndex);
|
|
60 |
IMPORT_C TInt Append(TText aChar);
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Sets the new unformatted phone number.
|
|
64 |
*
|
|
65 |
* Formatting does not actually occur until an API is called that accesses in some way the formatted buffer
|
|
66 |
* or one of its characteristics
|
|
67 |
*
|
|
68 |
* @param aNumber Ungrouped phone number to be copied into the NumberGrouping engine's unformatted buffer
|
|
69 |
* @return KErrOverflow if the number is too long for the length of the unformatted buffer
|
|
70 |
*/
|
|
71 |
IMPORT_C TInt Set(const TDesC& aNumber);
|
|
72 |
|
|
73 |
/**
|
|
74 |
* @return Length of the currently formatted (grouped) buffer
|
|
75 |
*/
|
|
76 |
IMPORT_C TInt Length() const;
|
|
77 |
|
|
78 |
/**
|
|
79 |
* @return Length of the currently unformatted buffer
|
|
80 |
*/
|
|
81 |
IMPORT_C TInt UnFormattedLength() const;
|
|
82 |
|
|
83 |
/**
|
|
84 |
* This returns the maximum size of the unformatted buffer. This is the value that was provided during
|
|
85 |
* construction.
|
|
86 |
*
|
|
87 |
* Descriptors provided to Set() must be shorter than this length.
|
|
88 |
*
|
|
89 |
* @return maximum length of the unformatted buffer.
|
|
90 |
*/
|
|
91 |
IMPORT_C TInt MaxDisplayLength() const;
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Routine to determine if the character at a given position in the formatted phone number
|
|
95 |
* is a space character derived from the number grouping. That is, not part of the supplied phone number
|
|
96 |
* proper, but a space character from the number grouping.
|
|
97 |
*
|
|
98 |
* A client can check the descriptor returned by FormattedNumber() directly to perform a simple test
|
|
99 |
* of whether the character is a Space or not (whether or not derived from number grouping formatting)
|
|
100 |
*
|
|
101 |
* Note also that this returns EFalse if the character is some other formatting character besides
|
|
102 |
* space. To determine that, use IsCharacterInsertedByNumberGrouping().
|
|
103 |
*
|
|
104 |
* @param aPos The index of the character of interest
|
|
105 |
* @return EFalse iff the characer at aPos in the formatted buffer is a space coming from grouping
|
|
106 |
*/
|
|
107 |
IMPORT_C TBool IsSpace(TInt aPos) const;
|
|
108 |
|
|
109 |
/**
|
|
110 |
* Access to section of the formatted buffer.
|
|
111 |
* This routine returns a descriptor for the indicated range in the formatted (grouped) internal
|
|
112 |
* buffer. If there are spaces at either end of the indicated section of the formatted buffer, then
|
|
113 |
* the returned descriptor is adjusted to point to the trimmed buffer in order to avoid the spaces.
|
|
114 |
*
|
|
115 |
* @param aFrom Inclusive starting index
|
|
116 |
* @param aTo Inclusive end index
|
|
117 |
* @return reference to const non-modifiable descriptor for the indicated, trimmed text
|
|
118 |
*/
|
|
119 |
IMPORT_C const TDesC& FormattedNumber(TInt aFrom, TInt aTo) const;
|
|
120 |
|
|
121 |
IMPORT_C const TDesC& FormattedNumber() const;
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Access to part of the reverse formatted number. If there are spaces at either end of the indicated
|
|
125 |
* section of the formatted buffer, then the returned descriptor is adjusted to point to the trimmed
|
|
126 |
* buffer in order to avoid the spaces.
|
|
127 |
*
|
|
128 |
* Returns KNullDesC if the feature has not been enabled by passing ETrue to the
|
|
129 |
* parameter aReversed during construction
|
|
130 |
*
|
|
131 |
* @param aFrom lower (inclusive) limit of the text to look at
|
|
132 |
* @param aTo upper (inclusive) limit of the text to look at
|
|
133 |
* @return Reference to descriptor containing the selected text
|
|
134 |
*/
|
|
135 |
IMPORT_C const TDesC& ReverseFormattedNumber(TInt aFrom, TInt aTo) const;
|
|
136 |
|
|
137 |
/**
|
|
138 |
* Access to the reverse formatted number
|
|
139 |
*
|
|
140 |
* Returns KNullDesC if the feature has not been enabled by passing ETrue to the
|
|
141 |
* parameter aReversed during construction
|
|
142 |
*
|
|
143 |
* @return Reference to descriptor containing the reverse formatted text
|
|
144 |
*/
|
|
145 |
IMPORT_C const TDesC& ReverseFormattedNumber() const;
|
|
146 |
IMPORT_C const TDesC& Selection(TInt aFrom, TInt aTo) const;
|
|
147 |
|
|
148 |
IMPORT_C const TDesC& UnFormattedNumber(TInt aFrom, TInt aTo) const;
|
|
149 |
IMPORT_C const TDesC& UnFormattedNumber() const;
|
|
150 |
|
|
151 |
/**
|
|
152 |
* This method allows the client to determine if the indexed character is a number grouping supplied
|
|
153 |
* character. Specifically, this means that this character originates in the number grouping formatting
|
|
154 |
* and not from the supplied unformatted phone number.
|
|
155 |
*
|
|
156 |
* Where the number has not been grouped (e.g. because there is an invalid phone number character in the
|
|
157 |
* supplied descriptor), this method returns EFalse, even if the character pointed to may be of the nature
|
|
158 |
* of a number grouping character. Use IsChangedByGrouping() to see if the number has been changed by
|
|
159 |
* grouping at all.
|
|
160 |
*
|
|
161 |
* Where a client is interested purely in the nature of the characters rather than whether they come from
|
|
162 |
* grouping or not, he may examine the examine the text via the descriptor reference returned by
|
|
163 |
* FormattedNumber().
|
|
164 |
*
|
|
165 |
* @since Series 60 2.6
|
|
166 |
* @param aPos The index provided is for the formatted number.
|
|
167 |
* @return EFalse iff the character at the supplied index is part of the supplied phone number
|
|
168 |
*/
|
|
169 |
IMPORT_C TBool IsCharacterInsertedByNumberGrouping(TInt aPos) const;
|
|
170 |
|
|
171 |
/**
|
|
172 |
* Method to determine if the current number has been changed by number grouping.
|
|
173 |
* If this returns EFalse, then FormattedNumber() and UnFormattedNumber() refer to descriptors of with identical
|
|
174 |
* content.
|
|
175 |
* If this method returns ETrue, then the descriptors that would be returned by the two accessor APIs refer
|
|
176 |
* to descriptors with different content.
|
|
177 |
*
|
|
178 |
* @since Series 60 2.6
|
|
179 |
* @return ETrue iff formatting of the number has made an effective difference.
|
|
180 |
*/
|
|
181 |
IMPORT_C TBool IsChangedByGrouping() const;
|
|
182 |
|
|
183 |
/**
|
|
184 |
* @return return iLanguage.
|
|
185 |
*/
|
|
186 |
inline TLanguage Language() const;
|
|
187 |
|
|
188 |
|
|
189 |
public:
|
|
190 |
|
|
191 |
TLanguage iForceLanguage;
|
|
192 |
|
|
193 |
private: // private classes and enums
|
|
194 |
|
|
195 |
class TPNGSeparator
|
|
196 |
{
|
|
197 |
public:
|
|
198 |
TPNGSeparator();
|
|
199 |
TPNGSeparator( TInt aPos, TText aSeparatorCharacter );
|
|
200 |
public:
|
|
201 |
TInt iPosition;
|
|
202 |
TText iSeparatorCharacter;
|
|
203 |
};
|
|
204 |
|
|
205 |
class TPNGGroupingInfo
|
|
206 |
{
|
|
207 |
public:
|
|
208 |
TPNGGroupingInfo();
|
|
209 |
public:
|
|
210 |
TInt iMinNumberOfDigits;
|
|
211 |
TInt iMaxNumberOfDigits;
|
|
212 |
RArray<TPNGSeparator> iAfterPositions; // Positions of separators "after" the beginning
|
|
213 |
TPNGSeparator iBeforePosition; // Positions of separators "before" the end
|
|
214 |
};
|
|
215 |
|
|
216 |
// Constant for no pattern in use:
|
|
217 |
enum
|
|
218 |
{
|
|
219 |
ENoMatchedPattern = -1
|
|
220 |
};
|
|
221 |
|
|
222 |
private: // Constructors
|
|
223 |
CPNGNumberGrouping( TInt aMaxLength, TBool aReserved);
|
|
224 |
void ConstructL();
|
|
225 |
|
|
226 |
private:
|
|
227 |
TLanguage doReadLanguageFromSharedData() const;
|
|
228 |
|
|
229 |
void doReadFormatInfoFromResourceFileL();
|
|
230 |
void doClearGroupingItemsList();
|
|
231 |
void doClearFormattedNumbers();
|
|
232 |
|
|
233 |
void doNumberGroupingL() const;
|
|
234 |
void doNumberSquashing() const;
|
|
235 |
|
|
236 |
/**
|
|
237 |
* Read and process a single NUMBER_GROUPING_ITEM resource structure
|
|
238 |
*/
|
|
239 |
void ReadGroupingSchemeL(
|
|
240 |
TResourceReader& aResourceReader,
|
|
241 |
RPointerArray<TDesC>& aGroupingPatternsList,
|
|
242 |
TInt& aMaxExtraCharacters );
|
|
243 |
|
|
244 |
/**
|
|
245 |
* Read and skip a single NUMBER_GROUPING_ITEM resource structure
|
|
246 |
*/
|
|
247 |
void SkipGroupingSchemeL( TResourceReader& aResourceReader ) const;
|
|
248 |
|
|
249 |
/**
|
|
250 |
* Process the format pattern for "after positions"
|
|
251 |
*/
|
|
252 |
void ParseForAfterPositions(
|
|
253 |
const TDesC& aFormatPattern,
|
|
254 |
TPNGGroupingInfo* aGroupingInfo,
|
|
255 |
const TDesC& aWildcardedMatchingPattern,
|
|
256 |
TInt& aMaxExtraCharacters,
|
|
257 |
TBool& trailingPossible ) const;
|
|
258 |
|
|
259 |
/**
|
|
260 |
* Process the format pattern for a before positions
|
|
261 |
*/
|
|
262 |
void ParseForBeforePosition(
|
|
263 |
const TDesC& aFormatPattern,
|
|
264 |
CPNGNumberGrouping::TPNGGroupingInfo* aGroupingInfo,
|
|
265 |
TInt& aMaxExtraCharacters
|
|
266 |
) const;
|
|
267 |
|
|
268 |
/**
|
|
269 |
* This routine is used to find a wildcarded version of the matching pattern
|
|
270 |
* provided in the "initialDigits" element for a grouping scheme read from resource.
|
|
271 |
* It uses the services of the CRegularExpression class, an instance of which is constructed
|
|
272 |
* with the provided aMatchString pattern only.
|
|
273 |
*
|
|
274 |
* The client must supply a modifiable descriptor long enough to hold the wildcarded version
|
|
275 |
* of the pattern.
|
|
276 |
*
|
|
277 |
* For each character index, if there is only one possible valid character, this puts in that
|
|
278 |
* character. If there are more than one, then the supplied aWildcardChar is inserted. The
|
|
279 |
* initialDigits element uses a full stop as a numeric wildcard; this is replaced with the nominated
|
|
280 |
* wildcard.
|
|
281 |
*
|
|
282 |
* Rules: (where 'n, has been passed is used as the wildcard)
|
|
283 |
* "<a numeric digit>" -> "<a numeric digit>"
|
|
284 |
* ( e.g. "1" -> "1" )
|
|
285 |
* "+" -> "+"
|
|
286 |
* "." -> "n"
|
|
287 |
* "[0-3]" -> "n"
|
|
288 |
*
|
|
289 |
* @param aMatchString Regular expression to provide example of
|
|
290 |
* @param aWildcardChar The character to put in the example pattern if there is no single
|
|
291 |
* valid character at that point
|
|
292 |
* @param aWildcardMatchString Descriptor to write the wildcarded match pattern into
|
|
293 |
*/
|
|
294 |
void GetWildcardVersionOfMatchStringL(
|
|
295 |
const TDesC& aMatchString,
|
|
296 |
TText aWildcard,
|
|
297 |
TDes& aWildcardMatchString ) const;
|
|
298 |
|
|
299 |
/**
|
|
300 |
* This method expresses the policy of what characters may form part of a phone number
|
|
301 |
* Note that this method is valid even it there is no formatting going on. It is an intrinsic
|
|
302 |
* test on the character itself
|
|
303 |
*/
|
|
304 |
TBool IsValidPhoneNumberCharacter(TText aCharacter) const;
|
|
305 |
|
|
306 |
/**
|
|
307 |
* Examines the unformatted number, counting how many digits are found before non-digit
|
|
308 |
* characters or the end is encountered.
|
|
309 |
* Returns 0 if Set() has not been called.
|
|
310 |
*/
|
|
311 |
TInt LengthToGroup() const;
|
|
312 |
|
|
313 |
/**
|
|
314 |
* Perform number grouping using pattern at given index. Grouping is only applied to the leading
|
|
315 |
* aLengthToGroup characters.
|
|
316 |
*/
|
|
317 |
void doNumberGroupingForPatternL( TInt aMatchedPattern, TInt aLengthToGroup ) const;
|
|
318 |
|
|
319 |
private: // private data
|
|
320 |
|
|
321 |
HBufC* iUnformattedNumber;
|
|
322 |
mutable TPtrC iUnformattedNumberPtr;
|
|
323 |
|
|
324 |
mutable HBufC* iFormattedNumber;
|
|
325 |
mutable TPtrC iFormattedNumberPtr;
|
|
326 |
|
|
327 |
mutable HBufC* iReverseFormattedNumber;
|
|
328 |
mutable TPtrC iReverseFormattedNumberPtr;
|
|
329 |
|
|
330 |
mutable TPtrC iSelectionPtr;
|
|
331 |
|
|
332 |
mutable TLanguage iLanguage; // the system language
|
|
333 |
TInt iMaxUnformattedLength;
|
|
334 |
TBool iReversed;
|
|
335 |
|
|
336 |
CRegularExpression* iRegExp; // the patterns for matching
|
|
337 |
RPointerArray<TPNGGroupingInfo> iGroupingItemsList; // the formatting info
|
|
338 |
|
|
339 |
mutable TInt iMatchedPatternIndex; // keep track of what pattern is matched
|
|
340 |
CPNGNumberGroupingExtension* iExtension;
|
|
341 |
};
|
|
342 |
|
|
343 |
inline TLanguage CPNGNumberGrouping::Language() const
|
|
344 |
{
|
|
345 |
return iLanguage;
|
|
346 |
}
|
|
347 |
|
|
348 |
|
|
349 |
#endif // C_NUMBER_GROUPING_H
|
|
350 |
|
|
351 |
// End of File
|