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