epoc32/include/convutils.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
/*
williamr@4
     2
* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@4
     3
* All rights reserved.
williamr@4
     4
* This component and the accompanying materials are made available
williamr@4
     5
* under the terms of "Eclipse Public License v1.0"
williamr@4
     6
* which accompanies this distribution, and is available
williamr@4
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@4
     8
*
williamr@4
     9
* Initial Contributors:
williamr@4
    10
* Nokia Corporation - initial contribution.
williamr@4
    11
*
williamr@4
    12
* Contributors:
williamr@4
    13
*
williamr@4
    14
* Description: 
williamr@4
    15
*
williamr@4
    16
*/
williamr@4
    17
williamr@2
    18
williamr@2
    19
#if !defined(__CONVUTILS_H__)
williamr@2
    20
#define __CONVUTILS_H__
williamr@2
    21
williamr@2
    22
#if !defined(__E32STD_H__)
williamr@2
    23
#include <e32std.h>
williamr@2
    24
#endif
williamr@2
    25
williamr@2
    26
#if !defined(__E32BASE_H__)
williamr@2
    27
#include <e32base.h>
williamr@2
    28
#endif
williamr@2
    29
williamr@2
    30
#if !defined(__CHARCONV_H__)
williamr@2
    31
#include <charconv.h>
williamr@2
    32
#endif
williamr@2
    33
williamr@2
    34
struct SCnvConversionData;
williamr@2
    35
williamr@2
    36
 
williamr@2
    37
class CnvUtilities
williamr@2
    38
