2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
25 /* CFStringEncodingConverterExt.h
26 Copyright (c) 1998-2003, Apple, Inc. All rights reserved.
29 #ifndef __CFSTRINGENCODINGCONVERETEREXT_H__
30 #define __CFSTRINGENCODINGCONVERETEREXT_H__ 1
32 #include "CFStringEncodingConverter.h"
34 #if defined(__cplusplus)
38 #define MAX_DECOMPOSED_LENGTH (10)
41 kCFStringEncodingConverterStandard
= 0,
42 kCFStringEncodingConverterCheapEightBit
= 1,
43 kCFStringEncodingConverterStandardEightBit
= 2,
44 kCFStringEncodingConverterCheapMultiByte
= 3,
45 kCFStringEncodingConverterPlatformSpecific
= 4 // Other fields are ignored
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
);
61 typedef UInt32 (*CFStringEncodingToBytesLenProc
)(UInt32 flags
, const UniChar
*characters
, UInt32 numChars
);
62 typedef UInt32 (*CFStringEncodingToUnicodeLenProc
)(UInt32 flags
, const UInt8
*bytes
, UInt32 numBytes
);
64 typedef UInt32 (*CFStringEncodingToBytesPrecomposeProc
)(UInt32 flags
, const UniChar
*character
, UInt32 numChars
, UInt8
*bytes
, UInt32 maxByteLen
, UInt32
*usedByteLen
);
65 typedef Boolean (*CFStringEncodingIsValidCombiningCharacterProc
)(UniChar character
);
70 UInt16 maxBytesPerChar
;
71 UInt16 maxDecomposedCharLen
;
74 CFStringEncodingToBytesLenProc toBytesLen
;
75 CFStringEncodingToUnicodeLenProc toUnicodeLen
;
76 CFStringEncodingToBytesFallbackProc toBytesFallback
;
77 CFStringEncodingToUnicodeFallbackProc toUnicodeFallback
;
78 CFStringEncodingToBytesPrecomposeProc toBytesPrecompose
;
79 CFStringEncodingIsValidCombiningCharacterProc isValidCombiningChar
;
80 } CFStringEncodingConverter
;
83 extern const CFStringEncodingConverter
*CFStringEncodingGetConverter(UInt32 encoding
);
86 kCFStringEncodingGetConverterSelector
= 0,
87 kCFStringEncodingIsDecomposableCharacterSelector
= 1,
88 kCFStringEncodingDecomposeCharacterSelector
= 2,
89 kCFStringEncodingIsValidLatin1CombiningCharacterSelector
= 3,
90 kCFStringEncodingPrecomposeLatin1CharacterSelector
= 4
93 extern const void *CFStringEncodingGetAddressForSelector(UInt32 selector
);
95 #define BOOTSTRAPFUNC_NAME CFStringEncodingBootstrap
96 typedef const CFStringEncodingConverter
* (*CFStringEncodingBootstrapProc
)(UInt32 encoding
, const void *getSelector
);
98 extern UInt32
CFStringEncodingGetScriptCodeForEncoding(CFStringEncoding encoding
);
100 /* Latin precomposition */
101 /* This function does not precompose recursively nor to U+01E0 and U+01E1.
103 extern Boolean
CFStringEncodingIsValidCombiningCharacterForLatin1(UniChar character
);
104 extern UniChar
CFStringEncodingPrecomposeLatinCharacter(const UniChar
*character
, UInt32 numChars
, UInt32
*usedChars
);
106 /* Convenience functions for converter development */
107 typedef struct _CFStringEncodingUnicodeTo8BitCharMap
{
111 } CFStringEncodingUnicodeTo8BitCharMap
;
113 /* Binary searches CFStringEncodingUnicodeTo8BitCharMap */
114 CF_INLINE Boolean
CFStringEncodingUnicodeTo8BitEncoding(const CFStringEncodingUnicodeTo8BitCharMap
*theTable
, UInt32 numElem
, UniChar character
, UInt8
*ch
) {
115 const CFStringEncodingUnicodeTo8BitCharMap
*p
, *q
, *divider
;
117 if ((character
< theTable
[0]._u
) || (character
> theTable
[numElem
-1]._u
)) {
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; }
132 #if defined(__cplusplus)
136 #endif /* __CFSTRINGENCODINGCONVERETEREXT_H__ */