|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /* ================================================================ */
26: /*
27: File: ConvertUTF.h
28: Author: Mark E. Davis
29: Copyright (C) 1994 Taligent, Inc. All rights reserved.
30:
31: This code is copyrighted. Under the copyright laws, this code may not
32: be copied, in whole or part, without prior written consent of Taligent.
33:
34: Taligent grants the right to use or reprint this code as long as this
35: ENTIRE copyright notice is reproduced in the code or reproduction.
36: The code is provided AS-IS, AND TALIGENT DISCLAIMS ALL WARRANTIES,
37: EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO IMPLIED
38: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN
39: NO EVENT WILL TALIGENT BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING,
40: WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS
41: INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY
42: LOSS) ARISING OUT OF THE USE OR INABILITY TO USE THIS CODE, EVEN
43: IF TALIGENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
44: BECAUSE SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF
45: LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE
46: LIMITATION MAY NOT APPLY TO YOU.
47:
48: RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
49: government is subject to restrictions as set forth in subparagraph
50: (c)(l)(ii) of the Rights in Technical Data and Computer Software
51: clause at DFARS 252.227-7013 and FAR 52.227-19.
52:
53: This code may be protected by one or more U.S. and International
54: Patents.
55:
56: TRADEMARKS: Taligent and the Taligent Design Mark are registered
57: trademarks of Taligent, Inc.
58: */
59: /* ================================================================ */
60:
61: // #include <types.h>
62:
63: /* ================================================================ */
64: /* The following 4 definitions are compiler-specific.
65: I would use wchar_t for UCS2/UTF16, except that the C standard
66: does not guarantee that it has at least 16 bits, so wchar_t is
67: no less portable than unsigned short!
68: */
69:
70: typedef unsigned long UCS4;
71: typedef unsigned short UCS2;
72: typedef unsigned short UTF16;
73: typedef unsigned char UTF8;
74:
75: /*
76: const UCS4 kReplacementCharacter = 0x0000FFFDUL;
77: const UCS4 kMaximumUCS2 = 0x0000FFFFUL;
78: const UCS4 kMaximumUTF16 = 0x0010FFFFUL;
79: const UCS4 kMaximumUCS4 = 0x7FFFFFFFUL;
80: */
81:
82: /* ================================================================ */
83: /* Each of these routines converts the text between *sourceStart and
84: sourceEnd, putting the result into the buffer between *targetStart and
85: targetEnd. Note: the end pointers are *after* the last item: e.g.
86: *(sourceEnd - 1) is the last item.
87:
88: The return result indicates whether the conversion was successful,
89: and if not, whether the problem was in the source or target buffers.
90:
91: After the conversion, *sourceStart and *targetStart are both
92: updated to point to the end of last text successfully converted in
93: the respective buffers.
94: */
95:
96: typedef enum {
97: ok, /* conversion successful */
98: sourceExhausted, /* partial character in source, but hit end */
99: targetExhausted /* insuff. room in target for conversion */
100: } ConversionResult;
101:
102: ConversionResult ConvertUTF16toUTF8 (
103: UTF16** sourceStart, const UTF16* sourceEnd,
104: UTF8** targetStart, const UTF8* targetEnd);
105:
106: ConversionResult ConvertUTF8toUTF16 (
107: UTF8** sourceStart, UTF8* sourceEnd,
108: UTF16** targetStart, const UTF16* targetEnd);
109:
110: /* ================================================================ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.