/** 
williamr@2
    39
Provides static character conversion utilities for complex encodings. Its functions 
williamr@2
    40
may be called from a plug-in DLL's implementation of ConvertFromUnicode() 
williamr@2
    41
and ConvertToUnicode().
williamr@2
    42
williamr@2
    43
These utility functions are provided for use when converting to/from complex 
williamr@2
    44
character set encodings, including modal encodings. Modal encodings are those 
williamr@2
    45
where the interpretation of a given byte of data is dependent on the current 
williamr@2
    46
mode; mode changing is performed by escape sequences which occur in the byte 
williamr@2
    47
stream. A non-modal complex encoding is one in which characters are encoded 
williamr@2
    48
using variable numbers of bytes. The number of bytes used to encode a character 
williamr@2
    49
depends on the value of the initial byte.
williamr@2
    50
@publishedAll 
williamr@2
    51
@released
williamr@2
    52
*/
williamr@2
    53
	{
williamr@2
    54
public:
williamr@2
    55
	// type definitions for converting from Unicode
williamr@2
    56
	
williamr@2
    57
	/**  A pointer to a function which "mangles" text when converting from
williamr@2
    58
	Unicode into a complex modal or non-modal foreign character set
williamr@2
    59
	encoding.
williamr@2
    60
williamr@2
    61
	It might insert a shifting character, escape sequence, or other
williamr@2
    62
	special characters.If the target character set encoding is modal, the
williamr@2
    63
	implementation of this function may call the
williamr@2
    64
	CnvUtilities::ConvertFromIntermediateBufferInPlace()
williamr@2
    65
	utility function which is provided because many modal character sets
williamr@2
    66
	require an identical implementation of this function.
williamr@2
    67
williamr@2
    68
	" convutils.lib " */
williamr@2
    69
    typedef void (*FConvertFromIntermediateBufferInPlace)(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut);
williamr@2
    70
	struct SCharacterSet
williamr@2
    71
	/** Stores information about a non-Unicode character set. The information 
williamr@2
    72
	is used to locate the conversion information required by 
williamr@2
    73
	ConvertFromUnicode() and ConvertToUnicode().
williamr@2
    74
williamr@2
    75
	An array of these structs  that contains all available character sets  
williamr@2
    76
	can be generated by CreateArrayOfCharacterSetsAvailableLC() and 
williamr@2
    77
	CreateArrayOfCharacterSetsAvailableL(), and is used by one of the 
williamr@2
    78
	overloads of PrepareToConvertToOrFromL(). */
williamr@2
    79
		{
williamr@2
    80
		/** The conversion data. */
williamr@2
    81
		const SCnvConversionData* iConversionData; // must *not* be set to NULL
williamr@2
    82
		/** A pointer to a function which "mangles" the text in a way 
williamr@2
    83
		appropriate to the target complex character set. For instance it 
williamr@2
    84
		might insert a shifting character, escape sequence, or other special 
williamr@2
    85
		characters. */
williamr@2
    86
		FConvertFromIntermediateBufferInPlace iConvertFromIntermediateBufferInPlace; // must *not* be set to NULL
williamr@2
    87
		/** The escape sequence which introduces the character set, i.e. it 
williamr@2
    88
		identifies this character set as the next one to use. Must not be NULL.
williamr@2
    89
		If the character set is non-modal, this should be set to an empty 
williamr@2
    90
		descriptor. */
williamr@2
    91
		const TDesC8* iEscapeSequence; // must *not* be set to NULL
williamr@2
    92
		};
williamr@2
    93
	// type definitions for converting to Unicode
williamr@2
    94
williamr@2
    95
	/** A pointer to a function which calculates the number of consecutive
williamr@2
    96
	bytes in the remainder of the foreign descriptor which can be
williamr@2
    97
	converted using the current character set's conversion data.
williamr@2
    98
williamr@2
    99
	Called when converting from a non-modal complex character set encoding
williamr@2
   100
	into Unicode. It may return a negative
williamr@2
   101
	CCnvCharacterSetConverter::TError value to indicate an
williamr@2
   102
	error in the encoding.
williamr@2
   103
williamr@2
   104
	" convutils.lib " */
williamr@2
   105
	typedef TInt (*FNumberOfBytesAbleToConvert)(const TDesC8& aDescriptor); // may return negative CCnvCharacterSetConverter::TError values
williamr@2
   106
	
williamr@2
   107
	/** A pointer to a function which prepares the text for conversion into
williamr@2
   108
	Unicode.
williamr@2
   109
williamr@2
   110
	For instance it might remove any shifting or other special characters.
williamr@2
   111
	Called when converting from a non-modal complex character set encoding
williamr@2
   112
	into Unicode.
williamr@2
   113
williamr@2
   114
	" convutils.lib " */
williamr@2
   115
 	typedef void (*FConvertToIntermediateBufferInPlace)(TDes8& aDescriptor);
williamr@2
   116
williamr@2
   117
	struct SState
williamr@2
   118
	/** Character conversion data for one of the character sets which is 
williamr@2
   119
	specified in a modal character set encoding. An array of these structs 
williamr@2
   120
	is used when converting from a modal character set into Unicode, using 
williamr@2
   121
	CnvUtilities::ConvertToUnicodeFromModalForeign(). Neither of the members 
williamr@2
   122
	may be NULL. */
williamr@2
   123
		{
williamr@2
   124
		/** The escape sequence which introduces the character set, i.e. it 
williamr@2
   125
		identifies this character set as the next one to use. This must begin 
williamr@2
   126
		with KControlCharacterEscape. */
williamr@2
   127
		const TDesC8* iEscapeSequence; // must *not* be set to NULL and must begin with 0x1b
williamr@2
   128
		/** The conversion data. */
williamr@2
   129
		const SCnvConversionData* iConversionData; // must *not* be set to NULL
williamr@2
   130
		};
williamr@2
   131
	struct SMethod
williamr@2
   132
		{
williamr@2
   133
		/** A pointer to a function which calculates the number of consecutive 
williamr@2
   134
		bytes in the remainder of the foreign descriptor which can be converted 
williamr@2
   135
		using the current character set's conversion data. It may return a 
williamr@2
   136
		negative CCnvCharacterSetConverter::TError value to indicate an error 
williamr@2
   137
		in the encoding. */
williamr@2
   138
		FNumberOfBytesAbleToConvert iNumberOfBytesAbleToConvert; // must *not* be set to NULL
williamr@2
   139
		/** A pointer to a function which prepares the text for conversion 
williamr@2
   140
		into Unicode. For instance it might remove any shifting or other 
williamr@2
   141
		special characters. */
williamr@2
   142
		FConvertToIntermediateBufferInPlace iConvertToIntermediateBufferInPlace; // must *not* be set to NULL
williamr@2
   143
		/** The conversion data. */
williamr@2
   144
		const SCnvConversionData* iConversionData; // must *not* be set to NULL
williamr@2
   145
		/** The number of bytes per character. */
williamr@2
   146
		TInt16 iNumberOfBytesPerCharacter;
williamr@2
   147
		/** The number of core bytes per character. */
williamr@2
   148
		TInt16 iNumberOfCoreBytesPerCharacter;
williamr@2
   149
		};
williamr@2
   150
public:
williamr@2
   151
	// these functions may *not* have CCnvCharacterSetConverter::EInputConversionFlagStopAtFirstUnconvertibleCharacter set in aInputConversionFlags
williamr@2
   152
	IMPORT_C static TInt ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters, const TArray<SCharacterSet>& aArrayOfCharacterSets);
