charconvfw/Charconv/ongoing/test/source/otherutf/UTF8.H
author Pat Downey <patd@symbian.org>
Wed, 01 Sep 2010 12:39:40 +0100
branchRCL_3
changeset 55 336bee5c2d35
permissions -rw-r--r--
Revert incorrect RCL_3 drop: Revision: 201021 Kit: 201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/* ================================================================ */
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
/*
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
File:	ConvertUTF.h
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
Author: Mark E. Davis
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
Copyright (C) 1994 Taligent, Inc. All rights reserved.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
This code is copyrighted. Under the copyright laws, this code may not
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
be copied, in whole or part, without prior written consent of Taligent. 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
Taligent grants the right to use or reprint this code as long as this
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
ENTIRE copyright notice is reproduced in the code or reproduction.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
The code is provided AS-IS, AND TALIGENT DISCLAIMS ALL WARRANTIES,
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO IMPLIED
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IN
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
NO EVENT WILL TALIGENT BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING,
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
LOSS) ARISING OUT OF THE USE OR INABILITY TO USE THIS CODE, EVEN
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
IF TALIGENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
BECAUSE SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
LIMITATION MAY NOT APPLY TO YOU.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
government is subject to restrictions as set forth in subparagraph
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
(c)(l)(ii) of the Rights in Technical Data and Computer Software
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
clause at DFARS 252.227-7013 and FAR 52.227-19.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
This code may be protected by one or more U.S. and International
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
Patents.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
TRADEMARKS: Taligent and the Taligent Design Mark are registered
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
trademarks of Taligent, Inc.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
*/
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
/* ================================================================ */
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
// #include <stdio.h> // commented out by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
// #include <stdlib.h> // commented out by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
// #include <types.h>
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
// #include <string.h> // commented out by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
#if !defined(__E32STD_H__) // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
#include <e32std.h> // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
#endif // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
/* ================================================================ */
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
/*	The following 4 definitions are compiler-specific.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
	I would use wchar_t for UCS2/UTF16, except that the C standard
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
	does not guarantee that it has at least 16 bits, so wchar_t is
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
	no less portable than unsigned short!
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
*/
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
typedef unsigned long	UCS4;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
typedef unsigned short	UCS2;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
typedef unsigned short	UTF16;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
typedef unsigned char	UTF8;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
// typedef enum {false, true} Boolean; // commented out by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
const UCS4 kReplacementCharacter =	0x0000FFFDUL;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
const UCS4 kMaximumUCS2 =			0x0000FFFFUL;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
const UCS4 kMaximumUTF16 =			0x0010FFFFUL;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    63
const UCS4 kMaximumUCS4 =			0x7FFFFFFFUL;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
/* ================================================================ */
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
/*	Each of these routines converts the text between *sourceStart and 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
sourceEnd, putting the result into the buffer between *targetStart and
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
targetEnd. Note: the end pointers are *after* the last item: e.g. 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
*(sourceEnd - 1) is the last item.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    70
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    71
	The return result indicates whether the conversion was successful,
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
and if not, whether the problem was in the source or target buffers.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    73
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
	After the conversion, *sourceStart and *targetStart are both
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    75
updated to point to the end of last text successfully converted in
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    76
the respective buffers.
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
*/
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
typedef enum {
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
	ok, 				/* conversion successful */
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
	sourceExhausted,	/* partial character in source, but hit end */
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
	targetExhausted		/* insuff. room in target for conversion */
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
} ConversionResult;
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
IMPORT_C // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
ConversionResult	ConvertUCS4toUTF16 (
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
		UCS4** sourceStart, const UCS4* sourceEnd, 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
		UTF16** targetStart, const UTF16* targetEnd);
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    89
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
IMPORT_C // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
ConversionResult	ConvertUTF16toUCS4 (
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
		UTF16** sourceStart, UTF16* sourceEnd, 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
		UCS4** targetStart, const UCS4* targetEnd);
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
IMPORT_C // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
ConversionResult	ConvertUTF16toUTF8 (
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97
		UTF16** sourceStart, const UTF16* sourceEnd, 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
		UTF8** targetStart, const UTF8* targetEnd);
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
		
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
IMPORT_C // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
ConversionResult	ConvertUTF8toUTF16 (
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
		UTF8** sourceStart, UTF8* sourceEnd, 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
		UTF16** targetStart, const UTF16* targetEnd);
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
IMPORT_C // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
ConversionResult	ConvertUCS4toUTF8 (
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
		UCS4** sourceStart, const UCS4* sourceEnd, 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
		UTF8** targetStart, const UTF8* targetEnd);
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
		
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
IMPORT_C // added by DPB
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   111
ConversionResult	ConvertUTF8toUCS4 (
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
		UTF8** sourceStart, UTF8* sourceEnd, 
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   113
		UCS4** targetStart, const UCS4* targetEnd);
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   114
336bee5c2d35 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   115
/* ================================================================ */