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