williamr@2
   153
	IMPORT_C static TInt ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters, const TArray<SCharacterSet>& aArrayOfCharacterSets, TUint& aOutputConversionFlags, TUint aInputConversionFlags);
williamr@2
   154
	IMPORT_C static void ConvertFromIntermediateBufferInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut, const TDesC8& aEscapeSequence, TInt aNumberOfBytesPerCharacter);
williamr@2
   155
	IMPORT_C static TInt ConvertToUnicodeFromModalForeign(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aState, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<SState>& aArrayOfStates); // the first element of aArrayOfStates is taken to be the default state
williamr@2
   156
	IMPORT_C static TInt ConvertToUnicodeFromModalForeign(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aState, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<SState>& aArrayOfStates, TUint& aOutputConversionFlags, TUint aInputConversionFlags); // the first element of aArrayOfStates is taken to be the default state
williamr@2
   157
	IMPORT_C static TInt ConvertToUnicodeFromHeterogeneousForeign(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<SMethod>& aArrayOfMethods);
williamr@2
   158
	IMPORT_C static TInt ConvertToUnicodeFromHeterogeneousForeign(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<SMethod>& aArrayOfMethods, TUint& aOutputConversionFlags, TUint aInputConversionFlags);
williamr@2
   159
private:
williamr@2
   160
	static void CheckArrayOfCharacterSets(const TArray<SCharacterSet>& aArrayOfCharacterSets);
williamr@2
   161
	static void CheckArrayOfStates(const TArray<SState>& aArrayOfStates);
williamr@2
   162
	static void CheckArrayOfMethods(const TArray<SMethod>& aArrayOfMethods);
williamr@2
   163
	static TInt LengthOfUnicodeCharacter(const TDesC16& aUnicode, TInt aIndex);
williamr@2
   164
	static TBool NextHomogeneousForeignRun(const SCnvConversionData*& aConversionData, TInt& aNumberOfForeignBytesConsumed, TPtrC8& aHomogeneousRun, TPtrC8& aRemainderOfForeign, const TArray<SState>& aArrayOfStates, TUint& aOutputConversionFlags);
williamr@2
   165
	static TBool MatchesEscapeSequence(TInt& aNumberOfForeignBytesConsumed, TPtrC8& aHomogeneousRun, TPtrC8& aRemainderOfForeign, const TDesC8& aEscapeSequence);
williamr@2
   166
	static TBool IsStartOf(const TDesC8& aStart, const TDesC8& aPotentiallyLongerDescriptor);
williamr@2
   167
	inline static TInt ReduceToNearestMultipleOf(TInt aNumber1, TInt aNumber2) {return (aNumber1/aNumber2)*aNumber2;}
williamr@2
   168
	};
williamr@2
   169
williamr@2
   170
#endif
williamr@4
   171