2 * Copyright (c) 2008 Apple 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-2007, Apple Inc. All rights reserved.
27 #if !defined(__COREFOUNDATION_CFSTRINGENCODINGCONVERETEREXT__)
28 #define __COREFOUNDATION_CFSTRINGENCODINGCONVERETEREXT__ 1
30 #include <CoreFoundation/CFStringEncodingConverter.h>
34 #define MAX_DECOMPOSED_LENGTH (10)
37 kCFStringEncodingConverterStandard
= 0,
38 kCFStringEncodingConverterCheapEightBit
= 1,
39 kCFStringEncodingConverterStandardEightBit
= 2,
40 kCFStringEncodingConverterCheapMultiByte
= 3,
41 kCFStringEncodingConverterPlatformSpecific
= 4 // Other fields are ignored
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
);
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
);
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
);
66 uint16_t maxBytesPerChar
;
67 uint16_t maxDecomposedCharLen
;
68 uint8_t encodingClass
;
70 CFStringEncodingToBytesLenProc toBytesLen
;
71 CFStringEncodingToUnicodeLenProc toUnicodeLen
;
72 CFStringEncodingToBytesFallbackProc toBytesFallback
;
73 CFStringEncodingToUnicodeFallbackProc toUnicodeFallback
;
74 CFStringEncodingToBytesPrecomposeProc toBytesPrecompose
;
75 CFStringEncodingIsValidCombiningCharacterProc isValidCombiningChar
;
76 } CFStringEncodingConverter
;
79 extern const CFStringEncodingConverter
*CFStringEncodingGetConverter(uint32_t encoding
);
82 kCFStringEncodingGetConverterSelector
= 0,
83 kCFStringEncodingIsDecomposableCharacterSelector
= 1,
84 kCFStringEncodingDecomposeCharacterSelector
= 2,
85 kCFStringEncodingIsValidLatin1CombiningCharacterSelector
= 3,
86 kCFStringEncodingPrecomposeLatin1CharacterSelector
= 4
89 extern const void *CFStringEncodingGetAddressForSelector(uint32_t selector
);
91 #define BOOTSTRAPFUNC_NAME CFStringEncodingBootstrap
92 typedef const CFStringEncodingConverter
* (*CFStringEncodingBootstrapProc
)(uint32_t encoding
, const void *getSelector
);
94 extern uint32_t CFStringEncodingGetScriptCodeForEncoding(CFStringEncoding encoding
);
96 /* Latin precomposition */
97 /* This function does not precompose recursively nor to U+01E0 and U+01E1.
99 extern bool CFStringEncodingIsValidCombiningCharacterForLatin1(UniChar character
);
100 extern UniChar
CFStringEncodingPrecomposeLatinCharacter(const UniChar
*character
, CFIndex numChars
, CFIndex
*usedChars
);
102 /* Convenience functions for converter development */
103 typedef struct _CFStringEncodingUnicodeTo8BitCharMap
{
107 } CFStringEncodingUnicodeTo8BitCharMap
;
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
;
113 if ((character
< theTable
[0]._u
) || (character
> theTable
[numElem
-1]._u
)) {
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; }
130 #endif /* ! __COREFOUNDATION_CFSTRINGENCODINGCONVERETEREXT__ */