2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #if !defined(__UTF_H__)
22 #if !defined(__E32STD_H__)
29 Converts text between Unicode (UCS-2) and the two Unicode transformation
30 formats UTF-7 and UTF-8. There are no functions to convert directly between
33 Objects of this class do not need to be created because all the member functions
34 are static. The four functions are passed text in the second argument and
35 output the resulting text in the first argument. Sixteen-bit descriptors are
36 used to hold text encoded in UCS-2 (i.e. normal 16 bit Unicode), and eight-bit
37 descriptors are used to hold text encoded in either of the transformation
40 The conversion functions return the number of characters which were not converted
41 because the output descriptor was not long enough to hold all of the converted
42 text. This allows users of this class to perform partial conversions on an
43 input descriptor, handling the case when the input descriptor is truncated
44 mid way through a multi-byte character. The caller does not have to guess
45 how big to make the output descriptor for a given input descriptor- they
46 can simply do the conversion in a loop using a small output descriptor. The
47 ability to handle truncated descriptors is particularly useful if the caller
48 is receiving information in chunks from an external source.
54 /** Conversion error flags. At this stage there is only one error flag
55 - others may be added in the future. */
58 /** The input descriptor contains a single corrupt character. This
59 might occur when the input descriptor only contains some of the bytes
60 of a single multi-byte character. */
61 EErrorIllFormedInput=KErrCorrupt
64 /** Initial value for the state argument in a set of related calls to
65 ConvertToUnicode(). */
66 enum {KStateDefault=0};
68 // the conversion functions return either one of the TError values above, or the number of unconverted elements left at the end of the input descriptor
69 IMPORT_C static TInt ConvertFromUnicodeToUtf7(TDes8& aUtf7, const TDesC16& aUnicode, TBool aEncodeOptionalDirectCharactersInBase64);
70 static TInt ConvertFromUnicodeToUtf7(TDes8& aUtf7, const TDesC16& aUnicode, TBool aIsImapUtf7, TBool aEncodeOptionalDirectCharactersInBase64);
71 IMPORT_C static TInt ConvertFromUnicodeToUtf8(TDes8& aUtf8, const TDesC16& aUnicode);
72 static TInt ConvertFromUnicodeToUtf8(TDes8& aUtf8, const TDesC16& aUnicode, TBool aGenerateJavaConformantUtf8);
73 IMPORT_C static TInt ConvertToUnicodeFromUtf7(TDes16& aUnicode, const TDesC8& aUtf7, TInt& aState);
74 static TInt ConvertToUnicodeFromUtf7(TDes16& aUnicode, const TDesC8& aUtf7, TBool aIsImapUtf7, TInt& aState);
75 IMPORT_C static TInt ConvertToUnicodeFromUtf8(TDes16& aUnicode, const TDesC8& aUtf8);
76 static TInt ConvertToUnicodeFromUtf8(TDes16& aUnicode, const TDesC8& aUtf8, TBool aGenerateJavaConformantUtf8);
77 static TInt ConvertToUnicodeFromUtf8(TDes16& aUnicode, const TDesC8& aUtf8, TBool aGenerateJavaConformantUtf8,
78 TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter);
80 IMPORT_C static HBufC8* ConvertFromUnicodeToUtf7L(const TDesC16& aUnicode,TBool aEncodeOptionalDirectCharactersInBase64);
81 IMPORT_C static HBufC8* ConvertFromUnicodeToUtf8L(const TDesC16& aUnicode);
82 IMPORT_C static HBufC16* ConvertToUnicodeFromUtf7L(const TDesC8& aUtf7);
83 IMPORT_C static HBufC16* ConvertToUnicodeFromUtf8L(const TDesC8& aUtf8);