1 {	CFString.h
2 	Copyright (c) 1998-2013, Apple Inc. All rights reserved.
3 }
4 {
5     Modified for use with Free Pascal
6     Version 308
7     Please report any bugs to <gpc@microbizz.nl>
8 }
9 
10 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
11 {$mode macpas}
12 {$modeswitch cblocks}
13 {$packenum 1}
14 {$macro on}
15 {$inline on}
16 {$calling mwpascal}
17 
18 unit CFString;
19 interface
20 {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
21 {$setc GAP_INTERFACES_VERSION := $0308}
22 
23 {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
24     {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
25 {$endc}
26 
27 {$ifc defined CPUPOWERPC and defined CPUI386}
28 	{$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
29 {$endc}
30 {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
31 	{$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
32 {$endc}
33 
34 {$ifc not defined __ppc__ and defined CPUPOWERPC32}
35 	{$setc __ppc__ := 1}
36 {$elsec}
37 	{$setc __ppc__ := 0}
38 {$endc}
39 {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
40 	{$setc __ppc64__ := 1}
41 {$elsec}
42 	{$setc __ppc64__ := 0}
43 {$endc}
44 {$ifc not defined __i386__ and defined CPUI386}
45 	{$setc __i386__ := 1}
46 {$elsec}
47 	{$setc __i386__ := 0}
48 {$endc}
49 {$ifc not defined __x86_64__ and defined CPUX86_64}
50 	{$setc __x86_64__ := 1}
51 {$elsec}
52 	{$setc __x86_64__ := 0}
53 {$endc}
54 {$ifc not defined __arm__ and defined CPUARM}
55 	{$setc __arm__ := 1}
56 {$elsec}
57 	{$setc __arm__ := 0}
58 {$endc}
59 {$ifc not defined __arm64__ and defined CPUAARCH64}
60   {$setc __arm64__ := 1}
61 {$elsec}
62   {$setc __arm64__ := 0}
63 {$endc}
64 
65 {$ifc defined cpu64}
66   {$setc __LP64__ := 1}
67 {$elsec}
68   {$setc __LP64__ := 0}
69 {$endc}
70 
71 
72 {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
73 	{$error Conflicting definitions for __ppc__ and __i386__}
74 {$endc}
75 
76 {$ifc defined __ppc__ and __ppc__}
77 	{$setc TARGET_CPU_PPC := TRUE}
78 	{$setc TARGET_CPU_PPC64 := FALSE}
79 	{$setc TARGET_CPU_X86 := FALSE}
80 	{$setc TARGET_CPU_X86_64 := FALSE}
81 	{$setc TARGET_CPU_ARM := FALSE}
82 	{$setc TARGET_CPU_ARM64 := FALSE}
83 	{$setc TARGET_OS_MAC := TRUE}
84 	{$setc TARGET_OS_IPHONE := FALSE}
85 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
86 	{$setc TARGET_OS_EMBEDDED := FALSE}
87 {$elifc defined __ppc64__ and __ppc64__}
88 	{$setc TARGET_CPU_PPC := FALSE}
89 	{$setc TARGET_CPU_PPC64 := TRUE}
90 	{$setc TARGET_CPU_X86 := FALSE}
91 	{$setc TARGET_CPU_X86_64 := FALSE}
92 	{$setc TARGET_CPU_ARM := FALSE}
93 	{$setc TARGET_CPU_ARM64 := FALSE}
94 	{$setc TARGET_OS_MAC := TRUE}
95 	{$setc TARGET_OS_IPHONE := FALSE}
96 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
97 	{$setc TARGET_OS_EMBEDDED := FALSE}
98 {$elifc defined __i386__ and __i386__}
99 	{$setc TARGET_CPU_PPC := FALSE}
100 	{$setc TARGET_CPU_PPC64 := FALSE}
101 	{$setc TARGET_CPU_X86 := TRUE}
102 	{$setc TARGET_CPU_X86_64 := FALSE}
103 	{$setc TARGET_CPU_ARM := FALSE}
104 	{$setc TARGET_CPU_ARM64 := FALSE}
105 {$ifc defined iphonesim}
106  	{$setc TARGET_OS_MAC := FALSE}
107 	{$setc TARGET_OS_IPHONE := TRUE}
108 	{$setc TARGET_IPHONE_SIMULATOR := TRUE}
109 {$elsec}
110 	{$setc TARGET_OS_MAC := TRUE}
111 	{$setc TARGET_OS_IPHONE := FALSE}
112 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
113 {$endc}
114 	{$setc TARGET_OS_EMBEDDED := FALSE}
115 {$elifc defined __x86_64__ and __x86_64__}
116 	{$setc TARGET_CPU_PPC := FALSE}
117 	{$setc TARGET_CPU_PPC64 := FALSE}
118 	{$setc TARGET_CPU_X86 := FALSE}
119 	{$setc TARGET_CPU_X86_64 := TRUE}
120 	{$setc TARGET_CPU_ARM := FALSE}
121 	{$setc TARGET_CPU_ARM64 := FALSE}
122 {$ifc defined iphonesim}
123  	{$setc TARGET_OS_MAC := FALSE}
124 	{$setc TARGET_OS_IPHONE := TRUE}
125 	{$setc TARGET_IPHONE_SIMULATOR := TRUE}
126 {$elsec}
127 	{$setc TARGET_OS_MAC := TRUE}
128 	{$setc TARGET_OS_IPHONE := FALSE}
129 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
130 {$endc}
131 	{$setc TARGET_OS_EMBEDDED := FALSE}
132 {$elifc defined __arm__ and __arm__}
133 	{$setc TARGET_CPU_PPC := FALSE}
134 	{$setc TARGET_CPU_PPC64 := FALSE}
135 	{$setc TARGET_CPU_X86 := FALSE}
136 	{$setc TARGET_CPU_X86_64 := FALSE}
137 	{$setc TARGET_CPU_ARM := TRUE}
138 	{$setc TARGET_CPU_ARM64 := FALSE}
139 	{$setc TARGET_OS_MAC := FALSE}
140 	{$setc TARGET_OS_IPHONE := TRUE}
141 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
142 	{$setc TARGET_OS_EMBEDDED := TRUE}
143 {$elifc defined __arm64__ and __arm64__}
144 	{$setc TARGET_CPU_PPC := FALSE}
145 	{$setc TARGET_CPU_PPC64 := FALSE}
146 	{$setc TARGET_CPU_X86 := FALSE}
147 	{$setc TARGET_CPU_X86_64 := FALSE}
148 	{$setc TARGET_CPU_ARM := FALSE}
149 	{$setc TARGET_CPU_ARM64 := TRUE}
150 {$ifc defined ios}
151 	{$setc TARGET_OS_MAC := FALSE}
152 	{$setc TARGET_OS_IPHONE := TRUE}
153 	{$setc TARGET_OS_EMBEDDED := TRUE}
154 {$elsec}
155 	{$setc TARGET_OS_MAC := TRUE}
156 	{$setc TARGET_OS_IPHONE := FALSE}
157 	{$setc TARGET_OS_EMBEDDED := FALSE}
158 {$endc}
159 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
160 {$elsec}
161 	{$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
162 {$endc}
163 
164 {$ifc defined __LP64__ and __LP64__ }
165   {$setc TARGET_CPU_64 := TRUE}
166 {$elsec}
167   {$setc TARGET_CPU_64 := FALSE}
168 {$endc}
169 
170 {$ifc defined FPC_BIG_ENDIAN}
171 	{$setc TARGET_RT_BIG_ENDIAN := TRUE}
172 	{$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
173 {$elifc defined FPC_LITTLE_ENDIAN}
174 	{$setc TARGET_RT_BIG_ENDIAN := FALSE}
175 	{$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
176 {$elsec}
177 	{$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
178 {$endc}
179 {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
180 {$setc CALL_NOT_IN_CARBON := FALSE}
181 {$setc OLDROUTINENAMES := FALSE}
182 {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
183 {$setc OPAQUE_UPP_TYPES := TRUE}
184 {$setc OTCARBONAPPLICATION := TRUE}
185 {$setc OTKERNEL := FALSE}
186 {$setc PM_USE_SESSION_APIS := TRUE}
187 {$setc TARGET_API_MAC_CARBON := TRUE}
188 {$setc TARGET_API_MAC_OS8 := FALSE}
189 {$setc TARGET_API_MAC_OSX := TRUE}
190 {$setc TARGET_CARBON := TRUE}
191 {$setc TARGET_CPU_68K := FALSE}
192 {$setc TARGET_CPU_MIPS := FALSE}
193 {$setc TARGET_CPU_SPARC := FALSE}
194 {$setc TARGET_OS_UNIX := FALSE}
195 {$setc TARGET_OS_WIN32 := FALSE}
196 {$setc TARGET_RT_MAC_68881 := FALSE}
197 {$setc TARGET_RT_MAC_CFM := FALSE}
198 {$setc TARGET_RT_MAC_MACHO := TRUE}
199 {$setc TYPED_FUNCTION_POINTERS := TRUE}
200 {$setc TYPE_BOOL := FALSE}
201 {$setc TYPE_EXTENDED := FALSE}
202 {$setc TYPE_LONGLONG := TRUE}
203 uses MacTypes,CFBase,CFArray,CFData,CFDictionary,CFCharacterSet,CFLocale;
204 {$endc} {not MACOSALLINCLUDE}
205 
206 {$ALIGN POWER}
207 
208 
209 {
210 Please note: CFStrings are conceptually an array of Unicode characters.
211 However, in general, how a CFString stores this array is an implementation
212 detail. For instance, CFString might choose to use an array of 8-bit characters
213 to store its contents, or it might use multiple blocks of memory, or whatever.
214 This is especially true since CFString is toll-free bridged with NSString, enabling
215 any NSString instance to be used as a CFString. Furthermore, the implementation
216 may change depending on the default system encoding, the user's language,
217 or even a release or update of the OS.
218 
219 What this means is that you should use the following advanced functions with care:
220 
221   CFStringGetPascalStringPtr()
222   CFStringGetCStringPtr()
223   CFStringGetCharactersPtr()
224 
225 These functions are provided for optimization only. They will either return the desired
226 pointer quickly, in constant time, or they return NULL. They might choose to return NULL
227 for many reasons; for instance it's possible that for users running in different
228 languages these sometimes return NULL; or in a future OS release the first two might
229 switch to always returning NULL. Never observing NULL returns in your usages of these
230 functions does not mean they won't ever return NULL. (But note the CFStringGetCharactersPtr()
231 exception mentioned further below.)
232 
233 In your usages of these functions, if you get a NULL return, use the non-Ptr version
234 of the functions as shown in this example:
235 
236   Str255 buffer;
237   StringPtr ptr = CFStringGetPascalStringPtr(str, encoding);
238   if (ptr == NULL) (
239       if (CFStringGetPascalString(str, buffer, 256, encoding)) ptr = buffer;
240   )
241 
242 Note that CFStringGetCString() or CFStringGetPascalString() calls might still fail --- but
243 that will happen in two circumstances only: The conversion from the UniChar contents of CFString
244 to the specified encoding fails, or the buffer is too small. If they fail, that means
245 the conversion was not possible.
246 
247 If you need a copy of the buffer in the above example, you might consider simply calling
248 CFStringGetCString() in all cases --- CFStringGetCStringPtr() is simply an optimization.
249 
250 In addition, the following functions, which create immutable CFStrings from developer
251 supplied buffers without copying the buffers, might have to actually copy
252 under certain circumstances (If they do copy, the buffer will be dealt with by the
253 "contentsDeallocator" argument.):
254 
255   CFStringCreateWithPascalStringNoCopy()
256   CFStringCreateWithCStringNoCopy()
257   CFStringCreateWithCharactersNoCopy()
258 
259 You should of course never depend on the backing store of these CFStrings being
260 what you provided, and in other no circumstance should you change the contents
261 of that buffer (given that would break the invariant about the CFString being immutable).
262 
263 Having said all this, there are actually ways to create a CFString where the backing store
264 is external, and can be manipulated by the developer or CFString itself:
265 
266   CFStringCreateMutableWithExternalCharactersNoCopy()
267   CFStringSetExternalCharactersNoCopy()
268 
269 A "contentsAllocator" is used to realloc or free the backing store by CFString.
270 kCFAllocatorNull can be provided to assure CFString will never realloc or free the buffer.
271 Developer can call CFStringSetExternalCharactersNoCopy() to update
272 CFString's idea of what's going on, if the buffer is changed externally. In these
273 strings, CFStringGetCharactersPtr() is guaranteed to return the external buffer.
274 
275 These functions are here to allow wrapping a buffer of UniChar characters in a CFString,
276 allowing the buffer to passed into CFString functions and also manipulated via CFString
277 mutation functions. In general, developers should not use this technique for all strings,
278 as it prevents CFString from using certain optimizations.
279 }
280 
281 { Identifier for character encoding; the values are the same as Text Encoding Converter TextEncoding.
282 }
283 type
284 	CFStringEncoding = UInt32;
285 	CFStringEncodingPtr = ^CFStringEncoding;
286 
287 { Platform-independent built-in encodings; always available on all platforms.
288    Call CFStringGetSystemEncoding() to get the default system encoding.
289 }
290 type
291 	CFStringBuiltInEncodings = CFStringEncoding;
292 const
293 	kCFStringEncodingInvalidId = $FFFFFFFF;
294 	kCFStringEncodingMacRoman = 0;
295 	kCFStringEncodingWindowsLatin1 = $0500; {  ANSI codepage 1252  }
296 	kCFStringEncodingISOLatin1 = $0201; {  ISO 8859-1  }
297 	kCFStringEncodingNextStepLatin = $0B01; {  NextStep encoding }
298 	kCFStringEncodingASCII = $0600; {  0..127 (in creating CFString, values greater than 0x7F are treated as corresponding Unicode value)  }
299 	kCFStringEncodingUnicode = $0100; {  kTextEncodingUnicodeDefault  + kTextEncodingDefaultFormat (aka kUnicode16BitFormat)  }
300 	kCFStringEncodingUTF8 = $08000100; {  kTextEncodingUnicodeDefault + kUnicodeUTF8Format  }
301 	kCFStringEncodingNonLossyASCII = $0BFF; {  7bit Unicode variants used by YellowBox & Java  }
302 {#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4}
303 	kCFStringEncodingUTF16 = $0100; { kTextEncodingUnicodeDefault + kUnicodeUTF16Format (alias of kCFStringEncodingUnicode) }
304 	kCFStringEncodingUTF16BE = $10000100; { kTextEncodingUnicodeDefault + kUnicodeUTF16BEFormat }
305 	kCFStringEncodingUTF16LE = $14000100; { kTextEncodingUnicodeDefault + kUnicodeUTF16LEFormat }
306 
307 	kCFStringEncodingUTF32 = $0C000100; { kTextEncodingUnicodeDefault + kUnicodeUTF32Format }
308 	kCFStringEncodingUTF32BE = $18000100; { kTextEncodingUnicodeDefault + kUnicodeUTF32BEFormat }
309 	kCFStringEncodingUTF32LE = $1C000100; { kTextEncodingUnicodeDefault + kUnicodeUTF32LEFormat }
310 {#endif} { MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 }
311 
312 { CFString type ID }
CFStringGetTypeIDnull313 function CFStringGetTypeID: CFTypeID; external name '_CFStringGetTypeID';
314 
315 { CFSTR() allows creation of compile-time constant CFStringRefs; the argument
316 should be a constant C-string.
317 
318 CFSTR(), not being a "Copy" or "Create" function, does not return a new
319 reference for you. So, you should not release the return value. This is
320 much like constant C or Pascal strings --- when you use "hello world"
321 in a program, you do not free it.
322 
323 However, strings returned from CFSTR() can be retained and released in a
324 properly nested fashion, just like any other CF type. That is, if you pass
325 a CFSTR() return value to a function such as SetMenuItemWithCFString(), the
326 function can retain it, then later, when it's done with it, it can release it.
327 
328 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5
329 At this point non-7 bit characters (that is, characters > 127) in CFSTR() are not
330 supported and using them will lead to unpredictable results. This includes escaped
331 (\nnn) characters whose values are > 127. Even if it works for you in testing,
332 it might not work for a user with a different language preference.
333 #else
334 Non-7 bit characters (that is, above 127) in CFSTR() are supported, although care must
335 be taken in dealing with files containing them. If you can trust your editor and tools
336 to deal with non-ASCII characters in the source code, then you can use them directly
337 in CFSTR(); otherwise, you can represent such characters with their escaped octal
338 equivalents in the encoding the compiler will use to interpret them (for instance,
339 O-umlaut is \303\226 in UTF-8). UTF-8 is the recommended encoding here,
340 since it is the default choice with Mac OS X developer tools.
341 #endif
342 
343 }
344 {
345 	*** Pascal Usage of CFSTR et al ***
346 
347 	For Pascal:
348 
349 		To define your own constant CFStrings, call call CFSTRP with a
350 		constant Pascal single-quoted string only, for example
351 		CFSTRP('a constant string').
352 
353 	For MetroWerks Pascal:
354 
355 		Include the CFStringGlue file in your project (it defines the private function,
356 		CFSTRP0, which you should never call directly.
357 
358 		In your uses clause, use CFString and CFStringGlue and whichever PInterface files
359 		defining the constant CFStrings (or define your own using CFSTRP('pascal string')).
360 
361 	For GNU Pascal:
362 
363 		Include the GPCMacros.inc file (for example $I GPCMacros.inc).
364 
365 		In your uses clause, use CFString (and, optionally, CFStringGlue and the
366 		PInterface files defining the constant CFStrings).
367 
368 		You can optionally use CFSTR with a constant double-quoted C String (for example,
369 		CFSTR("a constant C string")) although it will make no difference, but will
370 		result in closer  C source code similarity.
371 
372 	For maximum compatibility in both GPC and MetroWerks Pascal
373 
374 		Include the GPCMacros.inc file in GPC as part of your GPC prefix.
375 
376 		Include the CFStringGlue file in your MW project.
377 
378 		Only ever use CFSTRP with a constant Pascal string.
379 
380 		In your uses clause for a unit, use the CFString, CFStringGlue and any
381 		PInterface files defining any constant CFStrings you need.
382 }
383 
384 {
385 	CFSTR Must only be called with a constant CString
386 }
CFSTRnull387 function CFSTR( c: PChar ): CFStringRef; external name '___CFStringMakeConstantString';
388 {
389 	CFSTRP Must only be called with a constant Pascal String
390 }
CFSTRPnull391 function CFSTRP( c: PChar ): CFStringRef; external name '___CFStringMakeConstantString';
392 
393 {
394 	CFSTRP0 Must only be called with a constant Pascal String terminated with a chr(0)
395 }
CFSTRP0null396 function CFSTRP0( c: PChar ): CFStringRef; external name '___CFStringMakeConstantString';
397 
398 {** Immutable string creation functions **}
399 
400 { Functions to create basic immutable strings. The provided allocator is used for all memory activity in these functions.
401 }
402 
403 { The following four functions copy the provided buffer into CFString's internal storage. }
CFStringCreateWithPascalStringnull404 function CFStringCreateWithPascalString( alloc: CFAllocatorRef; const (*var*) pStr: Str255; encoding: CFStringEncoding ): CFStringRef; external name '_CFStringCreateWithPascalString';
405 
CFStringCreateWithCStringnull406 function CFStringCreateWithCString( alloc: CFAllocatorRef; cStr: ConstCStringPtr; encoding: CFStringEncoding ): CFStringRef; external name '_CFStringCreateWithCString';
407 
408 { The following takes an explicit length, and allows you to specify whether the data is an external format --- that is, whether to pay attention to the BOM character (if any) and do byte swapping if necessary
409 }
CFStringCreateWithBytesnull410 function CFStringCreateWithBytes( alloc: CFAllocatorRef; bytes: UnivPtr; numBytes: CFIndex; encoding: CFStringEncoding; isExternalRepresentation: Boolean ): CFStringRef; external name '_CFStringCreateWithBytes';
411 
CFStringCreateWithCharactersnull412 function CFStringCreateWithCharacters( alloc: CFAllocatorRef; chars: UniCharPtr; numChars: CFIndex ): CFStringRef; external name '_CFStringCreateWithCharacters';
413 
414 { These functions try not to copy the provided buffer. The buffer will be deallocated
415 with the provided contentsDeallocator when it's no longer needed; to not free
416 the buffer, specify kCFAllocatorNull here. As usual, NULL means default allocator.
417 
418 NOTE: Do not count on these buffers as being used by the string;
419 in some cases the CFString might free the buffer and use something else
420 (for instance if it decides to always use Unicode encoding internally).
421 
422 NOTE: If you are not transferring ownership of the buffer to the CFString
423 (for instance, you supplied contentsDeallocator = kCFAllocatorNull), it is your
424 responsibility to assure the buffer does not go away during the lifetime of the string.
425 If the string is retained or copied, its lifetime might extend in ways you cannot
426 predict. So, for strings created with buffers whose lifetimes you cannot
427 guarantee, you need to be extremely careful --- do not hand it out to any
428 APIs which might retain or copy the strings.
429 }
CFStringCreateWithPascalStringNoCopynull430 function CFStringCreateWithPascalStringNoCopy( alloc: CFAllocatorRef; const (*var*) pStr: Str255; encoding: CFStringEncoding; contentsDeallocator: CFAllocatorRef ): CFStringRef; external name '_CFStringCreateWithPascalStringNoCopy';
431 
CFStringCreateWithCStringNoCopynull432 function CFStringCreateWithCStringNoCopy( alloc: CFAllocatorRef; cStr: ConstCStringPtr; encoding: CFStringEncoding; contentsDeallocator: CFAllocatorRef ): CFStringRef; external name '_CFStringCreateWithCStringNoCopy';
433 
434 { The following takes an explicit length, and allows you to specify whether the data is an external format --- that is, whether to pay attention to the BOM character (if any) and do byte swapping if necessary
435 }
CFStringCreateWithBytesNoCopynull436 function CFStringCreateWithBytesNoCopy( alloc: CFAllocatorRef; bytes: UnivPtr; numBytes: CFIndex; encoding: CFStringEncoding; isExternalRepresentation: Boolean; contentsDeallocator: CFAllocatorRef ): CFStringRef; external name '_CFStringCreateWithBytesNoCopy';
437 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
438 
CFStringCreateWithCharactersNoCopynull439 function CFStringCreateWithCharactersNoCopy( alloc: CFAllocatorRef; chars: UniCharPtr; numChars: CFIndex; contentsDeallocator: CFAllocatorRef ): CFStringRef; external name '_CFStringCreateWithCharactersNoCopy';
440 
441 { Create copies of part or all of the string.
442 }
CFStringCreateWithSubstringnull443 function CFStringCreateWithSubstring( alloc: CFAllocatorRef; str: CFStringRef; range: CFRange ): CFStringRef; external name '_CFStringCreateWithSubstring';
444 
CFStringCreateCopynull445 function CFStringCreateCopy( alloc: CFAllocatorRef; theString: CFStringRef ): CFStringRef; external name '_CFStringCreateCopy';
446 
447 { These functions create a CFString from the provided printf-like format string and arguments.
448 }
CFStringCreateWithFormatnull449 function CFStringCreateWithFormat( alloc: CFAllocatorRef; formatOptions: CFDictionaryRef; format: CFStringRef; ... ): CFStringRef; external name '_CFStringCreateWithFormat';
450 
CFStringCreateWithFormatAndArgumentsnull451 function CFStringCreateWithFormatAndArguments( alloc: CFAllocatorRef; formatOptions: CFDictionaryRef; format: CFStringRef; arguments: UnivPtr ): CFStringRef; external name '_CFStringCreateWithFormatAndArguments';
452 
453 { Functions to create mutable strings. "maxLength", if not 0, is a hard bound on the length of the string. If 0, there is no limit on the length.
454 }
CFStringCreateMutablenull455 function CFStringCreateMutable( alloc: CFAllocatorRef; maxLength: CFIndex ): CFMutableStringRef; external name '_CFStringCreateMutable';
456 
CFStringCreateMutableCopynull457 function CFStringCreateMutableCopy( alloc: CFAllocatorRef; maxLength: CFIndex; theString: CFStringRef ): CFMutableStringRef; external name '_CFStringCreateMutableCopy';
458 
459 { This function creates a mutable string that has a developer supplied and directly editable backing store.
460 The string will be manipulated within the provided buffer (if any) until it outgrows capacity; then the
461 externalCharactersAllocator will be consulted for more memory. When the CFString is deallocated, the
462 buffer will be freed with the externalCharactersAllocator. Provide kCFAllocatorNull here to prevent the buffer
463 from ever being reallocated or deallocated by CFString. See comments at top of this file for more info.
464 }
CFStringCreateMutableWithExternalCharactersNoCopynull465 function CFStringCreateMutableWithExternalCharactersNoCopy( alloc: CFAllocatorRef; chars: UniCharPtr; numChars: CFIndex; capacity: CFIndex; externalCharactersAllocator: CFAllocatorRef ): CFMutableStringRef; external name '_CFStringCreateMutableWithExternalCharactersNoCopy';
466 
467 {** Basic accessors for the contents **}
468 
469 { Number of 16-bit Unicode characters in the string.
470 }
CFStringGetLengthnull471 function CFStringGetLength( theString: CFStringRef ): CFIndex; external name '_CFStringGetLength';
472 
473 { Extracting the contents of the string. For obtaining multiple characters, calling
474 CFStringGetCharacters() is more efficient than multiple calls to CFStringGetCharacterAtIndex().
475 If the length of the string is not known (so you can't use a fixed size buffer for CFStringGetCharacters()),
476 another method is to use is CFStringGetCharacterFromInlineBuffer() (see further below).
477 }
CFStringGetCharacterAtIndexnull478 function CFStringGetCharacterAtIndex( theString: CFStringRef; idx: CFIndex ): UniChar; external name '_CFStringGetCharacterAtIndex';
479 
480 procedure CFStringGetCharacters( theString: CFStringRef; range: CFRange; buffer: UniCharPtr ); external name '_CFStringGetCharacters';
481 
482 
483 {** Conversion to other encodings **}
484 
485 { These two convert into the provided buffer; they return false if conversion isn't possible
486 (due to conversion error, or not enough space in the provided buffer).
487 These functions do zero-terminate or put the length byte; the provided bufferSize should include
488 space for this (so pass 256 for Str255). More sophisticated usages can go through CFStringGetBytes().
489 These functions are equivalent to calling CFStringGetBytes() with
490 the range of the string; lossByte = 0; and isExternalRepresentation = false;
491 if successful, they then insert the leading length or terminating zero, as desired.
492 }
CFStringGetPascalStringnull493 function CFStringGetPascalString( theString: CFStringRef; buffer: StringPtr; bufferSize: CFIndex; encoding: CFStringEncoding ): Boolean; external name '_CFStringGetPascalString';
494 
CFStringGetCStringnull495 function CFStringGetCString( theString: CFStringRef; buffer: CStringPtr; bufferSize: CFIndex; encoding: CFStringEncoding ): Boolean; external name '_CFStringGetCString';
496 
497 
498 { These functions attempt to return in O(1) time the desired format for the string.
499 Note that although this means a pointer to the internal structure is being returned,
500 this can't always be counted on. Please see note at the top of the file for more
501 details.
502 }
CFStringGetPascalStringPtrnull503 function CFStringGetPascalStringPtr( theString: CFStringRef; encoding: CFStringEncoding ): ConstStringPtr; external name '_CFStringGetPascalStringPtr'; { May return NULL at any time; be prepared for NULL }
504 
CFStringGetCStringPtrnull505 function CFStringGetCStringPtr( theString: CFStringRef; encoding: CFStringEncoding ): ConstCStringPtr; external name '_CFStringGetCStringPtr'; { May return NULL at any time; be prepared for NULL }
506 
CFStringGetCharactersPtrnull507 function CFStringGetCharactersPtr( theString: CFStringRef ): UniCharPtr; external name '_CFStringGetCharactersPtr'; { May return NULL at any time; be prepared for NULL }
508 
509 { The primitive conversion routine; allows you to convert a string piece at a time
510        into a fixed size buffer. Returns number of characters converted.
511    Characters that cannot be converted to the specified encoding are represented
512        with the byte specified by lossByte; if lossByte is 0, then lossy conversion
513        is not allowed and conversion stops, returning partial results.
514    Pass buffer==NULL if you don't care about the converted string (but just the convertability,
515        or number of bytes required).
516    maxBufLength indicates the maximum number of bytes to generate. It is ignored when buffer==NULL.
517    Does not zero-terminate. If you want to create Pascal or C string, allow one extra byte at start or end.
518    Setting isExternalRepresentation causes any extra bytes that would allow
519        the data to be made persistent to be included; for instance, the Unicode BOM. Note that
520        CFString prepends UTF encoded data with the Unicode BOM <http://www.unicode.org/faq/utf_bom.html>
521        when generating external representation if the target encoding allows. It's important to note that
522        only UTF-8, UTF-16, and UTF-32 define the handling of the byte order mark character, and the "LE"
523        and "BE" variants of UTF-16 and UTF-32 don't.
524 }
CFStringGetBytesnull525 function CFStringGetBytes( theString: CFStringRef; range: CFRange; encoding: CFStringEncoding; lossByte: ByteParameter; isExternalRepresentation: Boolean; buffer: UInt8Ptr; maxBufLen: CFIndex; var usedBufLen: CFIndex ): CFIndex; external name '_CFStringGetBytes';
526 
527 { Convenience functions String <-> Data. These generate "external" formats, that is, formats that
528    can be written out to disk. For instance, if the encoding is Unicode,
529    CFStringCreateFromExternalRepresentation() pays attention to the BOM character (if any)
530    and does byte swapping if necessary. Similarly CFStringCreateExternalRepresentation() will
531    include a BOM character if appropriate. See CFStringGetBytes() for more on this and lossByte.
532 }
CFStringCreateFromExternalRepresentationnull533 function CFStringCreateFromExternalRepresentation( alloc: CFAllocatorRef; data: CFDataRef; encoding: CFStringEncoding ): CFStringRef; external name '_CFStringCreateFromExternalRepresentation';	{ May return NULL on conversion error }
534 
CFStringCreateExternalRepresentationnull535 function CFStringCreateExternalRepresentation( alloc: CFAllocatorRef; theString: CFStringRef; encoding: CFStringEncoding; lossByte: ByteParameter ): CFDataRef; external name '_CFStringCreateExternalRepresentation'; { May return NULL on conversion error }
536 
537 { Hints about the contents of a string
538 }
CFStringGetSmallestEncodingnull539 function CFStringGetSmallestEncoding( theString: CFStringRef ): CFStringEncoding; external name '_CFStringGetSmallestEncoding';	{ Result in O(n) time max }
540 
CFStringGetFastestEncodingnull541 function CFStringGetFastestEncoding( theString: CFStringRef ): CFStringEncoding; external name '_CFStringGetFastestEncoding';	{ Result in O(1) time max }
542 
543 { General encoding info
544 }
CFStringGetSystemEncodingnull545 function CFStringGetSystemEncoding: CFStringEncoding; external name '_CFStringGetSystemEncoding';		{ The default encoding for the system; untagged 8-bit characters are usually in this encoding }
546 
CFStringGetMaximumSizeForEncodingnull547 function CFStringGetMaximumSizeForEncoding( length: CFIndex; encoding: CFStringEncoding ): CFIndex; external name '_CFStringGetMaximumSizeForEncoding'; { Max bytes a string of specified length (in UniChars) will take up if encoded }
548 
549 
550 {** FileSystem path conversion functions **}
551 
552 { Extract the contents of the string as a NULL-terminated 8-bit string appropriate for passing to POSIX APIs (for example, normalized for HFS+).  The string is zero-terminated. false will be returned if the conversion results don't fit into the buffer.  Use CFStringGetMaximumSizeOfFileSystemRepresentation() if you want to make sure the buffer is of sufficient length.
553 }
CFStringGetFileSystemRepresentationnull554 function CFStringGetFileSystemRepresentation( strng: CFStringRef; buffer: CStringPtr; maxBufLen: CFIndex ): Boolean; external name '_CFStringGetFileSystemRepresentation';
555 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
556 
557 { Get the upper bound on the number of bytes required to hold the file system representation for the string. This result is returned quickly as a very rough approximation, and could be much larger than the actual space required. The result includes space for the zero termination. If you are allocating a buffer for long-term keeping, it's recommended that you reallocate it smaller (to be the right size) after calling CFStringGetFileSystemRepresentation().
558 }
CFStringGetMaximumSizeOfFileSystemRepresentationnull559 function CFStringGetMaximumSizeOfFileSystemRepresentation( strng: CFStringRef ): CFIndex; external name '_CFStringGetMaximumSizeOfFileSystemRepresentation';
560 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
561 
562 { Create a CFString from the specified zero-terminated POSIX file system representation.  If the conversion fails (possible due to bytes in the buffer not being a valid sequence of bytes for the appropriate character encoding), NULL is returned.
563 }
CFStringCreateWithFileSystemRepresentationnull564 function CFStringCreateWithFileSystemRepresentation( alloc: CFAllocatorRef; buffer: ConstCStringPtr ): CFStringRef; external name '_CFStringCreateWithFileSystemRepresentation';
565 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
566 
567 
568 {** Comparison functions. **}
569 
570 { Find and compare flags; these are OR'ed together and provided as CFStringCompareFlags in the various functions.
571 }
572 type
573 	CFStringCompareFlags = CFOptionFlags;
574 const
575 																{  Flags used in all find and compare operations  }
576 	kCFCompareCaseInsensitive = 1;
577 	kCFCompareBackwards = 4;							{  Starting from the end of the string  }
578 	kCFCompareAnchored = 8;							{  Only at the specified starting point  }
579 	kCFCompareNonliteral = 16;							{  If specified, loose equivalence is performed (o-umlaut == o, umlaut)  }
580 	kCFCompareLocalized = 32;							{  User's default locale is used for the comparisons  }
581 	kCFCompareNumerically = 64;							{  Numeric comparison is used; that is, Foo2.txt < Foo7.txt < Foo25.txt  }
582 	kCFCompareDiacriticInsensitive = 128; (* CF_AVAILABLE_STARTING(10_5, 2_0) *) { If specified, ignores diacritics (o-umlaut == o) }
583 	kCFCompareWidthInsensitive = 256; (* CF_AVAILABLE_STARTING(10_5, 2_0) *) { If specified, ignores width differences ('a' == UFF41) }
584 	kCFCompareForcedOrdering = 512; (* CF_AVAILABLE_STARTING(10_5, 2_0) *) { If specified, comparisons are forced to return either kCFCompareLessThan or kCFCompareGreaterThan if the strings are equivalent but not strictly equal, for stability when sorting (e.g. "aaa" > "AAA" with kCFCompareCaseInsensitive specified) }
585 
586 { The main comparison routine; compares specified range of the first string to (the full range of) the second string.
587 locale == NULL indicates canonical locale (the return value from CFLocaleGetSystem()).
588 kCFCompareNumerically, added in 10.2, does not work if kCFCompareLocalized is specified on systems before 10.3
589 kCFCompareBackwards and kCFCompareAnchored are not applicable.
590 }
CFStringCompareWithOptionsAndLocalenull591 function CFStringCompareWithOptionsAndLocale( theString1: CFStringRef; theString2: CFStringRef; rangeToCompare: CFRange; compareOptions: CFStringCompareFlags; locale: CFLocaleRef ): CFComparisonResult; external name '_CFStringCompareWithOptionsAndLocale';
592 (* CF_AVAILABLE_STARTING(10_5, 2_0) *)
593 
594 { Comparison convenience. Uses the current user locale (the return value from CFLocaleCopyCurrent()) if kCFCompareLocalized.
595 }
CFStringCompareWithOptionsnull596 function CFStringCompareWithOptions( theString1: CFStringRef; theString2: CFStringRef; rangeToCompare: CFRange; compareOptions: CFStringCompareFlags ): CFComparisonResult; external name '_CFStringCompareWithOptions';
597 
598 { Comparison convenience suitable for passing as sorting functions.
599    kCFCompareNumerically, added in 10.2, does not work if kCFCompareLocalized is specified on systems before 10.3
600    kCFCompareBackwards and kCFCompareAnchored are not applicable.
601 }
CFStringComparenull602 function CFStringCompare( theString1: CFStringRef; theString2: CFStringRef; compareOptions: CFStringCompareFlags ): CFComparisonResult; external name '_CFStringCompare';
603 
604 { CFStringFindWithOptionsAndLocale() returns the found range in the CFRange * argument; you can pass NULL for simple discovery check.
605  locale == NULL indicates canonical locale (the return value from CFLocaleGetSystem()).
606  If stringToFind is the empty string (zero length), nothing is found.
607  Ignores the kCFCompareNumerically option.
608 }
CFStringFindWithOptionsAndLocalenull609 function CFStringFindWithOptionsAndLocale( theString: CFStringRef; stringToFind: CFStringRef; rangeToSearch: CFRange; searchOptions: CFStringCompareFlags; locale: CFLocaleRef; var result: CFRange ): Boolean; external name '_CFStringFindWithOptionsAndLocale';
610 (* CF_AVAILABLE_STARTING(10_5, 2_0) *)
611 
612 { Find convenience. Uses the current user locale (the return value from CFLocaleCopyCurrent()) if kCFCompareLocalized.
613 }
CFStringFindWithOptionsnull614 function CFStringFindWithOptions( theString: CFStringRef; stringToFind: CFStringRef; rangeToSearch: CFRange; searchOptions: CFStringCompareFlags; var result: CFRange ): Boolean; external name '_CFStringFindWithOptions';
615 
616 { CFStringCreateArrayWithFindResults() returns an array of CFRange pointers, or NULL if there are no matches.
617    Overlapping instances are not found; so looking for "AA" in "AAA" finds just one range.
618    Post 10.1: If kCFCompareBackwards is provided, the scan is done from the end (which can give a different result), and
619       the results are stored in the array backwards (last found range in slot 0).
620    If stringToFind is the empty string (zero length), nothing is found.
621    kCFCompareAnchored causes just the consecutive instances at start (or end, if kCFCompareBackwards) to be reported. So, searching for "AB" in "ABABXAB..." you just get the first two occurrences.
622    Ignores the kCFCompareNumerically option.
623 }
CFStringCreateArrayWithFindResultsnull624 function CFStringCreateArrayWithFindResults( alloc: CFAllocatorRef; theString: CFStringRef; stringToFind: CFStringRef; rangeToSearch: CFRange; compareOptions: CFStringCompareFlags ): CFArrayRef; external name '_CFStringCreateArrayWithFindResults';
625 
626 { Find conveniences; see comments above concerning empty string and options.
627 }
CFStringFindnull628 function CFStringFind( theString: CFStringRef; stringToFind: CFStringRef; compareOptions: CFStringCompareFlags ): CFRange; external name '_CFStringFind';
629 
CFStringHasPrefixnull630 function CFStringHasPrefix( theString: CFStringRef; prefix: CFStringRef ): Boolean; external name '_CFStringHasPrefix';
631 
CFStringHasSuffixnull632 function CFStringHasSuffix( theString: CFStringRef; suffix: CFStringRef ): Boolean; external name '_CFStringHasSuffix';
633 
634 {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
635 {!
636 	@function CFStringGetRangeOfComposedCharactersAtIndex
637 	Returns the range of the composed character sequence at the specified index.
638 	@param theString The CFString which is to be searched.  If this
639                 		parameter is not a valid CFString, the behavior is
640               		undefined.
641 	@param theIndex The index of the character contained in the
642 			composed character sequence.  If the index is
643 			outside the index space of the string (0 to N-1 inclusive,
644 			where N is the length of the string), the behavior is
645 			undefined.
646 	@result The range of the composed character sequence.
647 }
CFStringGetRangeOfComposedCharactersAtIndexnull648 function CFStringGetRangeOfComposedCharactersAtIndex( theString: CFStringRef; theIndex: CFIndex ): CFRange; external name '_CFStringGetRangeOfComposedCharactersAtIndex';
649 
650 {!
651 	@function CFStringFindCharacterFromSet
652 	Query the range of the first character contained in the specified character set.
653 	@param theString The CFString which is to be searched.  If this
654                 		parameter is not a valid CFString, the behavior is
655               		undefined.
656 	@param theSet The CFCharacterSet against which the membership
657 			of characters is checked.  If this parameter is not a valid
658 			CFCharacterSet, the behavior is undefined.
659 	@param range The range of characters within the string to search. If
660 			the range location or end point (defined by the location
661 			plus length minus 1) are outside the index space of the
662 			string (0 to N-1 inclusive, where N is the length of the
663 			string), the behavior is undefined. If the range length is
664 			negative, the behavior is undefined. The range may be empty
665 			(length 0), in which case no search is performed.
666 	@param searchOptions The bitwise-or'ed option flags to control
667 			the search behavior.  The supported options are
668 			kCFCompareBackwards andkCFCompareAnchored.
669 			If other option flags are specified, the behavior
670                         is undefined.
671 	@param result The pointer to a CFRange supplied by the caller in
672 			which the search result is stored.  Note that the length
673 			of this range can be more than 1, if for instance the
674 			result is a composed character. If a pointer to an invalid
675 			memory is specified, the behavior is undefined.
676 	@result true, if at least a character which is a member of the character
677 			set is found and result is filled, otherwise, false.
678 }
CFStringFindCharacterFromSetnull679 function CFStringFindCharacterFromSet( theString: CFStringRef; theSet: CFCharacterSetRef; rangeToSearch: CFRange; searchOptions: CFOptionFlags; var result: CFRange ): Boolean; external name '_CFStringFindCharacterFromSet';
680 {#endif}
681 
682 { Find range of bounds of the line(s) that span the indicated range (startIndex, numChars),
683    taking into account various possible line separator sequences (CR, CRLF, LF, and Unicode NextLine, LineSeparator, ParagraphSeparator).
684    All return values are "optional" (provide NULL if you don't want them)
685      lineBeginIndex: index of first character in line
686      lineEndIndex: index of first character of the next line (including terminating line separator characters)
687      contentsEndIndex: index of the first line separator character
688    Thus, lineEndIndex - lineBeginIndex is the number of chars in the line, including the line separators
689          contentsEndIndex - lineBeginIndex is the number of chars in the line w/out the line separators
690 }
691 procedure CFStringGetLineBounds( theString: CFStringRef; range: CFRange; var lineBeginIndex: CFIndex; var lineEndIndex: CFIndex; var contentsEndIndex: CFIndex ); external name '_CFStringGetLineBounds';
692 
693 { Same as CFStringGetLineBounds(), however, will only look for paragraphs. Won't stop at Unicode NextLine or LineSeparator characters.
694 }
695 procedure CFStringGetParagraphBounds( strng: CFStringRef; range: CFRange; var parBeginIndex: CFIndex; var parEndIndex: CFIndex; var contentsEndIndex: CFIndex ); external name '_CFStringGetParagraphBounds';
696 (* CF_AVAILABLE_STARTING(10_5, 2_0) *)
697 
698 {!
699 	@function CFStringGetHyphenationLocationBeforeIndex
700 	Retrieve the first potential hyphenation location found before the specified location.
701 	@param string The CFString which is to be hyphenated.  If this
702                 		parameter is not a valid CFString, the behavior is
703               		undefined.
704 	@param location An index in the string.  If a valid hyphen index is returned, it
705 	                will be before this index.
706 	@param limitRange The range of characters within the string to search. If
707 			the range location or end point (defined by the location
708 			plus length minus 1) are outside the index space of the
709 			string (0 to N-1 inclusive, where N is the length of the
710 			string), the behavior is undefined. If the range length is
711 			negative, the behavior is undefined. The range may be empty
712 			(length 0), in which case no hyphen location is generated.
713 	@param options Reserved for future use.
714 	@param locale Specifies which language's hyphenation conventions to use.
715 			This must be a valid locale.  Hyphenation data is not available
716 			for all locales.  You can use CFStringIsHyphenationAvailableForLocale
717 			to test for availability of hyphenation data.
718 	@param character The suggested hyphen character to insert.  Pass NULL if you
719 			do not need this information.
720 	@result an index in the string where it is appropriate to insert a hyphen, if
721 			one exists; else kCFNotFound
722 }
CFStringGetHyphenationLocationBeforeIndexnull723 function CFStringGetHyphenationLocationBeforeIndex( strng: CFStringRef; location: CFIndex; limitRange: CFRange; options: CFOptionFlags; locale: CFLocaleRef; character { may be null}: UTF32CharPtr ): CFIndex; external name '_CFStringGetHyphenationLocationBeforeIndex';
724 (* CF_AVAILABLE_STARTING(10_7, 4_2) *)
725 
CFStringIsHyphenationAvailableForLocalenull726 function CFStringIsHyphenationAvailableForLocale( locale: CFLocaleRef ): Boolean; external name '_CFStringIsHyphenationAvailableForLocale';
727 (* CF_AVAILABLE_STARTING(10_7, 4_3) *)
728 
729 {** Exploding and joining strings with a separator string **}
730 
CFStringCreateByCombiningStringsnull731 function CFStringCreateByCombiningStrings( alloc: CFAllocatorRef; theArray: CFArrayRef; separatorString: CFStringRef ): CFStringRef; external name '_CFStringCreateByCombiningStrings';	{ Empty array returns empty string; one element array returns the element }
732 
CFStringCreateArrayBySeparatingStringsnull733 function CFStringCreateArrayBySeparatingStrings( alloc: CFAllocatorRef; theString: CFStringRef; separatorString: CFStringRef ): CFArrayRef; external name '_CFStringCreateArrayBySeparatingStrings';	{ No separators in the string returns array with that string; string == sep returns two empty strings }
734 
735 
736 {** Parsing non-localized numbers from strings **}
737 
CFStringGetIntValuenull738 function CFStringGetIntValue( str: CFStringRef ): SInt32; external name '_CFStringGetIntValue';		{ Skips whitespace; returns 0 on error, MAX or -MAX on overflow }
739 
CFStringGetDoubleValuenull740 function CFStringGetDoubleValue( str: CFStringRef ): Float64; external name '_CFStringGetDoubleValue';	{ Skips whitespace; returns 0.0 on error }
741 
742 
743 {** MutableString functions **}
744 
745 { CFStringAppend("abcdef", "xxxxx") -> "abcdefxxxxx"
746    CFStringDelete("abcdef", CFRangeMake(2, 3)) -> "abf"
747    CFStringReplace("abcdef", CFRangeMake(2, 3), "xxxxx") -> "abxxxxxf"
748    CFStringReplaceAll("abcdef", "xxxxx") -> "xxxxx"
749 }
750 procedure CFStringAppend( theString: CFMutableStringRef; appendedString: CFStringRef ); external name '_CFStringAppend';
751 
752 procedure CFStringAppendCharacters( theString: CFMutableStringRef; chars: UniCharPtr; numChars: CFIndex ); external name '_CFStringAppendCharacters';
753 
754 procedure CFStringAppendPascalString( theString: CFMutableStringRef; const (*var*) pStr: Str255; encoding: CFStringEncoding ); external name '_CFStringAppendPascalString';
755 
756 procedure CFStringAppendCString( theString: CFMutableStringRef; cStr: ConstCStringPtr; encoding: CFStringEncoding ); external name '_CFStringAppendCString';
757 
758 procedure CFStringAppendFormat( theString: CFMutableStringRef; formatOptions: CFDictionaryRef; format: CFStringRef; ... ); external name '_CFStringAppendFormat';
759 
760 procedure CFStringAppendFormatAndArguments( theString: CFMutableStringRef; formatOptions: CFDictionaryRef; format: CFStringRef; arguments: UnivPtr ); external name '_CFStringAppendFormatAndArguments';
761 
762 procedure CFStringInsert( str: CFMutableStringRef; idx: CFIndex; insertedStr: CFStringRef ); external name '_CFStringInsert';
763 
764 procedure CFStringDelete( theString: CFMutableStringRef; range: CFRange ); external name '_CFStringDelete';
765 
766 procedure CFStringReplace( theString: CFMutableStringRef; range: CFRange; replacement: CFStringRef ); external name '_CFStringReplace';
767 
768 procedure CFStringReplaceAll( theString: CFMutableStringRef; replacement: CFStringRef ); external name '_CFStringReplaceAll';	{ Replaces whole string }
769 
770 {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
771 { Replace all occurrences of target in rangeToSearch of theString with replacement.
772    Pays attention to kCFCompareCaseInsensitive, kCFCompareBackwards, kCFCompareNonliteral, and kCFCompareAnchored.
773    kCFCompareBackwards can be used to do the replacement starting from the end, which could give a different result.
774      ex. AAAAA, replace AA with B -> BBA or ABB; latter if kCFCompareBackwards
775    kCFCompareAnchored assures only anchored but multiple instances are found (the instances must be consecutive at start or end)
776      ex. AAXAA, replace A with B -> BBXBB or BBXAA; latter if kCFCompareAnchored
777    Returns number of replacements performed.
778 }
CFStringFindAndReplacenull779 function CFStringFindAndReplace( theString: CFMutableStringRef; stringToFind: CFStringRef; replacementString: CFStringRef; rangeToSearch: CFRange; compareOptions: CFStringCompareFlags ): CFIndex; external name '_CFStringFindAndReplace';
780 
781 {#endif}
782 
783 { This function will make the contents of a mutable CFString point directly at the specified UniChar array.
784    It works only with CFStrings created with CFStringCreateMutableWithExternalCharactersNoCopy().
785    This function does not free the previous buffer.
786    The string will be manipulated within the provided buffer (if any) until it outgrows capacity; then the
787      externalCharactersAllocator will be consulted for more memory.
788    See comments at the top of this file for more info.
789 }
790 procedure CFStringSetExternalCharactersNoCopy( theString: CFMutableStringRef; chars: UniCharPtr; length: CFIndex; capacity: CFIndex ); external name '_CFStringSetExternalCharactersNoCopy'; { Works only on specially created mutable strings! }
791 
792 { CFStringPad() will pad or cut down a string to the specified size.
793    The pad string is used as the fill string; indexIntoPad specifies which character to start with.
794      CFStringPad("abc", " ", 9, 0) ->  "abc      "
795      CFStringPad("abc", ". ", 9, 1) -> "abc . . ."
796      CFStringPad("abcdef", ?, 3, ?) -> "abc"
797 
798      CFStringTrim() will trim the specified string from both ends of the string.
799      CFStringTrimWhitespace() will do the same with white space characters (tab, newline, etc)
800      CFStringTrim("  abc ", " ") -> "abc"
801      CFStringTrim("* * * *abc * ", "* ") -> "*abc "
802 }
803 procedure CFStringPad( theString: CFMutableStringRef; padString: CFStringRef; length: CFIndex; indexIntoPad: CFIndex ); external name '_CFStringPad';
804 
805 procedure CFStringTrim( theString: CFMutableStringRef; trimString: CFStringRef ); external name '_CFStringTrim';
806 
807 procedure CFStringTrimWhitespace( theString: CFMutableStringRef ); external name '_CFStringTrimWhitespace';
808 
809 {#if MAC_OS_X_VERSION_10_3 <= MAC_OS_X_VERSION_MAX_ALLOWED}
810 procedure CFStringLowercase( theString: CFMutableStringRef; locale: CFLocaleRef ); external name '_CFStringLowercase';
811 
812 procedure CFStringUppercase( theString: CFMutableStringRef; locale: CFLocaleRef ); external name '_CFStringUppercase';
813 
814 procedure CFStringCapitalize( theString: CFMutableStringRef; locale: CFLocaleRef ); external name '_CFStringCapitalize';
815 {#else}
816 //procedure CFStringLowercase( theString: CFMutableStringRef; localeTBD: {const} UnivPtr ); // localeTBD must be NULL on pre-10.3
817 
818 //procedure CFStringUppercase( theString: CFMutableStringRef; localeTBD: {const} UnivPtr ); // localeTBD must be NULL on pre-10.3
819 
820 //procedure CFStringCapitalize( theString: CFMutableStringRef; localeTBD: {const} UnivPtr ); // localeTBD must be NULL on pre-10.3
821 {#endif}
822 
823 {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
824 {!
825 	@typedef CFStringNormalizationForm
826 	This is the type of Unicode normalization forms as described in
827 	Unicode Technical Report #15. To normalize for use with file
828 	system calls, use CFStringGetFileSystemRepresentation().
829 }
830 type
831 	CFStringNormalizationForm = CFIndex;
832 const
833 	kCFStringNormalizationFormD = 0; // Canonical Decomposition
834 	kCFStringNormalizationFormKD = 1; // Compatibility Decomposition
835 	kCFStringNormalizationFormC = 2; // Canonical Decomposition followed by Canonical Composition
836 	kCFStringNormalizationFormKC = 3; // Compatibility Decomposition followed by Canonical Composition
837 
838 {!
839 	@function CFStringNormalize
840 	Normalizes the string into the specified form as described in
841 	Unicode Technical Report #15.
842 	@param theString  The string which is to be normalized.  If this
843 		parameter is not a valid mutable CFString, the behavior is
844 		undefined.
845 	@param theForm  The form into which the string is to be normalized.
846 		If this parameter is not a valid CFStringNormalizationForm value,
847 		the behavior is undefined.
848 }
849 procedure CFStringNormalize( theString: CFMutableStringRef; theForm: CFStringNormalizationForm ); external name '_CFStringNormalize';
850 {#endif}
851 
852 {#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED}
853 {!
854 	@function CFStringFold
855 	Folds the string into the form specified by the flags.
856 		Character foldings are operations that convert any of a set of characters
857 		sharing similar semantics into a single representative from that set.
858 		This function can be used to preprocess strings that are to be compared,
859 		searched, or indexed.
860 		Note that folding does not include normalization, so it is necessary
861 		to use CFStringNormalize in addition to CFStringFold in order to obtain
862 		the effect of kCFCompareNonliteral.
863 	@param theString  The string which is to be folded.  If this parameter is not
864 		a valid mutable CFString, the behavior is undefined.
865 	@param theFlag  The equivalency flags which describes the character folding form.
866 		Only those flags containing the word "insensitive" are recognized here; other flags are ignored.
867 		Folding with kCFCompareCaseInsensitive removes case distinctions in accordance with the mapping
868 		specified by ftp://ftp.unicode.org/Public/UNIDATA/CaseFolding.txt.  Folding with
869 		kCFCompareDiacriticInsensitive removes distinctions of accents and other diacritics.  Folding
870 		with kCFCompareWidthInsensitive removes character width distinctions by mapping characters in
871 		the range U+FF00-U+FFEF to their ordinary equivalents.
872 	@param theLocale The locale tailoring the character folding behavior. If NULL,
873 		it's considered to be the system locale returned from CFLocaleGetSystem().
874 		If non-NULL and not a valid CFLocale object, the behavior is undefined.
875 }
876 
877 procedure CFStringFold( theString: CFMutableStringRef; theFlags: CFOptionFlags; theLocale: CFLocaleRef ); external name '_CFStringFold';
878 (* CF_AVAILABLE_STARTING(10_5, 2_0) *)
879 {#endif MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED }
880 
881 
882 { Perform string transliteration.  The transformation represented by transform is applied to the given range of string, modifying it in place. Only the specified range will be modified, but the transform may look at portions of the string outside that range for context. NULL range pointer causes the whole string to be transformed. On return, range is modified to reflect the new range corresponding to the original range. reverse indicates that the inverse transform should be used instead, if it exists. If the transform is successful, true is returned; if unsuccessful, false. Reasons for the transform being unsuccessful include an invalid transform identifier, or attempting to reverse an irreversible transform.
883 
884 You can pass one of the predefined transforms below, or any valid ICU transform ID as defined in the ICU User Guide. Note that we do not support arbitrary set of ICU transform rules.
885 }
CFStringTransformnull886 function CFStringTransform( strng: CFMutableStringRef; var range: CFRange; transform: CFStringRef; reverse: Boolean ): Boolean; external name '_CFStringTransform';
887 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
888 
889 { Transform identifiers for CFStringTransform()
890 }
891 var kCFStringTransformStripCombiningMarks: CFStringRef; external name '_kCFStringTransformStripCombiningMarks'; (* attribute const *)
892 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
893 var kCFStringTransformToLatin: CFStringRef; external name '_kCFStringTransformToLatin'; (* attribute const *)
894 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
895 var kCFStringTransformFullwidthHalfwidth: CFStringRef; external name '_kCFStringTransformFullwidthHalfwidth'; (* attribute const *)
896 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
897 var kCFStringTransformLatinKatakana: CFStringRef; external name '_kCFStringTransformLatinKatakana'; (* attribute const *)
898 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
899 var kCFStringTransformLatinHiragana: CFStringRef; external name '_kCFStringTransformLatinHiragana'; (* attribute const *)
900 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
901 var kCFStringTransformHiraganaKatakana: CFStringRef; external name '_kCFStringTransformHiraganaKatakana'; (* attribute const *)
902 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
903 var kCFStringTransformMandarinLatin: CFStringRef; external name '_kCFStringTransformMandarinLatin'; (* attribute const *)
904 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
905 var kCFStringTransformLatinHangul: CFStringRef; external name '_kCFStringTransformLatinHangul'; (* attribute const *)
906 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
907 var kCFStringTransformLatinArabic: CFStringRef; external name '_kCFStringTransformLatinArabic'; (* attribute const *)
908 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
909 var kCFStringTransformLatinHebrew: CFStringRef; external name '_kCFStringTransformLatinHebrew'; (* attribute const *)
910 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
911 var kCFStringTransformLatinThai: CFStringRef; external name '_kCFStringTransformLatinThai'; (* attribute const *)
912 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
913 var kCFStringTransformLatinCyrillic: CFStringRef; external name '_kCFStringTransformLatinCyrillic'; (* attribute const *)
914 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
915 var kCFStringTransformLatinGreek: CFStringRef; external name '_kCFStringTransformLatinGreek'; (* attribute const *)
916 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
917 var kCFStringTransformToXMLHex: CFStringRef; external name '_kCFStringTransformToXMLHex'; (* attribute const *)
918 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
919 var kCFStringTransformToUnicodeName: CFStringRef; external name '_kCFStringTransformToUnicodeName'; (* attribute const *)
920 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
921 var kCFStringTransformStripDiacritics: CFStringRef; external name '_kCFStringTransformStripDiacritics'; (* attribute const *)
922 (* CF_AVAILABLE_STARTING(10_5, 2_0) *)
923 
924 
925 {** General encoding related functionality **}
926 
927 { This returns availability of the encoding on the system
928 }
CFStringIsEncodingAvailablenull929 function CFStringIsEncodingAvailable( encoding: CFStringEncoding ): Boolean; external name '_CFStringIsEncodingAvailable';
930 
931 { This function returns list of available encodings.  The returned list is terminated with kCFStringEncodingInvalidId and owned by the system.
932 }
CFStringGetListOfAvailableEncodingsnull933 function CFStringGetListOfAvailableEncodings: CFStringEncodingPtr; external name '_CFStringGetListOfAvailableEncodings';
934 
935 { Returns name of the encoding; non-localized.
936 }
CFStringGetNameOfEncodingnull937 function CFStringGetNameOfEncoding( encoding: CFStringEncoding ): CFStringRef; external name '_CFStringGetNameOfEncoding';
938 
939 { ID mapping functions from/to Cocoa NSStringEncoding.  Returns kCFStringEncodingInvalidId if no mapping exists.
940 }
CFStringConvertEncodingToNSStringEncodingnull941 function CFStringConvertEncodingToNSStringEncoding( encoding: CFStringEncoding ): UNSIGNEDLONG; external name '_CFStringConvertEncodingToNSStringEncoding';
942 
CFStringConvertNSStringEncodingToEncodingnull943 function CFStringConvertNSStringEncodingToEncoding( encoding: UNSIGNEDLONG ): CFStringEncoding; external name '_CFStringConvertNSStringEncodingToEncoding';
944 
945 { ID mapping functions from/to Microsoft Windows codepage (covers both OEM & ANSI).  Returns kCFStringEncodingInvalidId if no mapping exists.
946 }
CFStringConvertEncodingToWindowsCodepagenull947 function CFStringConvertEncodingToWindowsCodepage( encoding: CFStringEncoding ): UInt32; external name '_CFStringConvertEncodingToWindowsCodepage';
948 
CFStringConvertWindowsCodepageToEncodingnull949 function CFStringConvertWindowsCodepageToEncoding( codepage: UInt32 ): CFStringEncoding; external name '_CFStringConvertWindowsCodepageToEncoding';
950 
951 { ID mapping functions from/to IANA registery charset names.  Returns kCFStringEncodingInvalidId if no mapping exists.
952 }
CFStringConvertIANACharSetNameToEncodingnull953 function CFStringConvertIANACharSetNameToEncoding( theString: CFStringRef ): CFStringEncoding; external name '_CFStringConvertIANACharSetNameToEncoding';
954 
CFStringConvertEncodingToIANACharSetNamenull955 function CFStringConvertEncodingToIANACharSetName( encoding: CFStringEncoding ): CFStringRef; external name '_CFStringConvertEncodingToIANACharSetName';
956 
957 { Returns the most compatible MacOS script value for the input encoding }
958 { i.e. kCFStringEncodingMacRoman -> kCFStringEncodingMacRoman }
959 {	kCFStringEncodingWindowsLatin1 -> kCFStringEncodingMacRoman }
960 {	kCFStringEncodingISO_2022_JP -> kCFStringEncodingMacJapanese }
CFStringGetMostCompatibleMacStringEncodingnull961 function CFStringGetMostCompatibleMacStringEncoding( encoding: CFStringEncoding ): CFStringEncoding; external name '_CFStringGetMostCompatibleMacStringEncoding';
962 
963 
964 { The next two functions allow fast access to the contents of a string,
965    assuming you are doing sequential or localized accesses. To use, call
966    CFStringInitInlineBuffer() with a CFStringInlineBuffer (on the stack, say),
967    and a range in the string to look at. Then call CFStringGetCharacterFromInlineBuffer()
968    as many times as you want, with a index into that range (relative to the start
969    of that range). These are INLINE functions and will end up calling CFString only
970    once in a while, to fill a buffer.  CFStringGetCharacterFromInlineBuffer() returns 0 if
971    a location outside the original range is specified.
972 }
973 const
974 	__kCFStringInlineBufferLength = 64;
975 type
976 	CFStringInlineBuffer = record
977 		buffer: array[0..__kCFStringInlineBufferLength-1] of UniChar;
978 		theString: CFStringRef;
979 		directBuffer: UniCharPtr;
980 		rangeToBuffer: CFRange;		{ Range in string to buffer }
981 		bufferedRangeStart: CFIndex;		{ Start of range currently buffered (relative to rangeToBuffer.location) }
982 		bufferedRangeEnd: CFIndex;		{ bufferedRangeStart + number of chars actually buffered }
983 	end;
984 
985 // Not currently converted to Pascal
986 // #if defined(CF_INLINE)
987 // CF_INLINE void CFStringInitInlineBuffer(CFStringRef str, CFStringInlineBuffer *buf, CFRange range) {
988 //     buf->theString = str;
989 //     buf->rangeToBuffer = range;
990 //     buf->directBuffer = CFStringGetCharactersPtr(str);
991 //     buf->bufferedRangeStart = buf->bufferedRangeEnd = 0;
992 // }
993 //
994 // CF_INLINE UniChar CFStringGetCharacterFromInlineBuffer(CFStringInlineBuffer *buf, CFIndex idx) {
995 //     if (buf->directBuffer) {
996 // 	if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0;
997 //         return buf->directBuffer[idx + buf->rangeToBuffer.location];
998 //     }
999 //     if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
1000 // 	if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0;
1001 // 	if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0;
1002 // 	buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength;
1003 // 	if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length;
1004 // 	CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer);
1005 //     }
1006 //     return buf->buffer[idx - buf->bufferedRangeStart];
1007 // }
1008 //
1009 // #else
1010 // { If INLINE functions are not available, we do somewhat less powerful macros that work similarly (except be aware that the buf argument is evaluated multiple times).
1011 // }
1012 // #define CFStringInitInlineBuffer(str, buf, range) \
1013 //     do {(buf)->theString = str; (buf)->rangeToBuffer = range; (buf)->directBuffer = CFStringGetCharactersPtr(str);} while (0)
1014 //
1015 // #define CFStringGetCharacterFromInlineBuffer(buf, idx) \
1016 //     (((idx) < 0 || (idx) >= (buf)->rangeToBuffer.length) ? 0 : ((buf)->directBuffer ? (buf)->directBuffer[(idx) + (buf)->rangeToBuffer.location] : CFStringGetCharacterAtIndex((buf)->theString, (idx) + (buf)->rangeToBuffer.location)))
1017 //
1018 // #endif { CF_INLINE }
1019 //
1020 // { UTF-16 surrogate support
1021 //  }
1022 // CF_INLINE Boolean CFStringIsSurrogateHighCharacter(UniChar character) {
1023 //     return ((character >= 0xD800UL) && (character <= 0xDBFFUL) ? true : false);
1024 // }
1025 //
1026 // CF_INLINE Boolean CFStringIsSurrogateLowCharacter(UniChar character) {
1027 //     return ((character >= 0xDC00UL) && (character <= 0xDFFFUL) ? true : false);
1028 // }
1029 //
1030 // CF_INLINE UTF32Char CFStringGetLongCharacterForSurrogatePair(UniChar surrogateHigh, UniChar surrogateLow) {
1031 //     return ((surrogateHigh - 0xD800UL) << 10) + (surrogateLow - 0xDC00UL) + 0x0010000UL;
1032 // }
1033 //
1034 // // Maps a UTF-32 character to a pair of UTF-16 surrogate characters. The buffer pointed by surrogates has to have space for at least 2 UTF-16 characters. Returns true if mapped to a surrogate pair.
1035 // CF_INLINE Boolean CFStringGetSurrogatePairForLongCharacter(UTF32Char character, UniChar *surrogates) {
1036 //     if ((character > 0xFFFFUL) && (character < 0x110000UL)) { // Non-BMP character
1037 //         character -= 0x10000;
1038 //         if (NULL != surrogates) {
1039 //             surrogates[0] = (UniChar)((character >> 10) + 0xD800UL);
1040 //             surrogates[1] = (UniChar)((character & 0x3FF) + 0xDC00UL);
1041 //         }
1042 //         return true;
1043 //     } else {
1044 //         if (NULL != surrogates) *surrogates = (UniChar)character;
1045 //         return false;
1046 //     }
1047 // }
1048 
1049 { Rest of the stuff in this file is private and should not be used directly
1050 }
1051 { For debugging only; output goes to stderr
1052    Use CFShow() to printf the description of any CFType;
1053    Use CFShowStr() to printf detailed info about a CFString
1054 }
1055 procedure CFShow( obj: CFTypeRef ); external name '_CFShow';
1056 
1057 procedure CFShowStr( str: CFStringRef ); external name '_CFShowStr';
1058 
1059 { This function is private and should not be used directly }
__CFStringMakeConstantStringnull1060 function __CFStringMakeConstantString( cStr: ConstCStringPtr ): CFStringRef; external name '___CFStringMakeConstantString';	{ Private; do not use }
1061 
1062 
1063 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
1064 implementation
1065 
1066 
1067 end.
1068 
1069 {$endc} {not MACOSALLINCLUDE}
1070