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 /* CFStringEncodingConverter.h
24 Copyright (c) 1998-2007, Apple Inc. All rights reserved.
27 #if !defined(__COREFOUNDATION_CFSTRINGENCODINGCONVERTER__)
28 #define __COREFOUNDATION_CFSTRINGENCODINGCONVERTER__ 1
30 #include <CoreFoundation/CFString.h>
35 /* Values for flags argument for the conversion functions below. These can be combined, but the three NonSpacing behavior flags are exclusive.
38 kCFStringEncodingAllowLossyConversion
= 1, // Uses fallback functions to substitutes non mappable chars
39 kCFStringEncodingBasicDirectionLeftToRight
= (1 << 1), // Converted with original direction left-to-right.
40 kCFStringEncodingBasicDirectionRightToLeft
= (1 << 2), // Converted with original direction right-to-left.
41 kCFStringEncodingSubstituteCombinings
= (1 << 3), // Uses fallback function to combining chars.
42 kCFStringEncodingComposeCombinings
= (1 << 4), // Checks mappable precomposed equivalents for decomposed sequences. This is the default behavior.
43 kCFStringEncodingIgnoreCombinings
= (1 << 5), // Ignores combining chars.
44 kCFStringEncodingUseCanonical
= (1 << 6), // Always use canonical form
45 kCFStringEncodingUseHFSPlusCanonical
= (1 << 7), // Always use canonical form but leaves 0x2000 ranges
46 kCFStringEncodingPrependBOM
= (1 << 8), // Prepend BOM sequence (i.e. ISO2022KR)
47 kCFStringEncodingDisableCorporateArea
= (1 << 9), // Disable the usage of 0xF8xx area for Apple proprietary chars in converting to UniChar, resulting loosely mapping.
48 kCFStringEncodingASCIICompatibleConversion
= (1 << 10), // This flag forces strict ASCII compatible converion. i.e. MacJapanese 0x5C maps to Unicode 0x5C.
49 kCFStringEncodingLenientUTF8Conversion
= (1 << 11) // 10.1 (Puma) compatible lenient UTF-8 conversion.
52 /* Return values for CFStringEncodingUnicodeToBytes & CFStringEncodingBytesToUnicode functions
55 kCFStringEncodingConversionSuccess
= 0,
56 kCFStringEncodingInvalidInputStream
= 1,
57 kCFStringEncodingInsufficientOutputBufferLength
= 2,
58 kCFStringEncodingConverterUnavailable
= 3
61 /* Macro to shift lossByte argument.
63 #define CFStringEncodingLossyByteToMask(lossByte) ((uint32_t)(lossByte << 24)|kCFStringEncodingAllowLossyConversion)
64 #define CFStringEncodingMaskToLossyByte(flags) ((uint8_t)(flags >> 24))
66 /* Converts characters into the specified encoding. Returns the constants defined above.
67 If maxByteLen is 0, bytes is ignored. You can pass lossyByte by passing the value in flags argument.
68 i.e. CFStringEncodingUnicodeToBytes(encoding, CFStringEncodingLossyByteToMask(lossByte), ....)
70 extern uint32_t CFStringEncodingUnicodeToBytes(uint32_t encoding
, uint32_t flags
, const UniChar
*characters
, CFIndex numChars
, CFIndex
*usedCharLen
, uint8_t *bytes
, CFIndex maxByteLen
, CFIndex
*usedByteLen
);
72 /* Converts bytes in the specified encoding into unicode. Returns the constants defined above.
73 maxCharLen & usdCharLen are in UniChar length, not byte length.
74 If maxCharLen is 0, characters is ignored.
76 extern uint32_t CFStringEncodingBytesToUnicode(uint32_t encoding
, uint32_t flags
, const uint8_t *bytes
, CFIndex numBytes
, CFIndex
*usedByteLen
, UniChar
*characters
, CFIndex maxCharLen
, CFIndex
*usedCharLen
);
78 /* Fallback functions used when allowLossy
80 typedef CFIndex (*CFStringEncodingToBytesFallbackProc
)(const UniChar
*characters
, CFIndex numChars
, uint8_t *bytes
, CFIndex maxByteLen
, CFIndex
*usedByteLen
);
81 typedef CFIndex (*CFStringEncodingToUnicodeFallbackProc
)(const uint8_t *bytes
, CFIndex numBytes
, UniChar
*characters
, CFIndex maxCharLen
, CFIndex
*usedCharLen
);
83 extern bool CFStringEncodingIsValidEncoding(uint32_t encoding
);
85 /* Returns kCFStringEncodingInvalidId terminated encoding list
87 extern const uint32_t *CFStringEncodingListOfAvailableEncodings(void);
89 extern const char *CFStringEncodingName(uint32_t encoding
);
91 /* Returns NULL-terminated list of IANA registered canonical names
93 extern const char **CFStringEncodingCanonicalCharsetNames(uint32_t encoding
);
95 /* Returns required length of destination buffer for conversion. These functions are faster than specifying 0 to maxByteLen (maxCharLen), but unnecessarily optimal length
97 extern CFIndex
CFStringEncodingCharLengthForBytes(uint32_t encoding
, uint32_t flags
, const uint8_t *bytes
, CFIndex numBytes
);
98 extern CFIndex
CFStringEncodingByteLengthForCharacters(uint32_t encoding
, uint32_t flags
, const UniChar
*characters
, CFIndex numChars
);
100 /* Can register functions used for lossy conversion. Reregisters default procs if NULL
102 extern void CFStringEncodingRegisterFallbackProcedures(uint32_t encoding
, CFStringEncodingToBytesFallbackProc toBytes
, CFStringEncodingToUnicodeFallbackProc toUnicode
);
106 #endif /* ! __COREFOUNDATION_CFSTRINGENCODINGCONVERTER__ */