1 // Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9 
10 use std::os::raw::{c_char, c_ushort, c_void};
11 
12 use base::{Boolean, CFOptionFlags, CFIndex, CFAllocatorRef, CFRange, CFTypeID};
13 
14 pub type UniChar = c_ushort;
15 
16 // CFString.h
17 
18 pub type CFStringCompareFlags = CFOptionFlags;
19 //static kCFCompareCaseInsensitive: CFStringCompareFlags = 1;
20 //static kCFCompareBackwards: CFStringCompareFlags = 4;
21 //static kCFCompareAnchored: CFStringCompareFlags = 8;
22 //static kCFCompareNonliteral: CFStringCompareFlags = 16;
23 //static kCFCompareLocalized: CFStringCompareFlags = 32;
24 //static kCFCompareNumerically: CFStringCompareFlags = 64;
25 //static kCFCompareDiacriticInsensitive: CFStringCompareFlags = 128;
26 //static kCFCompareWidthInsensitive: CFStringCompareFlags = 256;
27 //static kCFCompareForcedOrdering: CFStringCompareFlags = 512;
28 
29 pub type CFStringEncoding = u32;
30 
31 // macOS built-in encodings.
32 
33 //static kCFStringEncodingMacRoman: CFStringEncoding = 0;
34 //static kCFStringEncodingWindowsLatin1: CFStringEncoding = 0x0500;
35 //static kCFStringEncodingISOLatin1: CFStringEncoding = 0x0201;
36 //static kCFStringEncodingNextStepLatin: CFStringEncoding = 0x0B01;
37 //static kCFStringEncodingASCII: CFStringEncoding = 0x0600;
38 //static kCFStringEncodingUnicode: CFStringEncoding = 0x0100;
39 pub static kCFStringEncodingUTF8: CFStringEncoding = 0x08000100;
40 //static kCFStringEncodingNonLossyASCII: CFStringEncoding = 0x0BFF;
41 
42 //static kCFStringEncodingUTF16: CFStringEncoding = 0x0100;
43 //static kCFStringEncodingUTF16BE: CFStringEncoding = 0x10000100;
44 //static kCFStringEncodingUTF16LE: CFStringEncoding = 0x14000100;
45 //static kCFStringEncodingUTF32: CFStringEncoding = 0x0c000100;
46 //static kCFStringEncodingUTF32BE: CFStringEncoding = 0x18000100;
47 //static kCFStringEncodingUTF32LE: CFStringEncoding = 0x1c000100;
48 
49 
50 // CFStringEncodingExt.h
51 
52 pub type CFStringEncodings = CFIndex;
53 
54 // External encodings, except those defined above.
55 // Defined above: kCFStringEncodingMacRoman = 0
56 //static kCFStringEncodingMacJapanese: CFStringEncoding = 1;
57 //static kCFStringEncodingMacChineseTrad: CFStringEncoding = 2;
58 //static kCFStringEncodingMacKorean: CFStringEncoding = 3;
59 //static kCFStringEncodingMacArabic: CFStringEncoding = 4;
60 //static kCFStringEncodingMacHebrew: CFStringEncoding = 5;
61 //static kCFStringEncodingMacGreek: CFStringEncoding = 6;
62 //static kCFStringEncodingMacCyrillic: CFStringEncoding = 7;
63 //static kCFStringEncodingMacDevanagari: CFStringEncoding = 9;
64 //static kCFStringEncodingMacGurmukhi: CFStringEncoding = 10;
65 //static kCFStringEncodingMacGujarati: CFStringEncoding = 11;
66 //static kCFStringEncodingMacOriya: CFStringEncoding = 12;
67 //static kCFStringEncodingMacBengali: CFStringEncoding = 13;
68 //static kCFStringEncodingMacTamil: CFStringEncoding = 14;
69 //static kCFStringEncodingMacTelugu: CFStringEncoding = 15;
70 //static kCFStringEncodingMacKannada: CFStringEncoding = 16;
71 //static kCFStringEncodingMacMalayalam: CFStringEncoding = 17;
72 //static kCFStringEncodingMacSinhalese: CFStringEncoding = 18;
73 //static kCFStringEncodingMacBurmese: CFStringEncoding = 19;
74 //static kCFStringEncodingMacKhmer: CFStringEncoding = 20;
75 //static kCFStringEncodingMacThai: CFStringEncoding = 21;
76 //static kCFStringEncodingMacLaotian: CFStringEncoding = 22;
77 //static kCFStringEncodingMacGeorgian: CFStringEncoding = 23;
78 //static kCFStringEncodingMacArmenian: CFStringEncoding = 24;
79 //static kCFStringEncodingMacChineseSimp: CFStringEncoding = 25;
80 //static kCFStringEncodingMacTibetan: CFStringEncoding = 26;
81 //static kCFStringEncodingMacMongolian: CFStringEncoding = 27;
82 //static kCFStringEncodingMacEthiopic: CFStringEncoding = 28;
83 //static kCFStringEncodingMacCentralEurRoman: CFStringEncoding = 29;
84 //static kCFStringEncodingMacVietnamese: CFStringEncoding = 30;
85 //static kCFStringEncodingMacExtArabic: CFStringEncoding = 31;
86 //static kCFStringEncodingMacSymbol: CFStringEncoding = 33;
87 //static kCFStringEncodingMacDingbats: CFStringEncoding = 34;
88 //static kCFStringEncodingMacTurkish: CFStringEncoding = 35;
89 //static kCFStringEncodingMacCroatian: CFStringEncoding = 36;
90 //static kCFStringEncodingMacIcelandic: CFStringEncoding = 37;
91 //static kCFStringEncodingMacRomanian: CFStringEncoding = 38;
92 //static kCFStringEncodingMacCeltic: CFStringEncoding = 39;
93 //static kCFStringEncodingMacGaelic: CFStringEncoding = 40;
94 //static kCFStringEncodingMacFarsi: CFStringEncoding = 0x8C;
95 //static kCFStringEncodingMacUkrainian: CFStringEncoding = 0x98;
96 //static kCFStringEncodingMacInuit: CFStringEncoding = 0xEC;
97 //static kCFStringEncodingMacVT100: CFStringEncoding = 0xFC;
98 //static kCFStringEncodingMacHFS: CFStringEncoding = 0xFF;
99 // Defined above: kCFStringEncodingISOLatin1 = 0x0201
100 //static kCFStringEncodingISOLatin2: CFStringEncoding = 0x0202;
101 //static kCFStringEncodingISOLatin3: CFStringEncoding = 0x0203;
102 //static kCFStringEncodingISOLatin4: CFStringEncoding = 0x0204;
103 //static kCFStringEncodingISOLatinCyrillic: CFStringEncoding = 0x0205;
104 //static kCFStringEncodingISOLatinArabic: CFStringEncoding = 0x0206;
105 //static kCFStringEncodingISOLatinGreek: CFStringEncoding = 0x0207;
106 //static kCFStringEncodingISOLatinHebrew: CFStringEncoding = 0x0208;
107 //static kCFStringEncodingISOLatin5: CFStringEncoding = 0x0209;
108 //static kCFStringEncodingISOLatin6: CFStringEncoding = 0x020A;
109 //static kCFStringEncodingISOLatinThai: CFStringEncoding = 0x020B;
110 //static kCFStringEncodingISOLatin7: CFStringEncoding = 0x020D;
111 //static kCFStringEncodingISOLatin8: CFStringEncoding = 0x020E;
112 //static kCFStringEncodingISOLatin9: CFStringEncoding = 0x020F;
113 //static kCFStringEncodingISOLatin10: CFStringEncoding = 0x0210;
114 //static kCFStringEncodingDOSLatinUS: CFStringEncoding = 0x0400;
115 //static kCFStringEncodingDOSGreek: CFStringEncoding = 0x0405;
116 //static kCFStringEncodingDOSBalticRim: CFStringEncoding = 0x0406;
117 //static kCFStringEncodingDOSLatin1: CFStringEncoding = 0x0410;
118 //static kCFStringEncodingDOSGreek1: CFStringEncoding = 0x0411;
119 //static kCFStringEncodingDOSLatin2: CFStringEncoding = 0x0412;
120 //static kCFStringEncodingDOSCyrillic: CFStringEncoding = 0x0413;
121 //static kCFStringEncodingDOSTurkish: CFStringEncoding = 0x0414;
122 //static kCFStringEncodingDOSPortuguese: CFStringEncoding = 0x0415;
123 //static kCFStringEncodingDOSIcelandic: CFStringEncoding = 0x0416;
124 //static kCFStringEncodingDOSHebrew: CFStringEncoding = 0x0417;
125 //static kCFStringEncodingDOSCanadianFrench: CFStringEncoding = 0x0418;
126 //static kCFStringEncodingDOSArabic: CFStringEncoding = 0x0419;
127 //static kCFStringEncodingDOSNordic: CFStringEncoding = 0x041A;
128 //static kCFStringEncodingDOSRussian: CFStringEncoding = 0x041B;
129 //static kCFStringEncodingDOSGreek2: CFStringEncoding = 0x041C;
130 //static kCFStringEncodingDOSThai: CFStringEncoding = 0x041D;
131 //static kCFStringEncodingDOSJapanese: CFStringEncoding = 0x0420;
132 //static kCFStringEncodingDOSChineseSimplif: CFStringEncoding = 0x0421;
133 //static kCFStringEncodingDOSKorean: CFStringEncoding = 0x0422;
134 //static kCFStringEncodingDOSChineseTrad: CFStringEncoding = 0x0423;
135 // Defined above: kCFStringEncodingWindowsLatin1 = 0x0500
136 //static kCFStringEncodingWindowsLatin2: CFStringEncoding = 0x0501;
137 //static kCFStringEncodingWindowsCyrillic: CFStringEncoding = 0x0502;
138 //static kCFStringEncodingWindowsGreek: CFStringEncoding = 0x0503;
139 //static kCFStringEncodingWindowsLatin5: CFStringEncoding = 0x0504;
140 //static kCFStringEncodingWindowsHebrew: CFStringEncoding = 0x0505;
141 //static kCFStringEncodingWindowsArabic: CFStringEncoding = 0x0506;
142 //static kCFStringEncodingWindowsBalticRim: CFStringEncoding = 0x0507;
143 //static kCFStringEncodingWindowsVietnamese: CFStringEncoding = 0x0508;
144 //static kCFStringEncodingWindowsKoreanJohab: CFStringEncoding = 0x0510;
145 // Defined above: kCFStringEncodingASCII = 0x0600
146 //static kCFStringEncodingANSEL: CFStringEncoding = 0x0601;
147 //static kCFStringEncodingJIS_X0201_76: CFStringEncoding = 0x0620;
148 //static kCFStringEncodingJIS_X0208_83: CFStringEncoding = 0x0621;
149 //static kCFStringEncodingJIS_X0208_90: CFStringEncoding = 0x0622;
150 //static kCFStringEncodingJIS_X0212_90: CFStringEncoding = 0x0623;
151 //static kCFStringEncodingJIS_C6226_78: CFStringEncoding = 0x0624;
152 //static kCFStringEncodingShiftJIS_X0213: CFStringEncoding = 0x0628;
153 //static kCFStringEncodingShiftJIS_X0213_MenKuTen: CFStringEncoding = 0x0629;
154 //static kCFStringEncodingGB_2312_80: CFStringEncoding = 0x0630;
155 //static kCFStringEncodingGBK_95: CFStringEncoding = 0x0631;
156 //static kCFStringEncodingGB_18030_2000: CFStringEncoding = 0x0632;
157 //static kCFStringEncodingKSC_5601_87: CFStringEncoding = 0x0640;
158 //static kCFStringEncodingKSC_5601_92_Johab: CFStringEncoding = 0x0641;
159 //static kCFStringEncodingCNS_11643_92_P1: CFStringEncoding = 0x0651;
160 //static kCFStringEncodingCNS_11643_92_P2: CFStringEncoding = 0x0652;
161 //static kCFStringEncodingCNS_11643_92_P3: CFStringEncoding = 0x0653;
162 //static kCFStringEncodingISO_2022_JP: CFStringEncoding = 0x0820;
163 //static kCFStringEncodingISO_2022_JP_2: CFStringEncoding = 0x0821;
164 //static kCFStringEncodingISO_2022_JP_1: CFStringEncoding = 0x0822;
165 //static kCFStringEncodingISO_2022_JP_3: CFStringEncoding = 0x0823;
166 //static kCFStringEncodingISO_2022_CN: CFStringEncoding = 0x0830;
167 //static kCFStringEncodingISO_2022_CN_EXT: CFStringEncoding = 0x0831;
168 //static kCFStringEncodingISO_2022_KR: CFStringEncoding = 0x0840;
169 //static kCFStringEncodingEUC_JP: CFStringEncoding = 0x0920;
170 //static kCFStringEncodingEUC_CN: CFStringEncoding = 0x0930;
171 //static kCFStringEncodingEUC_TW: CFStringEncoding = 0x0931;
172 //static kCFStringEncodingEUC_KR: CFStringEncoding = 0x0940;
173 //static kCFStringEncodingShiftJIS: CFStringEncoding = 0x0A01;
174 //static kCFStringEncodingKOI8_R: CFStringEncoding = 0x0A02;
175 //static kCFStringEncodingBig5: CFStringEncoding = 0x0A03;
176 //static kCFStringEncodingMacRomanLatin1: CFStringEncoding = 0x0A04;
177 //static kCFStringEncodingHZ_GB_2312: CFStringEncoding = 0x0A05;
178 //static kCFStringEncodingBig5_HKSCS_1999: CFStringEncoding = 0x0A06;
179 //static kCFStringEncodingVISCII: CFStringEncoding = 0x0A07;
180 //static kCFStringEncodingKOI8_U: CFStringEncoding = 0x0A08;
181 //static kCFStringEncodingBig5_E: CFStringEncoding = 0x0A09;
182 // Defined above: kCFStringEncodingNextStepLatin = 0x0B01
183 //static kCFStringEncodingNextStepJapanese: CFStringEncoding = 0x0B02;
184 //static kCFStringEncodingEBCDIC_US: CFStringEncoding = 0x0C01;
185 //static kCFStringEncodingEBCDIC_CP037: CFStringEncoding = 0x0C02;
186 //static kCFStringEncodingUTF7: CFStringEncoding = 0x04000100;
187 //static kCFStringEncodingUTF7_IMAP: CFStringEncoding = 0x0A10;
188 //static kCFStringEncodingShiftJIS_X0213_00: CFStringEncoding = 0x0628; /* Deprecated */
189 
190 #[repr(C)]
191 pub struct __CFString(c_void);
192 
193 pub type CFStringRef = *const __CFString;
194 
195 extern {
196     /*
197      * CFString.h
198      */
199 
200     // N.B. organized according to "Functions by task" in docs
201 
202     /* Creating a CFString */
203     //fn CFSTR
204     //fn CFStringCreateArrayBySeparatingStrings
205     //fn CFStringCreateByCombiningStrings
206     //fn CFStringCreateCopy
207     //fn CFStringCreateFromExternalRepresentation
CFStringCreateWithBytes(alloc: CFAllocatorRef, bytes: *const u8, numBytes: CFIndex, encoding: CFStringEncoding, isExternalRepresentation: Boolean) -> CFStringRef208     pub fn CFStringCreateWithBytes(alloc: CFAllocatorRef,
209                                    bytes: *const u8,
210                                    numBytes: CFIndex,
211                                    encoding: CFStringEncoding,
212                                    isExternalRepresentation: Boolean)
213                                    -> CFStringRef;
CFStringCreateWithBytesNoCopy(alloc: CFAllocatorRef, bytes: *const u8, numBytes: CFIndex, encoding: CFStringEncoding, isExternalRepresentation: Boolean, contentsDeallocator: CFAllocatorRef) -> CFStringRef214     pub fn CFStringCreateWithBytesNoCopy(alloc: CFAllocatorRef,
215                                          bytes: *const u8,
216                                          numBytes: CFIndex,
217                                          encoding: CFStringEncoding,
218                                          isExternalRepresentation: Boolean,
219                                          contentsDeallocator: CFAllocatorRef)
220                                          -> CFStringRef;
221     //fn CFStringCreateWithCharacters
222     //fn CFStringCreateWithCharactersNoCopy
CFStringCreateWithCString(alloc: CFAllocatorRef, cStr: *const c_char, encoding: CFStringEncoding) -> CFStringRef223     pub fn CFStringCreateWithCString(alloc: CFAllocatorRef,
224                                      cStr: *const c_char,
225                                      encoding: CFStringEncoding)
226                                      -> CFStringRef;
227     //fn CFStringCreateWithCStringNoCopy
228     //fn CFStringCreateWithFormat
229     //fn CFStringCreateWithFormatAndArguments
230     //fn CFStringCreateWithPascalString
231     //fn CFStringCreateWithPascalStringNoCopy
232     //fn CFStringCreateWithSubstring
233 
234     /* Searching Strings */
235     //fn CFStringCreateArrayWithFindResults
236     //fn CFStringFind
237     //fn CFStringFindCharacterFromSet
238     //fn CFStringFindWithOptions
239     //fn CFStringFindWithOptionsAndLocale
240     //fn CFStringGetLineBounds
241 
242     /* Comparing Strings */
243     //fn CFStringCompare
244     //fn CFStringCompareWithOptions
245     //fn CFStringCompareWithOptionsAndLocale
246     //fn CFStringHasPrefix
247     //fn CFStringHasSuffix
248 
249     /* Accessing Characters */
250     //fn CFStringCreateExternalRepresentation
CFStringGetBytes(theString: CFStringRef, range: CFRange, encoding: CFStringEncoding, lossByte: u8, isExternalRepresentation: Boolean, buffer: *mut u8, maxBufLen: CFIndex, usedBufLen: *mut CFIndex) -> CFIndex251     pub fn CFStringGetBytes(theString: CFStringRef,
252                             range: CFRange,
253                             encoding: CFStringEncoding,
254                             lossByte: u8,
255                             isExternalRepresentation: Boolean,
256                             buffer: *mut u8,
257                             maxBufLen: CFIndex,
258                             usedBufLen: *mut CFIndex)
259                             -> CFIndex;
260     //fn CFStringGetCharacterAtIndex
261     //fn CFStringGetCharacters
262     //fn CFStringGetCharactersPtr
263     //fn CFStringGetCharacterFromInlineBuffer
CFStringGetCString(theString: CFStringRef, buffer: *mut c_char, bufferSize: CFIndex, encoding: CFStringEncoding) -> Boolean264     pub fn CFStringGetCString(theString: CFStringRef,
265                               buffer: *mut c_char,
266                               bufferSize: CFIndex,
267                               encoding: CFStringEncoding)
268                               -> Boolean;
CFStringGetCStringPtr(theString: CFStringRef, encoding: CFStringEncoding) -> *const c_char269     pub fn CFStringGetCStringPtr(theString: CFStringRef,
270                                  encoding: CFStringEncoding)
271                                  -> *const c_char;
CFStringGetLength(theString: CFStringRef) -> CFIndex272     pub fn CFStringGetLength(theString: CFStringRef) -> CFIndex;
273     //fn CFStringGetPascalString
274     //fn CFStringGetPascalStringPtr
275     //fn CFStringGetRangeOfComposedCharactersAtIndex
276     //fn CFStringInitInlineBuffer
277 
278     /* Working With Hyphenation */
279     //fn CFStringGetHyphenationLocationBeforeIndex
280     //fn CFStringIsHyphenationAvailableForLocale
281 
282     /* Working With Encodings */
283     //fn CFStringConvertEncodingToIANACharSetName
284     //fn CFStringConvertEncodingToNSStringEncoding
285     //fn CFStringConvertEncodingToWindowsCodepage
286     //fn CFStringConvertIANACharSetNameToEncoding
287     //fn CFStringConvertNSStringEncodingToEncoding
288     //fn CFStringConvertWindowsCodepageToEncoding
289     //fn CFStringGetFastestEncoding
290     //fn CFStringGetListOfAvailableEncodings
291     //fn CFStringGetMaximumSizeForEncoding
292     //fn CFStringGetMostCompatibleMacStringEncoding
293     //fn CFStringGetNameOfEncoding
294     //fn CFStringGetSmallestEncoding
295     //fn CFStringGetSystemEncoding
296     //fn CFStringIsEncodingAvailable
297 
298     /* Getting Numeric Values */
299     //fn CFStringGetDoubleValue
300     //fn CFStringGetIntValue
301 
302     /* Getting String Properties */
303     //fn CFShowStr
CFStringGetTypeID() -> CFTypeID304     pub fn CFStringGetTypeID() -> CFTypeID;
305 
306     /* String File System Representations */
307     //fn CFStringCreateWithFileSystemRepresentation
308     //fn CFStringGetFileSystemRepresentation
309     //fn CFStringGetMaximumSizeOfFileSystemRepresentation
310 
311     /* Getting Paragraph Bounds */
312     //fn CFStringGetParagraphBounds
313 
314     /* Managing Surrogates */
315     //fn CFStringGetLongCharacterForSurrogatePair
316     //fn CFStringGetSurrogatePairForLongCharacter
317     //fn CFStringIsSurrogateHighCharacter
318     //fn CFStringIsSurrogateLowCharacter
319 }
320