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