2 * Copyright (c) 2009 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-2009, 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
42 kCFStringEncodingConverterICU
= 5 // Other fields are ignored
45 /* kCFStringEncodingConverterStandard */
46 typedef CFIndex (*CFStringEncodingToBytesProc
)(uint32_t flags
, const UniChar
*characters
, CFIndex numChars
, uint8_t *bytes
, CFIndex maxByteLen
, CFIndex
*usedByteLen
);
47 typedef CFIndex (*CFStringEncodingToUnicodeProc
)(uint32_t flags
, const uint8_t *bytes
, CFIndex numBytes
, UniChar
*characters
, CFIndex maxCharLen
, CFIndex
*usedCharLen
);
48 /* kCFStringEncodingConverterCheapEightBit */
49 typedef bool (*CFStringEncodingCheapEightBitToBytesProc
)(uint32_t flags
, UniChar character
, uint8_t *byte
);
50 typedef bool (*CFStringEncodingCheapEightBitToUnicodeProc
)(uint32_t flags
, uint8_t byte
, UniChar
*character
);
51 /* kCFStringEncodingConverterStandardEightBit */
52 typedef uint16_t (*CFStringEncodingStandardEightBitToBytesProc
)(uint32_t flags
, const UniChar
*characters
, CFIndex numChars
, uint8_t *byte
);
53 typedef uint16_t (*CFStringEncodingStandardEightBitToUnicodeProc
)(uint32_t flags
, uint8_t byte
, UniChar
*characters
);
54 /* kCFStringEncodingConverterCheapMultiByte */
55 typedef uint16_t (*CFStringEncodingCheapMultiByteToBytesProc
)(uint32_t flags
, UniChar character
, uint8_t *bytes
);
56 typedef uint16_t (*CFStringEncodingCheapMultiByteToUnicodeProc
)(uint32_t flags
, const uint8_t *bytes
, CFIndex numBytes
, UniChar
*character
);
58 typedef CFIndex (*CFStringEncodingToBytesLenProc
)(uint32_t flags
, const UniChar
*characters
, CFIndex numChars
);
59 typedef CFIndex (*CFStringEncodingToUnicodeLenProc
)(uint32_t flags
, const uint8_t *bytes
, CFIndex numBytes
);
61 typedef CFIndex (*CFStringEncodingToBytesPrecomposeProc
)(uint32_t flags
, const UniChar
*character
, CFIndex numChars
, uint8_t *bytes
, CFIndex maxByteLen
, CFIndex
*usedByteLen
);
62 typedef bool (*CFStringEncodingIsValidCombiningCharacterProc
)(UniChar character
);
67 uint16_t maxBytesPerChar
;
68 uint16_t maxDecomposedCharLen
;
69 uint8_t encodingClass
;
71 CFStringEncodingToBytesLenProc toBytesLen
;
72 CFStringEncodingToUnicodeLenProc toUnicodeLen
;
73 CFStringEncodingToBytesFallbackProc toBytesFallback
;
74 CFStringEncodingToUnicodeFallbackProc toUnicodeFallback
;
75 CFStringEncodingToBytesPrecomposeProc toBytesPrecompose
;
76 CFStringEncodingIsValidCombiningCharacterProc isValidCombiningChar
;
77 } 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 /* Latin precomposition */
95 /* This function does not precompose recursively nor to U+01E0 and U+01E1.
97 extern bool CFStringEncodingIsValidCombiningCharacterForLatin1(UniChar character
);
98 extern UniChar
CFStringEncodingPrecomposeLatinCharacter(const UniChar
*character
, CFIndex numChars
, CFIndex
*usedChars
);
100 /* Convenience functions for converter development */
101 typedef struct _CFStringEncodingUnicodeTo8BitCharMap
{
105 } CFStringEncodingUnicodeTo8BitCharMap
;
107 /* Binary searches CFStringEncodingUnicodeTo8BitCharMap */
108 CF_INLINE
bool CFStringEncodingUnicodeTo8BitEncoding(const CFStringEncodingUnicodeTo8BitCharMap
*theTable
, CFIndex numElem
, UniChar character
, uint8_t *ch
) {
109 const CFStringEncodingUnicodeTo8BitCharMap
*p
, *q
, *divider
;
111 if ((character
< theTable
[0]._u
) || (character
> theTable
[numElem
-1]._u
)) {
117 divider
= p
+ ((q
- p
) >> 1); /* divide by 2 */
118 if (character
< divider
->_u
) { q
= divider
- 1; }
119 else if (character
> divider
->_u
) { p
= divider
+ 1; }
120 else { *ch
= divider
->_c
; return 1; }
128 #endif /* ! __COREFOUNDATION_CFSTRINGENCODINGCONVERETEREXT__ */