]> git.saurik.com Git - apple/cf.git/blob - CFStringEncodingConverterExt.h
CF-476.10.tar.gz
[apple/cf.git] / CFStringEncodingConverterExt.h
1 /*
2 * Copyright (c) 2008 Apple 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-2007, Apple Inc. All rights reserved.
25 */
26
27 #if !defined(__COREFOUNDATION_CFSTRINGENCODINGCONVERETEREXT__)
28 #define __COREFOUNDATION_CFSTRINGENCODINGCONVERETEREXT__ 1
29
30 #include <CoreFoundation/CFStringEncodingConverter.h>
31
32 CF_EXTERN_C_BEGIN
33
34 #define MAX_DECOMPOSED_LENGTH (10)
35
36 enum {
37 kCFStringEncodingConverterStandard = 0,
38 kCFStringEncodingConverterCheapEightBit = 1,
39 kCFStringEncodingConverterStandardEightBit = 2,
40 kCFStringEncodingConverterCheapMultiByte = 3,
41 kCFStringEncodingConverterPlatformSpecific = 4 // Other fields are ignored
42 };
43
44 /* kCFStringEncodingConverterStandard */
45 typedef CFIndex (*CFStringEncodingToBytesProc)(uint32_t flags, const UniChar *characters, CFIndex numChars, uint8_t *bytes, CFIndex maxByteLen, CFIndex *usedByteLen);
46 typedef CFIndex (*CFStringEncodingToUnicodeProc)(uint32_t flags, const uint8_t *bytes, CFIndex numBytes, UniChar *characters, CFIndex maxCharLen, CFIndex *usedCharLen);
47 /* kCFStringEncodingConverterCheapEightBit */
48 typedef bool (*CFStringEncodingCheapEightBitToBytesProc)(uint32_t flags, UniChar character, uint8_t *byte);
49 typedef bool (*CFStringEncodingCheapEightBitToUnicodeProc)(uint32_t flags, uint8_t byte, UniChar *character);
50 /* kCFStringEncodingConverterStandardEightBit */
51 typedef uint16_t (*CFStringEncodingStandardEightBitToBytesProc)(uint32_t flags, const UniChar *characters, CFIndex numChars, uint8_t *byte);
52 typedef uint16_t (*CFStringEncodingStandardEightBitToUnicodeProc)(uint32_t flags, uint8_t byte, UniChar *characters);
53 /* kCFStringEncodingConverterCheapMultiByte */
54 typedef uint16_t (*CFStringEncodingCheapMultiByteToBytesProc)(uint32_t flags, UniChar character, uint8_t *bytes);
55 typedef uint16_t (*CFStringEncodingCheapMultiByteToUnicodeProc)(uint32_t flags, const uint8_t *bytes, CFIndex numBytes, UniChar *character);
56
57 typedef CFIndex (*CFStringEncodingToBytesLenProc)(uint32_t flags, const UniChar *characters, CFIndex numChars);
58 typedef CFIndex (*CFStringEncodingToUnicodeLenProc)(uint32_t flags, const uint8_t *bytes, CFIndex numBytes);
59
60 typedef CFIndex (*CFStringEncodingToBytesPrecomposeProc)(uint32_t flags, const UniChar *character, CFIndex numChars, uint8_t *bytes, CFIndex maxByteLen, CFIndex *usedByteLen);
61 typedef bool (*CFStringEncodingIsValidCombiningCharacterProc)(UniChar character);
62
63 typedef struct {
64 void *toBytes;
65 void *toUnicode;
66 uint16_t maxBytesPerChar;
67 uint16_t maxDecomposedCharLen;
68 uint8_t encodingClass;
69 uint32_t :24;
70 CFStringEncodingToBytesLenProc toBytesLen;
71 CFStringEncodingToUnicodeLenProc toUnicodeLen;
72 CFStringEncodingToBytesFallbackProc toBytesFallback;
73 CFStringEncodingToUnicodeFallbackProc toUnicodeFallback;
74 CFStringEncodingToBytesPrecomposeProc toBytesPrecompose;
75 CFStringEncodingIsValidCombiningCharacterProc isValidCombiningChar;
76 } CFStringEncodingConverter;
77
78
79 extern const CFStringEncodingConverter *CFStringEncodingGetConverter(uint32_t encoding);
80
81 enum {
82 kCFStringEncodingGetConverterSelector = 0,
83 kCFStringEncodingIsDecomposableCharacterSelector = 1,
84 kCFStringEncodingDecomposeCharacterSelector = 2,
85 kCFStringEncodingIsValidLatin1CombiningCharacterSelector = 3,
86 kCFStringEncodingPrecomposeLatin1CharacterSelector = 4
87 };
88
89 extern const void *CFStringEncodingGetAddressForSelector(uint32_t selector);
90
91 #define BOOTSTRAPFUNC_NAME CFStringEncodingBootstrap
92 typedef const CFStringEncodingConverter* (*CFStringEncodingBootstrapProc)(uint32_t encoding, const void *getSelector);
93
94 extern uint32_t CFStringEncodingGetScriptCodeForEncoding(CFStringEncoding encoding);
95
96 /* Latin precomposition */
97 /* This function does not precompose recursively nor to U+01E0 and U+01E1.
98 */
99 extern bool CFStringEncodingIsValidCombiningCharacterForLatin1(UniChar character);
100 extern UniChar CFStringEncodingPrecomposeLatinCharacter(const UniChar *character, CFIndex numChars, CFIndex *usedChars);
101
102 /* Convenience functions for converter development */
103 typedef struct _CFStringEncodingUnicodeTo8BitCharMap {
104 UniChar _u;
105 uint8_t _c;
106 uint8_t :8;
107 } CFStringEncodingUnicodeTo8BitCharMap;
108
109 /* Binary searches CFStringEncodingUnicodeTo8BitCharMap */
110 CF_INLINE bool CFStringEncodingUnicodeTo8BitEncoding(const CFStringEncodingUnicodeTo8BitCharMap *theTable, CFIndex numElem, UniChar character, uint8_t *ch) {
111 const CFStringEncodingUnicodeTo8BitCharMap *p, *q, *divider;
112
113 if ((character < theTable[0]._u) || (character > theTable[numElem-1]._u)) {
114 return 0;
115 }
116 p = theTable;
117 q = p + (numElem-1);
118 while (p <= q) {
119 divider = p + ((q - p) >> 1); /* divide by 2 */
120 if (character < divider->_u) { q = divider - 1; }
121 else if (character > divider->_u) { p = divider + 1; }
122 else { *ch = divider->_c; return 1; }
123 }
124 return 0;
125 }
126
127
128 CF_EXTERN_C_END
129
130 #endif /* ! __COREFOUNDATION_CFSTRINGENCODINGCONVERETEREXT__ */
131