2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 /* CFStringEncodingConverterExt.h
24 Copyright (c) 1998-2005, Apple, Inc. All rights reserved.
27 #ifndef __CFSTRINGENCODINGCONVERETEREXT_H__
28 #define __CFSTRINGENCODINGCONVERETEREXT_H__ 1
30 #include <CoreFoundation/CFStringEncodingConverter.h>
32 #if defined(__cplusplus)
36 #define MAX_DECOMPOSED_LENGTH (10)
39 kCFStringEncodingConverterStandard
= 0,
40 kCFStringEncodingConverterCheapEightBit
= 1,
41 kCFStringEncodingConverterStandardEightBit
= 2,
42 kCFStringEncodingConverterCheapMultiByte
= 3,
43 kCFStringEncodingConverterPlatformSpecific
= 4 // Other fields are ignored
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
);
59 typedef UInt32 (*CFStringEncodingToBytesLenProc
)(UInt32 flags
, const UniChar
*characters
, UInt32 numChars
);
60 typedef UInt32 (*CFStringEncodingToUnicodeLenProc
)(UInt32 flags
, const UInt8
*bytes
, UInt32 numBytes
);
62 typedef UInt32 (*CFStringEncodingToBytesPrecomposeProc
)(UInt32 flags
, const UniChar
*character
, UInt32 numChars
, UInt8
*bytes
, UInt32 maxByteLen
, UInt32
*usedByteLen
);
63 typedef Boolean (*CFStringEncodingIsValidCombiningCharacterProc
)(UniChar character
);
68 UInt16 maxBytesPerChar
;
69 UInt16 maxDecomposedCharLen
;
72 CFStringEncodingToBytesLenProc toBytesLen
;
73 CFStringEncodingToUnicodeLenProc toUnicodeLen
;
74 CFStringEncodingToBytesFallbackProc toBytesFallback
;
75 CFStringEncodingToUnicodeFallbackProc toUnicodeFallback
;
76 CFStringEncodingToBytesPrecomposeProc toBytesPrecompose
;
77 CFStringEncodingIsValidCombiningCharacterProc isValidCombiningChar
;
78 } CFStringEncodingConverter
;
81 extern const CFStringEncodingConverter
*CFStringEncodingGetConverter(UInt32 encoding
);
84 kCFStringEncodingGetConverterSelector
= 0,
85 kCFStringEncodingIsDecomposableCharacterSelector
= 1,
86 kCFStringEncodingDecomposeCharacterSelector
= 2,
87 kCFStringEncodingIsValidLatin1CombiningCharacterSelector
= 3,
88 kCFStringEncodingPrecomposeLatin1CharacterSelector
= 4
91 extern const void *CFStringEncodingGetAddressForSelector(UInt32 selector
);
93 #define BOOTSTRAPFUNC_NAME CFStringEncodingBootstrap
94 typedef const CFStringEncodingConverter
* (*CFStringEncodingBootstrapProc
)(UInt32 encoding
, const void *getSelector
);
96 extern UInt32
CFStringEncodingGetScriptCodeForEncoding(CFStringEncoding encoding
);
98 /* Latin precomposition */
99 /* This function does not precompose recursively nor to U+01E0 and U+01E1.
101 extern Boolean
CFStringEncodingIsValidCombiningCharacterForLatin1(UniChar character
);
102 extern UniChar
CFStringEncodingPrecomposeLatinCharacter(const UniChar
*character
, UInt32 numChars
, UInt32
*usedChars
);
104 /* Convenience functions for converter development */
105 typedef struct _CFStringEncodingUnicodeTo8BitCharMap
{
109 } CFStringEncodingUnicodeTo8BitCharMap
;
111 /* Binary searches CFStringEncodingUnicodeTo8BitCharMap */
112 CF_INLINE Boolean
CFStringEncodingUnicodeTo8BitEncoding(const CFStringEncodingUnicodeTo8BitCharMap
*theTable
, UInt32 numElem
, UniChar character
, UInt8
*ch
) {
113 const CFStringEncodingUnicodeTo8BitCharMap
*p
, *q
, *divider
;
115 if ((character
< theTable
[0]._u
) || (character
> theTable
[numElem
-1]._u
)) {
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; }
130 #if defined(__cplusplus)
134 #endif /* __CFSTRINGENCODINGCONVERETEREXT_H__ */