]>
Commit | Line | Data |
---|---|---|
9ce05555 | 1 | /* |
d8925383 | 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. |
9ce05555 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
9ce05555 A |
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 | /* CFStringEncodingConverter.h | |
d8925383 | 24 | Copyright (c) 1998-2005, Apple, Inc. All rights reserved. |
9ce05555 A |
25 | */ |
26 | ||
27 | #ifndef __CFSTRINGENCODINGCONVERTER__ | |
28 | #define __CFSTRINGENCODINGCONVERTER__ 1 | |
29 | ||
30 | #include <CoreFoundation/CFString.h> | |
31 | ||
32 | ||
33 | #if defined(__cplusplus) | |
34 | extern "C" { | |
35 | #endif | |
36 | ||
37 | /* Values for flags argument for the conversion functions below. These can be combined, but the three NonSpacing behavior flags are exclusive. | |
38 | */ | |
39 | enum { | |
40 | kCFStringEncodingAllowLossyConversion = 1, // Uses fallback functions to substitutes non mappable chars | |
41 | kCFStringEncodingBasicDirectionLeftToRight = (1 << 1), // Converted with original direction left-to-right. | |
42 | kCFStringEncodingBasicDirectionRightToLeft = (1 << 2), // Converted with original direction right-to-left. | |
43 | kCFStringEncodingSubstituteCombinings = (1 << 3), // Uses fallback function to combining chars. | |
44 | kCFStringEncodingComposeCombinings = (1 << 4), // Checks mappable precomposed equivalents for decomposed sequences. This is the default behavior. | |
45 | kCFStringEncodingIgnoreCombinings = (1 << 5), // Ignores combining chars. | |
46 | kCFStringEncodingUseCanonical = (1 << 6), // Always use canonical form | |
47 | kCFStringEncodingUseHFSPlusCanonical = (1 << 7), // Always use canonical form but leaves 0x2000 ranges | |
48 | kCFStringEncodingPrependBOM = (1 << 8), // Prepend BOM sequence (i.e. ISO2022KR) | |
49 | kCFStringEncodingDisableCorporateArea = (1 << 9), // Disable the usage of 0xF8xx area for Apple proprietary chars in converting to UniChar, resulting loosely mapping. | |
50 | kCFStringEncodingASCIICompatibleConversion = (1 << 10), // This flag forces strict ASCII compatible converion. i.e. MacJapanese 0x5C maps to Unicode 0x5C. | |
51 | kCFStringEncodingLenientUTF8Conversion = (1 << 11) // 10.1 (Puma) compatible lenient UTF-8 conversion. | |
52 | }; | |
53 | ||
54 | /* Return values for CFStringEncodingUnicodeToBytes & CFStringEncodingBytesToUnicode functions | |
55 | */ | |
56 | enum { | |
57 | kCFStringEncodingConversionSuccess = 0, | |
58 | kCFStringEncodingInvalidInputStream = 1, | |
59 | kCFStringEncodingInsufficientOutputBufferLength = 2, | |
60 | kCFStringEncodingConverterUnavailable = 3 | |
61 | }; | |
62 | ||
63 | /* Macro to shift lossByte argument. | |
64 | */ | |
65 | #define CFStringEncodingLossyByteToMask(lossByte) ((UInt32)(lossByte << 24)|kCFStringEncodingAllowLossyConversion) | |
66 | #define CFStringEncodingMaskToLossyByte(flags) ((UInt8)(flags >> 24)) | |
67 | ||
68 | /* Converts characters into the specified encoding. Returns the constants defined above. | |
69 | If maxByteLen is 0, bytes is ignored. You can pass lossyByte by passing the value in flags argument. | |
70 | i.e. CFStringEncodingUnicodeToBytes(encoding, CFStringEncodingLossyByteToMask(lossByte), ....) | |
71 | */ | |
72 | extern UInt32 CFStringEncodingUnicodeToBytes(UInt32 encoding, UInt32 flags, const UniChar *characters, UInt32 numChars, UInt32 *usedCharLen, UInt8 *bytes, UInt32 maxByteLen, UInt32 *usedByteLen); | |
73 | ||
74 | /* Converts bytes in the specified encoding into unicode. Returns the constants defined above. | |
75 | maxCharLen & usdCharLen are in UniChar length, not byte length. | |
76 | If maxCharLen is 0, characters is ignored. | |
77 | */ | |
78 | extern UInt32 CFStringEncodingBytesToUnicode(UInt32 encoding, UInt32 flags, const UInt8 *bytes, UInt32 numBytes, UInt32 *usedByteLen, UniChar *characters, UInt32 maxCharLen, UInt32 *usedCharLen); | |
79 | ||
80 | /* Fallback functions used when allowLossy | |
81 | */ | |
82 | typedef UInt32 (*CFStringEncodingToBytesFallbackProc)(const UniChar *characters, UInt32 numChars, UInt8 *bytes, UInt32 maxByteLen, UInt32 *usedByteLen); | |
83 | typedef UInt32 (*CFStringEncodingToUnicodeFallbackProc)(const UInt8 *bytes, UInt32 numBytes, UniChar *characters, UInt32 maxCharLen, UInt32 *usedCharLen); | |
84 | ||
85 | extern Boolean CFStringEncodingIsValidEncoding(UInt32 encoding); | |
86 | ||
87 | /* Returns kCFStringEncodingInvalidId terminated encoding list | |
88 | */ | |
89 | extern const UInt32 *CFStringEncodingListOfAvailableEncodings(void); | |
90 | ||
91 | extern const char *CFStringEncodingName(UInt32 encoding); | |
92 | ||
93 | /* Returns NULL-terminated list of IANA registered canonical names | |
94 | */ | |
95 | extern const char **CFStringEncodingCanonicalCharsetNames(UInt32 encoding); | |
96 | ||
97 | /* Returns required length of destination buffer for conversion. These functions are faster than specifying 0 to maxByteLen (maxCharLen), but unnecessarily optimal length | |
98 | */ | |
99 | extern UInt32 CFStringEncodingCharLengthForBytes(UInt32 encoding, UInt32 flags, const UInt8 *bytes, UInt32 numBytes); | |
100 | extern UInt32 CFStringEncodingByteLengthForCharacters(UInt32 encoding, UInt32 flags, const UniChar *characters, UInt32 numChars); | |
101 | ||
102 | /* Can register functions used for lossy conversion. Reregisters default procs if NULL | |
103 | */ | |
104 | extern void CFStringEncodingRegisterFallbackProcedures(UInt32 encoding, CFStringEncodingToBytesFallbackProc toBytes, CFStringEncodingToUnicodeFallbackProc toUnicode); | |
105 | ||
106 | #if defined(__cplusplus) | |
107 | } | |
108 | #endif | |
109 | ||
110 | #endif /* __CFSTRINGENCODINGCONVERTER__ */ | |
111 |