1.1 --- a/epoc32/include/convutils.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/convutils.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,167 @@
1.4 -convutils.h
1.5 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +//
1.19 +
1.20 +#if !defined(__CONVUTILS_H__)
1.21 +#define __CONVUTILS_H__
1.22 +
1.23 +#if !defined(__E32STD_H__)
1.24 +#include <e32std.h>
1.25 +#endif
1.26 +
1.27 +#if !defined(__E32BASE_H__)
1.28 +#include <e32base.h>
1.29 +#endif
1.30 +
1.31 +#if !defined(__CHARCONV_H__)
1.32 +#include <charconv.h>
1.33 +#endif
1.34 +
1.35 +struct SCnvConversionData;
1.36 +
1.37 +
1.38 +class CnvUtilities
1.39 +/**
1.40 +Provides static character conversion utilities for complex encodings. Its functions
1.41 +may be called from a plug-in DLL's implementation of ConvertFromUnicode()
1.42 +and ConvertToUnicode().
1.43 +
1.44 +These utility functions are provided for use when converting to/from complex
1.45 +character set encodings, including modal encodings. Modal encodings are those
1.46 +where the interpretation of a given byte of data is dependent on the current
1.47 +mode; mode changing is performed by escape sequences which occur in the byte
1.48 +stream. A non-modal complex encoding is one in which characters are encoded
1.49 +using variable numbers of bytes. The number of bytes used to encode a character
1.50 +depends on the value of the initial byte.
1.51 +@publishedAll
1.52 +@released
1.53 +*/
1.54 + {
1.55 +public:
1.56 + // type definitions for converting from Unicode
1.57 +
1.58 + /** A pointer to a function which "mangles" text when converting from
1.59 + Unicode into a complex modal or non-modal foreign character set
1.60 + encoding.
1.61 +
1.62 + It might insert a shifting character, escape sequence, or other
1.63 + special characters.If the target character set encoding is modal, the
1.64 + implementation of this function may call the
1.65 + CnvUtilities::ConvertFromIntermediateBufferInPlace()
1.66 + utility function which is provided because many modal character sets
1.67 + require an identical implementation of this function.
1.68 +
1.69 + " convutils.lib " */
1.70 + typedef void (*FConvertFromIntermediateBufferInPlace)(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut);
1.71 + struct SCharacterSet
1.72 + /** Stores information about a non-Unicode character set. The information
1.73 + is used to locate the conversion information required by
1.74 + ConvertFromUnicode() and ConvertToUnicode().
1.75 +
1.76 + An array of these structs that contains all available character sets
1.77 + can be generated by CreateArrayOfCharacterSetsAvailableLC() and
1.78 + CreateArrayOfCharacterSetsAvailableL(), and is used by one of the
1.79 + overloads of PrepareToConvertToOrFromL(). */
1.80 + {
1.81 + /** The conversion data. */
1.82 + const SCnvConversionData* iConversionData; // must *not* be set to NULL
1.83 + /** A pointer to a function which "mangles" the text in a way
1.84 + appropriate to the target complex character set. For instance it
1.85 + might insert a shifting character, escape sequence, or other special
1.86 + characters. */
1.87 + FConvertFromIntermediateBufferInPlace iConvertFromIntermediateBufferInPlace; // must *not* be set to NULL
1.88 + /** The escape sequence which introduces the character set, i.e. it
1.89 + identifies this character set as the next one to use. Must not be NULL.
1.90 + If the character set is non-modal, this should be set to an empty
1.91 + descriptor. */
1.92 + const TDesC8* iEscapeSequence; // must *not* be set to NULL
1.93 + };
1.94 + // type definitions for converting to Unicode
1.95 +
1.96 + /** A pointer to a function which calculates the number of consecutive
1.97 + bytes in the remainder of the foreign descriptor which can be
1.98 + converted using the current character set's conversion data.
1.99 +
1.100 + Called when converting from a non-modal complex character set encoding
1.101 + into Unicode. It may return a negative
1.102 + CCnvCharacterSetConverter::TError value to indicate an
1.103 + error in the encoding.
1.104 +
1.105 + " convutils.lib " */
1.106 + typedef TInt (*FNumberOfBytesAbleToConvert)(const TDesC8& aDescriptor); // may return negative CCnvCharacterSetConverter::TError values
1.107 +
1.108 + /** A pointer to a function which prepares the text for conversion into
1.109 + Unicode.
1.110 +
1.111 + For instance it might remove any shifting or other special characters.
1.112 + Called when converting from a non-modal complex character set encoding
1.113 + into Unicode.
1.114 +
1.115 + " convutils.lib " */
1.116 + typedef void (*FConvertToIntermediateBufferInPlace)(TDes8& aDescriptor);
1.117 +
1.118 + struct SState
1.119 + /** Character conversion data for one of the character sets which is
1.120 + specified in a modal character set encoding. An array of these structs
1.121 + is used when converting from a modal character set into Unicode, using
1.122 + CnvUtilities::ConvertToUnicodeFromModalForeign(). Neither of the members
1.123 + may be NULL. */
1.124 + {
1.125 + /** The escape sequence which introduces the character set, i.e. it
1.126 + identifies this character set as the next one to use. This must begin
1.127 + with KControlCharacterEscape. */
1.128 + const TDesC8* iEscapeSequence; // must *not* be set to NULL and must begin with 0x1b
1.129 + /** The conversion data. */
1.130 + const SCnvConversionData* iConversionData; // must *not* be set to NULL
1.131 + };
1.132 + struct SMethod
1.133 + {
1.134 + /** A pointer to a function which calculates the number of consecutive
1.135 + bytes in the remainder of the foreign descriptor which can be converted
1.136 + using the current character set's conversion data. It may return a
1.137 + negative CCnvCharacterSetConverter::TError value to indicate an error
1.138 + in the encoding. */
1.139 + FNumberOfBytesAbleToConvert iNumberOfBytesAbleToConvert; // must *not* be set to NULL
1.140 + /** A pointer to a function which prepares the text for conversion
1.141 + into Unicode. For instance it might remove any shifting or other
1.142 + special characters. */
1.143 + FConvertToIntermediateBufferInPlace iConvertToIntermediateBufferInPlace; // must *not* be set to NULL
1.144 + /** The conversion data. */
1.145 + const SCnvConversionData* iConversionData; // must *not* be set to NULL
1.146 + /** The number of bytes per character. */
1.147 + TInt16 iNumberOfBytesPerCharacter;
1.148 + /** The number of core bytes per character. */
1.149 + TInt16 iNumberOfCoreBytesPerCharacter;
1.150 + };
1.151 +public:
1.152 + // these functions may *not* have CCnvCharacterSetConverter::EInputConversionFlagStopAtFirstUnconvertibleCharacter set in aInputConversionFlags
1.153 + IMPORT_C static TInt ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters, const TArray<SCharacterSet>& aArrayOfCharacterSets);
1.154 + 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);
1.155 + IMPORT_C static void ConvertFromIntermediateBufferInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut, const TDesC8& aEscapeSequence, TInt aNumberOfBytesPerCharacter);
1.156 + 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
1.157 + 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
1.158 + IMPORT_C static TInt ConvertToUnicodeFromHeterogeneousForeign(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<SMethod>& aArrayOfMethods);
1.159 + 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);
1.160 +private:
1.161 + static void CheckArrayOfCharacterSets(const TArray<SCharacterSet>& aArrayOfCharacterSets);
1.162 + static void CheckArrayOfStates(const TArray<SState>& aArrayOfStates);
1.163 + static void CheckArrayOfMethods(const TArray<SMethod>& aArrayOfMethods);
1.164 + static TInt LengthOfUnicodeCharacter(const TDesC16& aUnicode, TInt aIndex);
1.165 + static TBool NextHomogeneousForeignRun(const SCnvConversionData*& aConversionData, TInt& aNumberOfForeignBytesConsumed, TPtrC8& aHomogeneousRun, TPtrC8& aRemainderOfForeign, const TArray<SState>& aArrayOfStates, TUint& aOutputConversionFlags);
1.166 + static TBool MatchesEscapeSequence(TInt& aNumberOfForeignBytesConsumed, TPtrC8& aHomogeneousRun, TPtrC8& aRemainderOfForeign, const TDesC8& aEscapeSequence);
1.167 + static TBool IsStartOf(const TDesC8& aStart, const TDesC8& aPotentiallyLongerDescriptor);
1.168 + inline static TInt ReduceToNearestMultipleOf(TInt aNumber1, TInt aNumber2) {return (aNumber1/aNumber2)*aNumber2;}
1.169 + };
1.170 +
1.171 +#endif