]> git.saurik.com Git - apple/cf.git/blob - StringEncodings.subproj/CFStringEncodingConverterExt.h
CF-299.35.tar.gz
[apple/cf.git] / StringEncodings.subproj / CFStringEncodingConverterExt.h
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* CFStringEncodingConverterExt.h
26 Copyright (c) 1998-2003, Apple, Inc. All rights reserved.
27 */
28
29 #ifndef __CFSTRINGENCODINGCONVERETEREXT_H__
30 #define __CFSTRINGENCODINGCONVERETEREXT_H__ 1
31
32 #include "CFStringEncodingConverter.h"
33
34 #if defined(__cplusplus)
35 extern "C" {
36 #endif
37
38 #define MAX_DECOMPOSED_LENGTH (10)
39
40 enum {
41 kCFStringEncodingConverterStandard = 0,
42 kCFStringEncodingConverterCheapEightBit = 1,
43 kCFStringEncodingConverterStandardEightBit = 2,
44 kCFStringEncodingConverterCheapMultiByte = 3,
45 kCFStringEncodingConverterPlatformSpecific = 4 // Other fields are ignored
46 };
47
48 /* kCFStringEncodingConverterStandard */
49 typedef UInt32 (*CFStringEncodingToBytesProc)(UInt32 flags, const UniChar *characters, UInt32 numChars, UInt8 *bytes, UInt32 maxByteLen, UInt32 *usedByteLen);
50 typedef UInt32 (*CFStringEncodingToUnicodeProc)(UInt32 flags, const UInt8 *bytes, UInt32 numBytes, UniChar *characters, UInt32 maxCharLen, UInt32 *usedCharLen);
51 /* kCFStringEncodingConverterCheapEightBit */
52 typedef Boolean (*CFStringEncodingCheapEightBitToBytesProc)(UInt32 flags, UniChar character, UInt8 *byte);
53 typedef Boolean (*CFStringEncodingCheapEightBitToUnicodeProc)(UInt32 flags, UInt8 byte, UniChar *character);
54 /* kCFStringEncodingConverterStandardEightBit */
55 typedef UInt16 (*CFStringEncodingStandardEightBitToBytesProc)(UInt32 flags, const UniChar *characters, UInt32 numChars, UInt8 *byte);
56 typedef UInt16 (*CFStringEncodingStandardEightBitToUnicodeProc)(UInt32 flags, UInt8 byte, UniChar *characters);
57 /* kCFStringEncodingConverterCheapMultiByte */
58 typedef UInt16 (*CFStringEncodingCheapMultiByteToBytesProc)(UInt32 flags, UniChar character, UInt8 *bytes);
59 typedef UInt16 (*CFStringEncodingCheapMultiByteToUnicodeProc)(UInt32 flags, const UInt8 *bytes, UInt32 numBytes, UniChar *character);
60
61 typedef UInt32 (*CFStringEncodingToBytesLenProc)(UInt32 flags, const UniChar *characters, UInt32 numChars);
62 typedef UInt32 (*CFStringEncodingToUnicodeLenProc)(UInt32 flags, const UInt8 *bytes, UInt32 numBytes);
63
64 typedef UInt32 (*CFStringEncodingToBytesPrecomposeProc)(UInt32 flags, const UniChar *character, UInt32 numChars, UInt8 *bytes, UInt32 maxByteLen, UInt32 *usedByteLen);
65 typedef Boolean (*CFStringEncodingIsValidCombiningCharacterProc)(UniChar character);
66
67 typedef struct {
68 void *toBytes;
69 void *toUnicode;
70 UInt16 maxBytesPerChar;
71 UInt16 maxDecomposedCharLen;
72 UInt8 encodingClass;
73 UInt32 :24;
74 CFStringEncodingToBytesLenProc toBytesLen;
75 CFStringEncodingToUnicodeLenProc toUnicodeLen;
76 CFStringEncodingToBytesFallbackProc toBytesFallback;
77 CFStringEncodingToUnicodeFallbackProc toUnicodeFallback;
78 CFStringEncodingToBytesPrecomposeProc toBytesPrecompose;
79 CFStringEncodingIsValidCombiningCharacterProc isValidCombiningChar;
80 } CFStringEncodingConverter;
81
82
83 extern const CFStringEncodingConverter *CFStringEncodingGetConverter(UInt32 encoding);
84
85 enum {
86 kCFStringEncodingGetConverterSelector = 0,
87 kCFStringEncodingIsDecomposableCharacterSelector = 1,
88 kCFStringEncodingDecomposeCharacterSelector = 2,
89 kCFStringEncodingIsValidLatin1CombiningCharacterSelector = 3,
90 kCFStringEncodingPrecomposeLatin1CharacterSelector = 4
91 };
92
93 extern const void *CFStringEncodingGetAddressForSelector(UInt32 selector);
94
95 #define BOOTSTRAPFUNC_NAME CFStringEncodingBootstrap
96 typedef const CFStringEncodingConverter* (*CFStringEncodingBootstrapProc)(UInt32 encoding, const void *getSelector);
97
98 extern UInt32 CFStringEncodingGetScriptCodeForEncoding(CFStringEncoding encoding);
99
100 /* Latin precomposition */
101 /* This function does not precompose recursively nor to U+01E0 and U+01E1.
102 */
103 extern Boolean CFStringEncodingIsValidCombiningCharacterForLatin1(UniChar character);
104 extern UniChar CFStringEncodingPrecomposeLatinCharacter(const UniChar *character, UInt32 numChars, UInt32 *usedChars);
105
106 /* Convenience functions for converter development */
107 typedef struct _CFStringEncodingUnicodeTo8BitCharMap {
108 UniChar _u;
109 UInt8 _c;
110 UInt8 :8;
111 } CFStringEncodingUnicodeTo8BitCharMap;
112
113 /* Binary searches CFStringEncodingUnicodeTo8BitCharMap */
114 CF_INLINE Boolean CFStringEncodingUnicodeTo8BitEncoding(const CFStringEncodingUnicodeTo8BitCharMap *theTable, UInt32 numElem, UniChar character, UInt8 *ch) {
115 const CFStringEncodingUnicodeTo8BitCharMap *p, *q, *divider;
116
117 if ((character < theTable[0]._u) || (character > theTable[numElem-1]._u)) {
118 return 0;
119 }
120 p = theTable;
121 q = p + (numElem-1);
122 while (p <= q) {
123 divider = p + ((q - p) >> 1); /* divide by 2 */
124 if (character < divider->_u) { q = divider - 1; }
125 else if (character > divider->_u) { p = divider + 1; }
126 else { *ch = divider->_c; return 1; }
127 }
128 return 0;
129 }
130
131
132 #if defined(__cplusplus)
133 }
134 #endif
135
136 #endif /* __CFSTRINGENCODINGCONVERETEREXT_H__ */