symport/charconv/framework/inc/utf.h
author Pat Downey <patrick.downey@nokia.com>
Thu, 25 Jun 2009 15:59:54 +0100
changeset 1 0a7b44b10206
child 2 806186ab5e14
permissions -rw-r--r--
Catch up of Symbian tools for @1627812
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     2
// All rights reserved.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     3
// This component and the accompanying materials are made available
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     4
// under the terms of the License "Symbian Foundation License v1.0"
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     5
// which accompanies this distribution, and is available
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     6
// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     7
//
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     8
// Initial Contributors:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    10
//
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    11
// Contributors:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    12
//
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    13
// Description:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    14
//
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    15
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    16
#if !defined(__UTF_H__)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    17
#define __UTF_H__
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    18
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    19
#if !defined(__E32STD_H__)
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    20
#include <e32std.h>
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    21
#endif
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    22
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    23
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    24
class CnvUtfConverter
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    25
/** 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    26
Converts text between Unicode (UCS-2) and the two Unicode transformation 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    27
formats UTF-7 and UTF-8. There are no functions to convert directly between 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    28
UTF-7 and UTF-8.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    29
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    30
Objects of this class do not need to be created because all the member functions 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    31
are static. The four functions are passed text in the second argument and 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    32
output the resulting text in the first argument. Sixteen-bit descriptors are 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    33
used to hold text encoded in UCS-2 (i.e. normal 16 bit Unicode), and eight-bit 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    34
descriptors are used to hold text encoded in either of the transformation 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    35
formats.
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    36
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    37
The conversion functions return the number of characters which were not converted 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    38
because the output descriptor was not long enough to hold all of the converted 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    39
text. This allows users of this class to perform partial conversions on an 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    40
input descriptor, handling the case when the input descriptor is truncated 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    41
mid way through a multi-byte character. The caller does not have to guess 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    42
how big to make the output descriptor for a given input descriptor- they 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    43
can simply do the conversion in a loop using a small output descriptor. The 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    44
ability to handle truncated descriptors is particularly useful if the caller 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    45
is receiving information in chunks from an external source. 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    46
@publishedAll
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    47
@released
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    48
*/
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    49
	{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    50
public:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    51
	/** Conversion error flags. At this stage there is only one error flag 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    52
	- others may be added in the future. */
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    53
	enum TError
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    54
		{
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    55
 		/** The input descriptor contains a single corrupt character. This 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    56
 		might occur when the input descriptor only contains some of the bytes 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    57
 		of a single multi-byte character. */
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    58
		EErrorIllFormedInput=KErrCorrupt
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    59
		};
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    60
	 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    61
	 /** Initial value for the state argument in a set of related calls to
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    62
	ConvertToUnicode(). */
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    63
	enum {KStateDefault=0}; 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    64
public:
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    65
	// 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
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    66
	IMPORT_C static TInt ConvertFromUnicodeToUtf7(TDes8& aUtf7, const TDesC16& aUnicode, TBool aEncodeOptionalDirectCharactersInBase64);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    67
	static TInt ConvertFromUnicodeToUtf7(TDes8& aUtf7, const TDesC16& aUnicode, TBool aIsImapUtf7, TBool aEncodeOptionalDirectCharactersInBase64);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    68
	IMPORT_C static TInt ConvertFromUnicodeToUtf8(TDes8& aUtf8, const TDesC16& aUnicode);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    69
	static TInt ConvertFromUnicodeToUtf8(TDes8& aUtf8, const TDesC16& aUnicode, TBool aGenerateJavaConformantUtf8);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    70
	IMPORT_C static TInt ConvertToUnicodeFromUtf7(TDes16& aUnicode, const TDesC8& aUtf7, TInt& aState);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    71
	static TInt ConvertToUnicodeFromUtf7(TDes16& aUnicode, const TDesC8& aUtf7, TBool aIsImapUtf7, TInt& aState);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    72
	IMPORT_C static TInt ConvertToUnicodeFromUtf8(TDes16& aUnicode, const TDesC8& aUtf8);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    73
	static TInt ConvertToUnicodeFromUtf8(TDes16& aUnicode, const TDesC8& aUtf8, TBool aGenerateJavaConformantUtf8);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    74
	static TInt ConvertToUnicodeFromUtf8(TDes16& aUnicode, const TDesC8& aUtf8, TBool aGenerateJavaConformantUtf8,
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    75
			TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    76
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    77
	IMPORT_C static HBufC8* ConvertFromUnicodeToUtf7L(const TDesC16& aUnicode,TBool aEncodeOptionalDirectCharactersInBase64);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    78
	IMPORT_C static HBufC8* ConvertFromUnicodeToUtf8L(const TDesC16& aUnicode);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    79
	IMPORT_C static HBufC16* ConvertToUnicodeFromUtf7L(const TDesC8& aUtf7); 
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    80
	IMPORT_C static HBufC16* ConvertToUnicodeFromUtf8L(const TDesC8& aUtf8);
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    81
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    82
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    83
	};
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    84
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    85
#endif
0a7b44b10206 Catch up of Symbian tools for @1627812
Pat Downey <patrick.downey@nokia.com>
parents:
diff changeset
    86