CFString.pas 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. { CFString.h
  2. Copyright (c) 1998-2005, Apple, Inc. All rights reserved.
  3. }
  4. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, November 2005 }
  5. {
  6. Modified for use with Free Pascal
  7. Version 200
  8. Please report any bugs to <[email protected]>
  9. }
  10. {$mode macpas}
  11. {$packenum 1}
  12. {$macro on}
  13. {$inline on}
  14. {$CALLING MWPASCAL}
  15. unit CFString;
  16. interface
  17. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  18. {$setc GAP_INTERFACES_VERSION := $0200}
  19. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  20. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  21. {$endc}
  22. {$ifc defined CPUPOWERPC and defined CPUI386}
  23. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  24. {$endc}
  25. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  26. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  27. {$endc}
  28. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  29. {$setc __ppc__ := 1}
  30. {$elsec}
  31. {$setc __ppc__ := 0}
  32. {$endc}
  33. {$ifc not defined __i386__ and defined CPUI386}
  34. {$setc __i386__ := 1}
  35. {$elsec}
  36. {$setc __i386__ := 0}
  37. {$endc}
  38. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  39. {$error Conflicting definitions for __ppc__ and __i386__}
  40. {$endc}
  41. {$ifc defined __ppc__ and __ppc__}
  42. {$setc TARGET_CPU_PPC := TRUE}
  43. {$setc TARGET_CPU_X86 := FALSE}
  44. {$elifc defined __i386__ and __i386__}
  45. {$setc TARGET_CPU_PPC := FALSE}
  46. {$setc TARGET_CPU_X86 := TRUE}
  47. {$elsec}
  48. {$error Neither __ppc__ nor __i386__ is defined.}
  49. {$endc}
  50. {$setc TARGET_CPU_PPC_64 := FALSE}
  51. {$ifc defined FPC_BIG_ENDIAN}
  52. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  53. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  54. {$elifc defined FPC_LITTLE_ENDIAN}
  55. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  56. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  57. {$elsec}
  58. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  59. {$endc}
  60. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  61. {$setc CALL_NOT_IN_CARBON := FALSE}
  62. {$setc OLDROUTINENAMES := FALSE}
  63. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  64. {$setc OPAQUE_UPP_TYPES := TRUE}
  65. {$setc OTCARBONAPPLICATION := TRUE}
  66. {$setc OTKERNEL := FALSE}
  67. {$setc PM_USE_SESSION_APIS := TRUE}
  68. {$setc TARGET_API_MAC_CARBON := TRUE}
  69. {$setc TARGET_API_MAC_OS8 := FALSE}
  70. {$setc TARGET_API_MAC_OSX := TRUE}
  71. {$setc TARGET_CARBON := TRUE}
  72. {$setc TARGET_CPU_68K := FALSE}
  73. {$setc TARGET_CPU_MIPS := FALSE}
  74. {$setc TARGET_CPU_SPARC := FALSE}
  75. {$setc TARGET_OS_MAC := TRUE}
  76. {$setc TARGET_OS_UNIX := FALSE}
  77. {$setc TARGET_OS_WIN32 := FALSE}
  78. {$setc TARGET_RT_MAC_68881 := FALSE}
  79. {$setc TARGET_RT_MAC_CFM := FALSE}
  80. {$setc TARGET_RT_MAC_MACHO := TRUE}
  81. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  82. {$setc TYPE_BOOL := FALSE}
  83. {$setc TYPE_EXTENDED := FALSE}
  84. {$setc TYPE_LONGLONG := TRUE}
  85. uses MacTypes,CFBase,CFArray,CFData,CFDictionary,CFCharacterSet,CFLocale;
  86. {$ALIGN POWER}
  87. {
  88. Please note: CFStrings are conceptually an array of Unicode characters.
  89. However, in general, how a CFString stores this array is an implementation
  90. detail. For instance, CFString might choose to use an array of 8-bit characters;
  91. to store its contents; or it might use multiple blocks of memory; or whatever.
  92. Furthermore, the implementation might change depending on the default
  93. system encoding, the user's language, the OS, or even a given release.
  94. What this means is that you should use the following advanced functions with care:
  95. CFStringGetPascalStringPtr()
  96. CFStringGetCStringPtr()
  97. CFStringGetCharactersPtr()
  98. These functions are provided for optimization only. They will either return the desired
  99. pointer quickly, in constant time, or they return NULL. They might choose to return NULL
  100. for many reasons; for instance it's possible that for users running in different
  101. languages these sometimes return NULL; or in a future OS release the first two might
  102. switch to always returning NULL. Never observing NULL returns in your usages of these
  103. functions does not mean they won't ever return NULL. (But note the CFStringGetCharactersPtr()
  104. exception mentioned further below.)
  105. In your usages of these functions, if you get a NULL return, use the non-Ptr version
  106. of the functions as shown in this example:
  107. Str255 buffer;
  108. StringPtr ptr = CFStringGetPascalStringPtr(str, encoding);
  109. if (ptr == NULL) (
  110. if (CFStringGetPascalString(str, buffer, 256, encoding)) ptr = buffer;
  111. )
  112. Note that CFStringGetPascalString() or CFStringGetCString() calls might still fail --- but
  113. that will happen in two circumstances only: The conversion from the UniChar contents of CFString
  114. to the specified encoding fails, or the buffer is too small. If they fail, that means
  115. the conversion was not possible.
  116. If you need a copy of the buffer in the above example, you might consider simply
  117. calling CFStringGetPascalString() in all cases --- CFStringGetPascalStringPtr()
  118. is simply an optimization.
  119. In addition, the following functions, which create immutable CFStrings from developer
  120. supplied buffers without copying the buffers, might have to actually copy
  121. under certain circumstances (If they do copy, the buffer will be dealt with by the
  122. "contentsDeallocator" argument.):
  123. CFStringCreateWithPascalStringNoCopy()
  124. CFStringCreateWithCStringNoCopy()
  125. CFStringCreateWithCharactersNoCopy()
  126. You should of course never depend on the backing store of these CFStrings being
  127. what you provided, and in other no circumstance should you change the contents
  128. of that buffer (given that would break the invariant about the CFString being immutable).
  129. Having said all this, there are actually ways to create a CFString where the backing store
  130. is external, and can be manipulated by the developer or CFString itself:
  131. CFStringCreateMutableWithExternalCharactersNoCopy()
  132. CFStringSetExternalCharactersNoCopy()
  133. A "contentsAllocator" is used to realloc or free the backing store by CFString.
  134. kCFAllocatorNull can be provided to assure CFString will never realloc or free the buffer.
  135. Developer can call CFStringSetExternalCharactersNoCopy() to update
  136. CFString's idea of what's going on, if the buffer is changed externally. In these
  137. strings, CFStringGetCharactersPtr() is guaranteed to return the external buffer.
  138. These functions are here to allow wrapping a buffer of UniChar characters in a CFString,
  139. allowing the buffer to passed into CFString functions and also manipulated via CFString
  140. mutation functions. In general, developers should not use this technique for all strings,
  141. as it prevents CFString from using certain optimizations.
  142. }
  143. { Identifier for character encoding; the values are the same as Text Encoding Converter TextEncoding.
  144. }
  145. type
  146. CFStringEncoding = UInt32;
  147. CFStringEncodingPtr = ^CFStringEncoding;
  148. { Platform-independent built-in encodings; always available on all platforms.
  149. Call CFStringGetSystemEncoding() to get the default system encoding.
  150. }
  151. type
  152. CFStringBuiltInEncodings = SInt32;
  153. const
  154. kCFStringEncodingInvalidId = $FFFFFFFF;
  155. kCFStringEncodingMacRoman = 0;
  156. kCFStringEncodingWindowsLatin1 = $0500; { ANSI codepage 1252 }
  157. kCFStringEncodingISOLatin1 = $0201; { ISO 8859-1 }
  158. kCFStringEncodingNextStepLatin = $0B01; { NextStep encoding }
  159. kCFStringEncodingASCII = $0600; { 0..127 (in creating CFString, values greater than 0x7F are treated as corresponding Unicode value) }
  160. kCFStringEncodingUnicode = $0100; { kTextEncodingUnicodeDefault + kTextEncodingDefaultFormat (aka kUnicode16BitFormat) }
  161. kCFStringEncodingUTF8 = $08000100; { kTextEncodingUnicodeDefault + kUnicodeUTF8Format }
  162. kCFStringEncodingNonLossyASCII = $0BFF; { 7bit Unicode variants used by YellowBox & Java }
  163. {#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4}
  164. kCFStringEncodingUTF16 = $0100; { kTextEncodingUnicodeDefault + kUnicodeUTF16Format (alias of kCFStringEncodingUnicode) }
  165. kCFStringEncodingUTF16BE = $10000100; { kTextEncodingUnicodeDefault + kUnicodeUTF16BEFormat }
  166. kCFStringEncodingUTF16LE = $14000100; { kTextEncodingUnicodeDefault + kUnicodeUTF16LEFormat }
  167. kCFStringEncodingUTF32 = $0C000100; { kTextEncodingUnicodeDefault + kUnicodeUTF32Format }
  168. kCFStringEncodingUTF32BE = $18000100; { kTextEncodingUnicodeDefault + kUnicodeUTF32BEFormat }
  169. kCFStringEncodingUTF32LE = $1C000100; { kTextEncodingUnicodeDefault + kUnicodeUTF32LEFormat }
  170. {#endif} { MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 }
  171. { CFString type ID }
  172. function CFStringGetTypeID: CFTypeID; external name '_CFStringGetTypeID';
  173. { Macro to allow creation of compile-time constant strings; the argument should be a constant string.
  174. CFSTR(), not being a "Copy" or "Create" function, does not return a new
  175. reference for you. So, you should not release the return value. This is
  176. much like constant C or Pascal strings --- when you use "hello world"
  177. in a program, you do not free it.
  178. However, strings returned from CFSTR() can be retained and released in a
  179. properly nested fashion, just like any other CF type. That is, if you pass
  180. a CFSTR() return value to a function such as SetMenuItemWithCFString(), the
  181. function can retain it, then later, when it's done with it, it can release it.
  182. At this point non-7 bit characters (that is, characters > 127) in CFSTR() are not
  183. supported and using them will lead to unpredictable results. This includes escaped
  184. (\nnn) characters whose values are > 127. Even if it works for you in testing,
  185. it might not work for a user with a different language preference.
  186. }
  187. {
  188. *** Pascal Usage of CFSTR et al ***
  189. For Pascal:
  190. To define your own constant CFStrings, call call CFSTRP with a
  191. constant Pascal single-quoted string only, for example
  192. CFSTRP('a constant string').
  193. For MetroWerks Pascal:
  194. Include the CFStringGlue file in your project (it defines the private function,
  195. CFSTRP0, which you should never call directly.
  196. In your uses clause, use CFString and CFStringGlue and whichever PInterface files
  197. defining the constant CFStrings (or define your own using CFSTRP('pascal string')).
  198. For GNU Pascal:
  199. Include the GPCMacros.inc file (for example $I GPCMacros.inc).
  200. In your uses clause, use CFString (and, optionally, CFStringGlue and the
  201. PInterface files defining the constant CFStrings).
  202. You can optionally use CFSTR with a constant double-quoted C String (for example,
  203. CFSTR("a constant C string")) although it will make no difference, but will
  204. result in closer C source code similarity.
  205. For maximum compatibility in both GPC and MetroWerks Pascal
  206. Include the GPCMacros.inc file in GPC as part of your GPC prefix.
  207. Include the CFStringGlue file in your MW project.
  208. Only ever use CFSTRP with a constant Pascal string.
  209. In your uses clause for a unit, use the CFString, CFStringGlue and any
  210. PInterface files defining any constant CFStrings you need.
  211. }
  212. {
  213. CFSTR Must only be called with a constant CString
  214. }
  215. function CFSTR( c: PChar ): CFStringRef; external name '___CFStringMakeConstantString';
  216. {
  217. CFSTRP Must only be called with a constant Pascal String
  218. }
  219. function CFSTRP( c: PChar ): CFStringRef; external name '___CFStringMakeConstantString';
  220. {
  221. CFSTRP0 Must only be called with a constant Pascal String terminated with a chr(0)
  222. }
  223. function CFSTRP0( c: PChar ): CFStringRef; external name '___CFStringMakeConstantString';
  224. {** Immutable string creation functions **}
  225. { Functions to create basic immutable strings. The provided allocator is used for all memory activity in these functions.
  226. }
  227. { These functions copy the provided buffer into CFString's internal storage. }
  228. function CFStringCreateWithPascalString( alloc: CFAllocatorRef; const (*var*) pStr: Str255; encoding: CFStringEncoding ): CFStringRef; external name '_CFStringCreateWithPascalString';
  229. function CFStringCreateWithCString( alloc: CFAllocatorRef; cStr: ConstCStringPtr; encoding: CFStringEncoding ): CFStringRef; external name '_CFStringCreateWithCString';
  230. function CFStringCreateWithCharacters( alloc: CFAllocatorRef; chars: UniCharPtr; numChars: CFIndex ): CFStringRef; external name '_CFStringCreateWithCharacters';
  231. { These functions try not to copy the provided buffer. The buffer will be deallocated
  232. with the provided contentsDeallocator when it's no longer needed; to not free
  233. the buffer, specify kCFAllocatorNull here. As usual, NULL means default allocator.
  234. NOTE: Do not count on these buffers as being used by the string;
  235. in some cases the CFString might free the buffer and use something else
  236. (for instance if it decides to always use Unicode encoding internally).
  237. NOTE: If you are not transferring ownership of the buffer to the CFString
  238. (for instance, you supplied contentsDeallocator = kCFAllocatorNull), it is your
  239. responsibility to assure the buffer does not go away during the lifetime of the string.
  240. If the string is retained or copied, its lifetime might extend in ways you cannot
  241. predict. So, for strings created with buffers whose lifetimes you cannot
  242. guarantee, you need to be extremely careful --- do not hand it out to any
  243. APIs which might retain or copy the strings.
  244. }
  245. function CFStringCreateWithPascalStringNoCopy( alloc: CFAllocatorRef; const (*var*) pStr: Str255; encoding: CFStringEncoding; contentsDeallocator: CFAllocatorRef ): CFStringRef; external name '_CFStringCreateWithPascalStringNoCopy';
  246. function CFStringCreateWithCStringNoCopy( alloc: CFAllocatorRef; cStr: ConstCStringPtr; encoding: CFStringEncoding; contentsDeallocator: CFAllocatorRef ): CFStringRef; external name '_CFStringCreateWithCStringNoCopy';
  247. function CFStringCreateWithCharactersNoCopy( alloc: CFAllocatorRef; chars: UniCharPtr; numChars: CFIndex; contentsDeallocator: CFAllocatorRef ): CFStringRef; external name '_CFStringCreateWithCharactersNoCopy';
  248. { Create copies of part or all of the string.
  249. }
  250. function CFStringCreateWithSubstring( alloc: CFAllocatorRef; str: CFStringRef; range: CFRange ): CFStringRef; external name '_CFStringCreateWithSubstring';
  251. function CFStringCreateCopy( alloc: CFAllocatorRef; theString: CFStringRef ): CFStringRef; external name '_CFStringCreateCopy';
  252. { These functions create a CFString from the provided printf-like format string and arguments.
  253. }
  254. function CFStringCreateWithFormat( alloc: CFAllocatorRef; formatOptions: CFDictionaryRef; format: CFStringRef; ... ): CFStringRef; external name '_CFStringCreateWithFormat';
  255. function CFStringCreateWithFormatAndArguments( alloc: CFAllocatorRef; formatOptions: CFDictionaryRef; format: CFStringRef; arguments: UnivPtr ): CFStringRef; external name '_CFStringCreateWithFormatAndArguments';
  256. { 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.
  257. }
  258. function CFStringCreateMutable( alloc: CFAllocatorRef; maxLength: CFIndex ): CFMutableStringRef; external name '_CFStringCreateMutable';
  259. function CFStringCreateMutableCopy( alloc: CFAllocatorRef; maxLength: CFIndex; theString: CFStringRef ): CFMutableStringRef; external name '_CFStringCreateMutableCopy';
  260. { This function creates a mutable string that has a developer supplied and directly editable backing store.
  261. The string will be manipulated within the provided buffer (if any) until it outgrows capacity; then the
  262. externalCharactersAllocator will be consulted for more memory. When the CFString is deallocated, the
  263. buffer will be freed with the externalCharactersAllocator. Provide kCFAllocatorNull here to prevent the buffer
  264. from ever being reallocated or deallocated by CFString. See comments at top of this file for more info.
  265. }
  266. function CFStringCreateMutableWithExternalCharactersNoCopy( alloc: CFAllocatorRef; chars: UniCharPtr; numChars: CFIndex; capacity: CFIndex; externalCharactersAllocator: CFAllocatorRef ): CFMutableStringRef; external name '_CFStringCreateMutableWithExternalCharactersNoCopy';
  267. {** Basic accessors for the contents **}
  268. { Number of 16-bit Unicode characters in the string.
  269. }
  270. function CFStringGetLength( theString: CFStringRef ): CFIndex; external name '_CFStringGetLength';
  271. { Extracting the contents of the string. For obtaining multiple characters, calling
  272. CFStringGetCharacters() is more efficient than multiple calls to CFStringGetCharacterAtIndex().
  273. If the length of the string is not known (so you can't use a fixed size buffer for CFStringGetCharacters()),
  274. another method is to use is CFStringGetCharacterFromInlineBuffer() (see further below).
  275. }
  276. function CFStringGetCharacterAtIndex( theString: CFStringRef; idx: CFIndex ): UniChar; external name '_CFStringGetCharacterAtIndex';
  277. procedure CFStringGetCharacters( theString: CFStringRef; range: CFRange; buffer: UniCharPtr ); external name '_CFStringGetCharacters';
  278. {** Conversion to other encodings **}
  279. { These two convert into the provided buffer; they return false if conversion isn't possible
  280. (due to conversion error, or not enough space in the provided buffer).
  281. These functions do zero-terminate or put the length byte; the provided bufferSize should include
  282. space for this (so pass 256 for Str255). More sophisticated usages can go through CFStringGetBytes().
  283. These functions are equivalent to calling CFStringGetBytes() with
  284. the range of the string; lossByte = 0; and isExternalRepresentation = false;
  285. if successful, they then insert the leading length of terminating zero, as desired.
  286. }
  287. function CFStringGetPascalString( theString: CFStringRef; buffer: StringPtr; bufferSize: CFIndex; encoding: CFStringEncoding ): Boolean; external name '_CFStringGetPascalString';
  288. function CFStringGetCString( theString: CFStringRef; buffer: CStringPtr; bufferSize: CFIndex; encoding: CFStringEncoding ): Boolean; external name '_CFStringGetCString';
  289. { These functions attempt to return in O(1) time the desired format for the string.
  290. Note that although this means a pointer to the internal structure is being returned,
  291. this can't always be counted on. Please see note at the top of the file for more
  292. details.
  293. }
  294. function CFStringGetPascalStringPtr( theString: CFStringRef; encoding: CFStringEncoding ): ConstStringPtr; external name '_CFStringGetPascalStringPtr'; { May return NULL at any time; be prepared for NULL }
  295. function CFStringGetCStringPtr( theString: CFStringRef; encoding: CFStringEncoding ): ConstCStringPtr; external name '_CFStringGetCStringPtr'; { May return NULL at any time; be prepared for NULL }
  296. function CFStringGetCharactersPtr( theString: CFStringRef ): UniCharPtr; external name '_CFStringGetCharactersPtr'; { May return NULL at any time; be prepared for NULL }
  297. { The primitive conversion routine; allows you to convert a string piece at a time
  298. into a fixed size buffer. Returns number of characters converted.
  299. Characters that cannot be converted to the specified encoding are represented
  300. with the byte specified by lossByte; if lossByte is 0, then lossy conversion
  301. is not allowed and conversion stops, returning partial results.
  302. Pass buffer==NULL if you don't care about the converted string (but just the convertability,
  303. or number of bytes required).
  304. maxBufLength indicates the maximum number of bytes to generate. It is ignored when buffer==NULL.
  305. Does not zero-terminate. If you want to create Pascal or C string, allow one extra byte at start or end.
  306. Setting isExternalRepresentation causes any extra bytes that would allow
  307. the data to be made persistent to be included; for instance, the Unicode BOM.
  308. }
  309. function CFStringGetBytes( theString: CFStringRef; range: CFRange; encoding: CFStringEncoding; lossByte: ByteParameter; isExternalRepresentation: Boolean; buffer: UInt8Ptr; maxBufLen: CFIndex; var usedBufLen: CFIndex ): CFIndex; external name '_CFStringGetBytes';
  310. { This one goes the other way by creating a CFString from a bag of bytes.
  311. This is much like CFStringCreateWithPascalString or CFStringCreateWithCString,
  312. except the length is supplied explicitly. In addition, you can specify whether
  313. the data is an external format --- that is, whether to pay attention to the
  314. BOM character (if any) and do byte swapping if necessary
  315. }
  316. function CFStringCreateWithBytes( alloc: CFAllocatorRef; bytes: UnivPtr; numBytes: CFIndex; encoding: CFStringEncoding; isExternalRepresentation: Boolean ): CFStringRef; external name '_CFStringCreateWithBytes';
  317. { Convenience functions String <-> Data. These generate "external" formats, that is, formats that
  318. can be written out to disk. For instance, if the encoding is Unicode, CFStringCreateFromExternalRepresentation()
  319. pays attention to the BOM character (if any) and does byte swapping if necessary.
  320. Similarly CFStringCreateExternalRepresentation() will always include a BOM character if the encoding is
  321. Unicode. See above for description of lossByte.
  322. }
  323. function CFStringCreateFromExternalRepresentation( alloc: CFAllocatorRef; data: CFDataRef; encoding: CFStringEncoding ): CFStringRef; external name '_CFStringCreateFromExternalRepresentation'; { May return NULL on conversion error }
  324. function CFStringCreateExternalRepresentation( alloc: CFAllocatorRef; theString: CFStringRef; encoding: CFStringEncoding; lossByte: ByteParameter ): CFDataRef; external name '_CFStringCreateExternalRepresentation'; { May return NULL on conversion error }
  325. { Hints about the contents of a string
  326. }
  327. function CFStringGetSmallestEncoding( theString: CFStringRef ): CFStringEncoding; external name '_CFStringGetSmallestEncoding'; { Result in O(n) time max }
  328. function CFStringGetFastestEncoding( theString: CFStringRef ): CFStringEncoding; external name '_CFStringGetFastestEncoding'; { Result in O(1) time max }
  329. { General encoding info
  330. }
  331. function CFStringGetSystemEncoding: CFStringEncoding; external name '_CFStringGetSystemEncoding'; { The default encoding for the system; untagged 8-bit characters are usually in this encoding }
  332. function CFStringGetMaximumSizeForEncoding( length: CFIndex; encoding: CFStringEncoding ): CFIndex; external name '_CFStringGetMaximumSizeForEncoding'; { Max bytes a string of specified length (in UniChars) will take up if encoded }
  333. {** FileSystem path conversion functions **}
  334. { Extract the contents of the string as a NULL-terminated 8-bit string appropriate for passing to POSIX APIs. 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.
  335. }
  336. function CFStringGetFileSystemRepresentation( strng: CFStringRef; buffer: CStringPtr; maxBufLen: CFIndex ): Boolean; external name '_CFStringGetFileSystemRepresentation';
  337. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  338. { 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().
  339. }
  340. function CFStringGetMaximumSizeOfFileSystemRepresentation( strng: CFStringRef ): CFIndex; external name '_CFStringGetMaximumSizeOfFileSystemRepresentation';
  341. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  342. { 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.
  343. }
  344. function CFStringCreateWithFileSystemRepresentation( alloc: CFAllocatorRef; buffer: ConstCStringPtr ): CFStringRef; external name '_CFStringCreateWithFileSystemRepresentation';
  345. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  346. {** Comparison functions. **}
  347. { Find and compare flags; these are OR'ed together as compareOptions or searchOptions in the various functions.
  348. This typedef doesn't appear in the functions; instead the argument is CFOptionFlags.
  349. }
  350. type
  351. CFStringCompareFlags = SInt32;
  352. const
  353. { Flags used in all find and compare operations }
  354. kCFCompareCaseInsensitive = 1;
  355. kCFCompareBackwards = 4; { Starting from the end of the string }
  356. kCFCompareAnchored = 8; { Only at the specified starting point }
  357. kCFCompareNonliteral = 16; { If specified, loose equivalence is performed (o-umlaut == o, umlaut) }
  358. kCFCompareLocalized = 32; { User's default locale is used for the comparisons }
  359. kCFCompareNumerically = 64; { Numeric comparison is used; that is, Foo2.txt < Foo7.txt < Foo25.txt }
  360. { The main comparison routine; compares specified range of the first string to (the full range of) the second string.
  361. locale == NULL indicates canonical locale.
  362. kCFCompareNumerically, added in 10.2, does not work if kCFCompareLocalized is specified on systems before 10.3
  363. kCFCompareBackwards and kCFCompareAnchored are not applicable.
  364. }
  365. function CFStringCompareWithOptions( theString1: CFStringRef; theString2: CFStringRef; rangeToCompare: CFRange; compareOptions: CFOptionFlags ): CFComparisonResult; external name '_CFStringCompareWithOptions';
  366. { Comparison convenience suitable for passing as sorting functions.
  367. kCFCompareNumerically, added in 10.2, does not work if kCFCompareLocalized is specified on systems before 10.3
  368. kCFCompareBackwards and kCFCompareAnchored are not applicable.
  369. }
  370. function CFStringCompare( theString1: CFStringRef; theString2: CFStringRef; compareOptions: CFOptionFlags ): CFComparisonResult; external name '_CFStringCompare';
  371. { CFStringFindWithOptions() returns the found range in the CFRange * argument; you can pass NULL for simple discovery check.
  372. If stringToFind is the empty string (zero length), nothing is found.
  373. Ignores the kCFCompareNumerically option.
  374. }
  375. function CFStringFindWithOptions( theString: CFStringRef; stringToFind: CFStringRef; rangeToSearch: CFRange; searchOptions: CFOptionFlags; var result: CFRange ): Boolean; external name '_CFStringFindWithOptions';
  376. { CFStringCreateArrayWithFindResults() returns an array of CFRange pointers, or NULL if there are no matches.
  377. Overlapping instances are not found; so looking for "AA" in "AAA" finds just one range.
  378. Post 10.1: If kCFCompareBackwards is provided, the scan is done from the end (which can give a different result), and
  379. the results are stored in the array backwards (last found range in slot 0).
  380. If stringToFind is the empty string (zero length), nothing is found.
  381. 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.
  382. Ignores the kCFCompareNumerically option.
  383. }
  384. function CFStringCreateArrayWithFindResults( alloc: CFAllocatorRef; theString: CFStringRef; stringToFind: CFStringRef; rangeToSearch: CFRange; compareOptions: CFOptionFlags ): CFArrayRef; external name '_CFStringCreateArrayWithFindResults';
  385. { Find conveniences; see comments above concerning empty string and options.
  386. }
  387. function CFStringFind( theString: CFStringRef; stringToFind: CFStringRef; compareOptions: CFOptionFlags ): CFRange; external name '_CFStringFind';
  388. function CFStringHasPrefix( theString: CFStringRef; prefix: CFStringRef ): Boolean; external name '_CFStringHasPrefix';
  389. function CFStringHasSuffix( theString: CFStringRef; suffix: CFStringRef ): Boolean; external name '_CFStringHasSuffix';
  390. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  391. {!
  392. @function CFStringGetRangeOfComposedCharactersAtIndex
  393. Returns the range of the composed character sequence at the specified index.
  394. @param theString The CFString which is to be searched. If this
  395. parameter is not a valid CFString, the behavior is
  396. undefined.
  397. @param theIndex The index of the character contained in the
  398. composed character sequence. If the index is
  399. outside the index space of the string (0 to N-1 inclusive,
  400. where N is the length of the string), the behavior is
  401. undefined.
  402. @result The range of the composed character sequence.
  403. }
  404. function CFStringGetRangeOfComposedCharactersAtIndex( theString: CFStringRef; theIndex: CFIndex ): CFRange; external name '_CFStringGetRangeOfComposedCharactersAtIndex';
  405. {!
  406. @function CFStringFindCharacterFromSet
  407. Query the range of the first character contained in the specified character set.
  408. @param theString The CFString which is to be searched. If this
  409. parameter is not a valid CFString, the behavior is
  410. undefined.
  411. @param theSet The CFCharacterSet against which the membership
  412. of characters is checked. If this parameter is not a valid
  413. CFCharacterSet, the behavior is undefined.
  414. @param range The range of characters within the string to search. If
  415. the range location or end point (defined by the location
  416. plus length minus 1) are outside the index space of the
  417. string (0 to N-1 inclusive, where N is the length of the
  418. string), the behavior is undefined. If the range length is
  419. negative, the behavior is undefined. The range may be empty
  420. (length 0), in which case no search is performed.
  421. @param searchOptions The bitwise-or'ed option flags to control
  422. the search behavior. The supported options are
  423. kCFCompareBackwards andkCFCompareAnchored.
  424. If other option flags are specified, the behavior
  425. is undefined.
  426. @param result The pointer to a CFRange supplied by the caller in
  427. which the search result is stored. Note that the length
  428. of this range could be more than If a pointer to an invalid
  429. memory is specified, the behavior is undefined.
  430. @result true, if at least a character which is a member of the character
  431. set is found and result is filled, otherwise, false.
  432. }
  433. function CFStringFindCharacterFromSet( theString: CFStringRef; theSet: CFCharacterSetRef; rangeToSearch: CFRange; searchOptions: CFOptionFlags; var result: CFRange ): Boolean; external name '_CFStringFindCharacterFromSet';
  434. {#endif}
  435. { Find range of bounds of the line(s) that span the indicated range (startIndex, numChars),
  436. taking into account various possible line separator sequences (CR, CRLF, LF, and Unicode LS, PS).
  437. All return values are "optional" (provide NULL if you don't want them)
  438. lineStartIndex: index of first character in line
  439. lineEndIndex: index of first character of the next line (including terminating line separator characters)
  440. contentsEndIndex: index of the first line separator character
  441. Thus, lineEndIndex - lineStartIndex is the number of chars in the line, including the line separators
  442. contentsEndIndex - lineStartIndex is the number of chars in the line w/out the line separators
  443. }
  444. procedure CFStringGetLineBounds( theString: CFStringRef; range: CFRange; var lineBeginIndex: CFIndex; var lineEndIndex: CFIndex; var contentsEndIndex: CFIndex ); external name '_CFStringGetLineBounds';
  445. {** Exploding and joining strings with a separator string **}
  446. function CFStringCreateByCombiningStrings( alloc: CFAllocatorRef; theArray: CFArrayRef; separatorString: CFStringRef ): CFStringRef; external name '_CFStringCreateByCombiningStrings'; { Empty array returns empty string; one element array returns the element }
  447. 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 }
  448. {** Parsing non-localized numbers from strings **}
  449. function CFStringGetIntValue( str: CFStringRef ): SInt32; external name '_CFStringGetIntValue'; { Skips whitespace; returns 0 on error, MAX or -MAX on overflow }
  450. function CFStringGetDoubleValue( str: CFStringRef ): Float64; external name '_CFStringGetDoubleValue'; { Skips whitespace; returns 0.0 on error }
  451. {** MutableString functions **}
  452. { CFStringAppend("abcdef", "xxxxx") -> "abcdefxxxxx"
  453. CFStringDelete("abcdef", CFRangeMake(2, 3)) -> "abf"
  454. CFStringReplace("abcdef", CFRangeMake(2, 3), "xxxxx") -> "abxxxxxf"
  455. CFStringReplaceAll("abcdef", "xxxxx") -> "xxxxx"
  456. }
  457. procedure CFStringAppend( theString: CFMutableStringRef; appendedString: CFStringRef ); external name '_CFStringAppend';
  458. procedure CFStringAppendCharacters( theString: CFMutableStringRef; chars: UniCharPtr; numChars: CFIndex ); external name '_CFStringAppendCharacters';
  459. procedure CFStringAppendPascalString( theString: CFMutableStringRef; const (*var*) pStr: Str255; encoding: CFStringEncoding ); external name '_CFStringAppendPascalString';
  460. procedure CFStringAppendCString( theString: CFMutableStringRef; cStr: ConstCStringPtr; encoding: CFStringEncoding ); external name '_CFStringAppendCString';
  461. procedure CFStringAppendFormat( theString: CFMutableStringRef; formatOptions: CFDictionaryRef; format: CFStringRef; ... ); external name '_CFStringAppendFormat';
  462. procedure CFStringAppendFormatAndArguments( theString: CFMutableStringRef; formatOptions: CFDictionaryRef; format: CFStringRef; arguments: UnivPtr ); external name '_CFStringAppendFormatAndArguments';
  463. procedure CFStringInsert( str: CFMutableStringRef; idx: CFIndex; insertedStr: CFStringRef ); external name '_CFStringInsert';
  464. procedure CFStringDelete( theString: CFMutableStringRef; range: CFRange ); external name '_CFStringDelete';
  465. procedure CFStringReplace( theString: CFMutableStringRef; range: CFRange; replacement: CFStringRef ); external name '_CFStringReplace';
  466. procedure CFStringReplaceAll( theString: CFMutableStringRef; replacement: CFStringRef ); external name '_CFStringReplaceAll'; { Replaces whole string }
  467. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  468. { Replace all occurrences of target in rangeToSearch of theString with replacement.
  469. Pays attention to kCFCompareCaseInsensitive, kCFCompareBackwards, kCFCompareNonliteral, and kCFCompareAnchored.
  470. kCFCompareBackwards can be used to do the replacement starting from the end, which could give a different result.
  471. ex. AAAAA, replace AA with B -> BBA or ABB; latter if kCFCompareBackwards
  472. kCFCompareAnchored assures only anchored but multiple instances are found (the instances must be consecutive at start or end)
  473. ex. AAXAA, replace A with B -> BBXBB or BBXAA; latter if kCFCompareAnchored
  474. Returns number of replacements performed.
  475. }
  476. function CFStringFindAndReplace( theString: CFMutableStringRef; stringToFind: CFStringRef; replacementString: CFStringRef; rangeToSearch: CFRange; compareOptions: CFOptionFlags ): CFIndex; external name '_CFStringFindAndReplace';
  477. {#endif}
  478. { This function will make the contents of a mutable CFString point directly at the specified UniChar array.
  479. It works only with CFStrings created with CFStringCreateMutableWithExternalCharactersNoCopy().
  480. This function does not free the previous buffer.
  481. The string will be manipulated within the provided buffer (if any) until it outgrows capacity; then the
  482. externalCharactersAllocator will be consulted for more memory.
  483. See comments at the top of this file for more info.
  484. }
  485. procedure CFStringSetExternalCharactersNoCopy( theString: CFMutableStringRef; chars: UniCharPtr; length: CFIndex; capacity: CFIndex ); external name '_CFStringSetExternalCharactersNoCopy'; { Works only on specially created mutable strings! }
  486. { CFStringPad() will pad or cut down a string to the specified size.
  487. The pad string is used as the fill string; indexIntoPad specifies which character to start with.
  488. CFStringPad("abc", " ", 9, 0) -> "abc "
  489. CFStringPad("abc", ". ", 9, 1) -> "abc . . ."
  490. CFStringPad("abcdef", ?, 3, ?) -> "abc"
  491. CFStringTrim() will trim the specified string from both ends of the string.
  492. CFStringTrimWhitespace() will do the same with white space characters (tab, newline, etc)
  493. CFStringTrim(" abc ", " ") -> "abc"
  494. CFStringTrim("* * * *abc * ", "* ") -> "*abc "
  495. }
  496. procedure CFStringPad( theString: CFMutableStringRef; padString: CFStringRef; length: CFIndex; indexIntoPad: CFIndex ); external name '_CFStringPad';
  497. procedure CFStringTrim( theString: CFMutableStringRef; trimString: CFStringRef ); external name '_CFStringTrim';
  498. procedure CFStringTrimWhitespace( theString: CFMutableStringRef ); external name '_CFStringTrimWhitespace';
  499. {#if MAC_OS_X_VERSION_10_3 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  500. procedure CFStringLowercase( theString: CFMutableStringRef; locale: CFLocaleRef ); external name '_CFStringLowercase';
  501. procedure CFStringUppercase( theString: CFMutableStringRef; locale: CFLocaleRef ); external name '_CFStringUppercase';
  502. procedure CFStringCapitalize( theString: CFMutableStringRef; locale: CFLocaleRef ); external name '_CFStringCapitalize';
  503. {#else}
  504. //procedure CFStringLowercase( theString: CFMutableStringRef; localeTBD: {const} UnivPtr ); // localeTBD must be NULL on pre-10.3
  505. //procedure CFStringUppercase( theString: CFMutableStringRef; localeTBD: {const} UnivPtr ); // localeTBD must be NULL on pre-10.3
  506. //procedure CFStringCapitalize( theString: CFMutableStringRef; localeTBD: {const} UnivPtr ); // localeTBD must be NULL on pre-10.3
  507. {#endif}
  508. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  509. {!
  510. @typedef CFStringNormalizationForm
  511. This is the type of Unicode normalization forms as described in
  512. Unicode Technical Report #15.
  513. }
  514. type
  515. CFStringNormalizationForm = SInt32;
  516. const
  517. kCFStringNormalizationFormD = 0; // Canonical Decomposition
  518. kCFStringNormalizationFormKD = 1; // Compatibility Decomposition
  519. kCFStringNormalizationFormC = 2; // Canonical Decomposition followed by Canonical Composition
  520. kCFStringNormalizationFormKC = 3; // Compatibility Decomposition followed by Canonical Composition
  521. {!
  522. @function CFStringNormalize
  523. Normalizes the string into the specified form as described in
  524. Unicode Technical Report #15.
  525. @param theString The string which is to be normalized. If this
  526. parameter is not a valid mutable CFString, the behavior is
  527. undefined.
  528. @param theForm The form into which the string is to be normalized.
  529. If this parameter is not a valid CFStringNormalizationForm value,
  530. the behavior is undefined.
  531. }
  532. procedure CFStringNormalize( theString: CFMutableStringRef; theForm: CFStringNormalizationForm ); external name '_CFStringNormalize';
  533. {#endif}
  534. { Perform string transliteration. The transformation represented by transform (see below for the full list of transforms supported) 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.
  535. }
  536. function CFStringTransform( strng: CFMutableStringRef; var range: CFRange; transform: CFStringRef; reverse: Boolean ): Boolean; external name '_CFStringTransform';
  537. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  538. { Transform identifiers for CFStringTransform()
  539. }
  540. var kCFStringTransformStripCombiningMarks: CFStringRef; external name '_kCFStringTransformStripCombiningMarks'; (* attribute const *)
  541. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  542. var kCFStringTransformToLatin: CFStringRef; external name '_kCFStringTransformToLatin'; (* attribute const *)
  543. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  544. var kCFStringTransformFullwidthHalfwidth: CFStringRef; external name '_kCFStringTransformFullwidthHalfwidth'; (* attribute const *)
  545. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  546. var kCFStringTransformLatinKatakana: CFStringRef; external name '_kCFStringTransformLatinKatakana'; (* attribute const *)
  547. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  548. var kCFStringTransformLatinHiragana: CFStringRef; external name '_kCFStringTransformLatinHiragana'; (* attribute const *)
  549. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  550. var kCFStringTransformHiraganaKatakana: CFStringRef; external name '_kCFStringTransformHiraganaKatakana'; (* attribute const *)
  551. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  552. var kCFStringTransformMandarinLatin: CFStringRef; external name '_kCFStringTransformMandarinLatin'; (* attribute const *)
  553. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  554. var kCFStringTransformLatinHangul: CFStringRef; external name '_kCFStringTransformLatinHangul'; (* attribute const *)
  555. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  556. var kCFStringTransformLatinArabic: CFStringRef; external name '_kCFStringTransformLatinArabic'; (* attribute const *)
  557. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  558. var kCFStringTransformLatinHebrew: CFStringRef; external name '_kCFStringTransformLatinHebrew'; (* attribute const *)
  559. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  560. var kCFStringTransformLatinThai: CFStringRef; external name '_kCFStringTransformLatinThai'; (* attribute const *)
  561. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  562. var kCFStringTransformLatinCyrillic: CFStringRef; external name '_kCFStringTransformLatinCyrillic'; (* attribute const *)
  563. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  564. var kCFStringTransformLatinGreek: CFStringRef; external name '_kCFStringTransformLatinGreek'; (* attribute const *)
  565. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  566. var kCFStringTransformToXMLHex: CFStringRef; external name '_kCFStringTransformToXMLHex'; (* attribute const *)
  567. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  568. var kCFStringTransformToUnicodeName: CFStringRef; external name '_kCFStringTransformToUnicodeName'; (* attribute const *)
  569. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  570. {** General encoding related functionality **}
  571. { This returns availability of the encoding on the system
  572. }
  573. function CFStringIsEncodingAvailable( encoding: CFStringEncoding ): Boolean; external name '_CFStringIsEncodingAvailable';
  574. { This function returns list of available encodings. The returned list is terminated with kCFStringEncodingInvalidId and owned by the system.
  575. }
  576. function CFStringGetListOfAvailableEncodings: CFStringEncodingPtr; external name '_CFStringGetListOfAvailableEncodings';
  577. { Returns name of the encoding; non-localized.
  578. }
  579. function CFStringGetNameOfEncoding( encoding: CFStringEncoding ): CFStringRef; external name '_CFStringGetNameOfEncoding';
  580. { ID mapping functions from/to Cocoa NSStringEncoding. Returns kCFStringEncodingInvalidId if no mapping exists.
  581. }
  582. function CFStringConvertEncodingToNSStringEncoding( encoding: CFStringEncoding ): UInt32; external name '_CFStringConvertEncodingToNSStringEncoding';
  583. function CFStringConvertNSStringEncodingToEncoding( encoding: UInt32 ): CFStringEncoding; external name '_CFStringConvertNSStringEncodingToEncoding';
  584. { ID mapping functions from/to Microsoft Windows codepage (covers both OEM & ANSI). Returns kCFStringEncodingInvalidId if no mapping exists.
  585. }
  586. function CFStringConvertEncodingToWindowsCodepage( encoding: CFStringEncoding ): UInt32; external name '_CFStringConvertEncodingToWindowsCodepage';
  587. function CFStringConvertWindowsCodepageToEncoding( codepage: UInt32 ): CFStringEncoding; external name '_CFStringConvertWindowsCodepageToEncoding';
  588. { ID mapping functions from/to IANA registery charset names. Returns kCFStringEncodingInvalidId if no mapping exists.
  589. }
  590. function CFStringConvertIANACharSetNameToEncoding( theString: CFStringRef ): CFStringEncoding; external name '_CFStringConvertIANACharSetNameToEncoding';
  591. function CFStringConvertEncodingToIANACharSetName( encoding: CFStringEncoding ): CFStringRef; external name '_CFStringConvertEncodingToIANACharSetName';
  592. { Returns the most compatible MacOS script value for the input encoding }
  593. { i.e. kCFStringEncodingMacRoman -> kCFStringEncodingMacRoman }
  594. { kCFStringEncodingWindowsLatin1 -> kCFStringEncodingMacRoman }
  595. { kCFStringEncodingISO_2022_JP -> kCFStringEncodingMacJapanese }
  596. function CFStringGetMostCompatibleMacStringEncoding( encoding: CFStringEncoding ): CFStringEncoding; external name '_CFStringGetMostCompatibleMacStringEncoding';
  597. { The next two functions allow fast access to the contents of a string,
  598. assuming you are doing sequential or localized accesses. To use, call
  599. CFStringInitInlineBuffer() with a CFStringInlineBuffer (on the stack, say),
  600. and a range in the string to look at. Then call CFStringGetCharacterFromInlineBuffer()
  601. as many times as you want, with a index into that range (relative to the start
  602. of that range). These are INLINE functions and will end up calling CFString only
  603. once in a while, to fill a buffer. CFStringGetCharacterFromInlineBuffer() returns 0 if
  604. a location outside the original range is specified.
  605. }
  606. const
  607. __kCFStringInlineBufferLength = 64;
  608. type
  609. CFStringInlineBuffer = record
  610. buffer: array[0..__kCFStringInlineBufferLength-1] of UniChar;
  611. theString: CFStringRef;
  612. directBuffer: UniCharPtr;
  613. rangeToBuffer: CFRange; { Range in string to buffer }
  614. bufferedRangeStart: CFIndex; { Start of range currently buffered (relative to rangeToBuffer.location) }
  615. bufferedRangeEnd: CFIndex; { bufferedRangeStart + number of chars actually buffered }
  616. end;
  617. // Not currently converted to Pascal
  618. // #if defined(CF_INLINE)
  619. // CF_INLINE void CFStringInitInlineBuffer(CFStringRef str, CFStringInlineBuffer *buf, CFRange range) {
  620. // buf->theString = str;
  621. // buf->rangeToBuffer = range;
  622. // buf->directBuffer = CFStringGetCharactersPtr(str);
  623. // buf->bufferedRangeStart = buf->bufferedRangeEnd = 0;
  624. // }
  625. //
  626. // CF_INLINE UniChar CFStringGetCharacterFromInlineBuffer(CFStringInlineBuffer *buf, CFIndex idx) {
  627. // if (buf->directBuffer) {
  628. // if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0;
  629. // return buf->directBuffer[idx + buf->rangeToBuffer.location];
  630. // }
  631. // if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) {
  632. // if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0;
  633. // if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0;
  634. // buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength;
  635. // if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length;
  636. // CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer);
  637. // }
  638. // return buf->buffer[idx - buf->bufferedRangeStart];
  639. // }
  640. //
  641. // #else
  642. // { 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).
  643. // }
  644. // #define CFStringInitInlineBuffer(str, buf, range) \
  645. // do {(buf)->theString = str; (buf)->rangeToBuffer = range; (buf)->directBuffer = CFStringGetCharactersPtr(str);} while (0)
  646. //
  647. // #define CFStringGetCharacterFromInlineBuffer(buf, idx) \
  648. // (((idx) < 0 || (idx) >= (buf)->rangeToBuffer.length) ? 0 : ((buf)->directBuffer ? (buf)->directBuffer[(idx) + (buf)->rangeToBuffer.location] : CFStringGetCharacterAtIndex((buf)->theString, (idx) + (buf)->rangeToBuffer.location)))
  649. //
  650. // #endif { CF_INLINE }
  651. { Rest of the stuff in this file is private and should not be used directly
  652. }
  653. { For debugging only
  654. Use CFShow() to printf the description of any CFType;
  655. Use CFShowStr() to printf detailed info about a CFString
  656. }
  657. procedure CFShow( obj: CFTypeRef ); external name '_CFShow';
  658. procedure CFShowStr( str: CFStringRef ); external name '_CFShowStr';
  659. { This function is private and should not be used directly }
  660. function __CFStringMakeConstantString( cStr: ConstCStringPtr ): CFStringRef; external name '___CFStringMakeConstantString'; { Private; do not use }
  661. implementation
  662. end.