-
Notifications
You must be signed in to change notification settings - Fork 0
/
CFString.h
1452 lines (1255 loc) · 42.8 KB
/
CFString.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
File: CFString.h
Contains: CoreFoundation strings
Version: Technology: Mac OS X
Release: Universal Interfaces 3.4
Copyright: © 1999-2001 by Apple Computer, Inc., all rights reserved
Bugs?: For bug reports, consult the following page on
the World Wide Web:
http://developer.apple.com/bugreporter/
*/
#ifndef __CFSTRING__
#define __CFSTRING__
#ifndef __CFBASE__
#include <CFBase.h>
#endif
#ifndef __CFARRAY__
#include <CFArray.h>
#endif
#ifndef __CFDATA__
#include <CFData.h>
#endif
#ifndef __CFDICTIONARY__
#include <CFDictionary.h>
#endif
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
#if PRAGMA_ENUM_ALWAYSINT
#if defined(__fourbyteints__) && !__fourbyteints__
#define __CFSTRING__RESTORE_TWOBYTEINTS
#pragma fourbyteints on
#endif
#pragma enumsalwaysint on
#elif PRAGMA_ENUM_OPTIONS
#pragma option enum=int
#elif PRAGMA_ENUM_PACK
#if __option(pack_enums)
#define __CFSTRING__RESTORE_PACKED_ENUMS
#pragma options(!pack_enums)
#endif
#endif
#include <stdarg.h>
/*
Please note: CFStrings are conceptually an array of Unicode characters.
However, in general, how a CFString stores this array is an implementation
detail. For instance, CFString might choose to use an array of 8-bit characters;
to store its contents; or it might use multiple blocks of memory; or whatever.
Furthermore, the implementation might change depending on the default
system encoding, the user's language, the OS, or even a given release.
What this means is that you should use the following advanced functions with care:
CFStringGetPascalStringPtr()
CFStringGetCStringPtr()
CFStringGetCharactersPtr()
These functions either return the desired pointer quickly, in constant time, or they
return NULL, which indicates you should use some of the other function, as shown
in this example:
Str255 buffer;
StringPtr ptr = CFStringGetPascalStringPtr(str, encoding);
if (ptr == NULL) {
if (CFStringGetPascalString(str, buffer, 256, encoding)) ptr = buffer;
}
Note that CFStringGetPascalString call might still return NULL --- but that will happen
in two circumstances only: The conversion from the UniChar contents of CFString
to the specified encoding fails, or the buffer is too small.
If you need a copy of the buffer in the above example, you might consider simply
calling CFStringGetPascalString() in all cases --- CFStringGetPascalStringPtr()
is simply an optimization.
In addition, the following functions, which create immutable CFStrings from developer
supplied buffers without copying the buffers, might have to actually copy
under certain circumstances (If they do copy, the buffer will be dealt with by the
"contentsDeallocator" argument.):
CFStringCreateWithPascalStringNoCopy()
CFStringCreateWithCStringNoCopy()
CFStringCreateWithCharactersNoCopy()
You should of course never depend on the backing store of these CFStrings being
what you provided, and in other no circumstance should you change the contents
of that buffer (given that would break the invariant about the CFString being immutable).
Having said all this, there are actually ways to create a CFString where the backing store
is external, and can be manipulated by the developer or CFString itself:
CFStringCreateMutableWithExternalCharactersNoCopy()
CFStringSetExternalCharactersNoCopy()
A "contentsAllocator" is used to realloc or free the backing store by CFString.
kCFAllocatorNull can be provided to assure CFString will never realloc or free the buffer.
Developer can call CFStringSetExternalCharactersNoCopy() to update
CFString's idea of what's going on, if the buffer is changed externally. In these
strings, CFStringGetCharactersPtr() is guaranteed to return the external buffer.
These functions are here to allow wrapping a buffer of UniChar characters in a CFString,
allowing the buffer to passed into CFString functions and also manipulated via CFString
mutation functions. In general, developers should not use this technique for all strings,
as it prevents CFString from using certain optimizations.
*/
/* Identifier for character encoding; the values are the same as Text Encoding Converter TextEncoding.
*/
typedef UInt32 CFStringEncoding;
/* Platform-independent built-in encodings; always available on all platforms.
Call CFStringGetSystemEncoding() to get the default system encoding.
*/
enum CFStringBuiltInEncodings {
kCFStringEncodingInvalidId = (long)0xFFFFFFFF,
kCFStringEncodingMacRoman = 0,
kCFStringEncodingWindowsLatin1 = 0x0500, /* ANSI codepage 1252 */
kCFStringEncodingISOLatin1 = 0x0201, /* ISO 8859-1 */
kCFStringEncodingNextStepLatin = 0x0B01, /* NextStep encoding*/
kCFStringEncodingASCII = 0x0600, /* 0..127 (in creating CFString, values greater than 0x7F are treated as corresponding Unicode value) */
kCFStringEncodingUnicode = 0x0100, /* kTextEncodingUnicodeDefault + kTextEncodingDefaultFormat (aka kUnicode16BitFormat) */
kCFStringEncodingUTF8 = 0x08000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF8Format */
kCFStringEncodingNonLossyASCII = 0x0BFF /* 7bit Unicode variants used by YellowBox & Java */
};
typedef enum CFStringBuiltInEncodings CFStringBuiltInEncodings;
/* CFString type ID */
/*
* CFStringGetTypeID()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFTypeID )
CFStringGetTypeID(void);
/* Macro to allow creation of compile-time constant strings; the argument should be a constant string.
CFSTR(), not being a "Copy" or "Create" function, does not return a new
reference for you. So, you should not release the return value. This is
much like constant C or Pascal strings --- when you use "hello world"
in a program, you do not free it.
However, strings returned from CFSTR() can be retained and released in a
properly nested fashion, just like any other CF type. That is, if you pass
a CFSTR() return value to a function such as SetMenuItemWithCFString(), the
function can retain it, then later, when it's done with it, it can release it.
*/
#define CFSTR(cStr) __CFStringMakeConstantString(cStr "")
/*** Immutable string creation functions ***/
/* Functions to create basic immutable strings. The provided allocator is used for all memory activity in these functions.
*/
/* These functions copy the provided buffer into CFString's internal storage. */
/*
* CFStringCreateWithPascalString()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithPascalString(
CFAllocatorRef alloc,
ConstStr255Param pStr,
CFStringEncoding encoding);
/*
* CFStringCreateWithCString()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithCString(
CFAllocatorRef alloc,
const char * cStr,
CFStringEncoding encoding);
/*
* CFStringCreateWithCharacters()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithCharacters(
CFAllocatorRef alloc,
const UniChar * chars,
CFIndex numChars);
/* These functions try not to copy the provided buffer. The buffer will be deallocated
with the provided contentsDeallocator when it's no longer needed; to not free
the buffer, specify kCFAllocatorNull here. As usual, NULL means default allocator.
NOTE: Do not count on these buffers as being used by the string;
in some cases the CFString might free the buffer and use something else
(for instance if it decides to always use Unicode encoding internally).
In addition, some encodings are not used internally; in
those cases CFString might also dump the provided buffer and use its own.
*/
/*
* CFStringCreateWithPascalStringNoCopy()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithPascalStringNoCopy(
CFAllocatorRef alloc,
ConstStr255Param pStr,
CFStringEncoding encoding,
CFAllocatorRef contentsDeallocator);
/*
* CFStringCreateWithCStringNoCopy()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithCStringNoCopy(
CFAllocatorRef alloc,
const char * cStr,
CFStringEncoding encoding,
CFAllocatorRef contentsDeallocator);
/*
* CFStringCreateWithCharactersNoCopy()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithCharactersNoCopy(
CFAllocatorRef alloc,
const UniChar * chars,
CFIndex numChars,
CFAllocatorRef contentsDeallocator);
/* Create copies of part or all of the string.
*/
/*
* CFStringCreateWithSubstring()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithSubstring(
CFAllocatorRef alloc,
CFStringRef str,
CFRange range);
/*
* CFStringCreateCopy()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateCopy(
CFAllocatorRef alloc,
CFStringRef theString);
/* These functions create a CFString from the provided printf-format and arguments.
*/
/*
* CFStringCreateWithFormat()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithFormat(
CFAllocatorRef alloc,
CFDictionaryRef formatOptions,
CFStringRef format,
...);
/*
* CFStringCreateWithFormatAndArguments()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithFormatAndArguments(
CFAllocatorRef alloc,
CFDictionaryRef formatOptions,
CFStringRef format,
va_list arguments);
/* 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.
*/
/*
* CFStringCreateMutable()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFMutableStringRef )
CFStringCreateMutable(
CFAllocatorRef alloc,
CFIndex maxLength);
/*
* CFStringCreateMutableCopy()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFMutableStringRef )
CFStringCreateMutableCopy(
CFAllocatorRef alloc,
CFIndex maxLength,
CFStringRef theString);
/* This function creates a mutable string that has a developer supplied and directly editable backing store.
The string will be manipulated within the provided buffer (if any) until it outgrows capacity; then the
externalCharactersAllocator will be consulted for more memory. When the CFString is deallocated, the
buffer will be freed with the externalCharactersAllocator. Provide kCFAllocatorNull here to prevent the buffer
from ever being reallocated or deallocated by CFString. See comments at top of this file for more info.
*/
/*
* CFStringCreateMutableWithExternalCharactersNoCopy()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFMutableStringRef )
CFStringCreateMutableWithExternalCharactersNoCopy(
CFAllocatorRef alloc,
UniChar * chars,
CFIndex numChars,
CFIndex capacity,
CFAllocatorRef externalCharactersAllocator);
/*** Basic accessors for the contents ***/
/* Number of 16-bit Unicode characters in the string.
*/
/*
* CFStringGetLength()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFIndex )
CFStringGetLength(CFStringRef theString);
/* Extracting the contents of the string. For obtaining multiple characters, calling
CFStringGetCharacters() is more efficient than multiple calls to CFStringGetCharacterAtIndex().
If the length of the string is not known (so you can't use a fixed size buffer for CFStringGetCharacters()),
another method is to use is CFStringGetCharacterFromInlineBuffer() (see further below).
*/
/*
* CFStringGetCharacterAtIndex()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( UniChar )
CFStringGetCharacterAtIndex(
CFStringRef theString,
CFIndex idx);
/*
* CFStringGetCharacters()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( void )
CFStringGetCharacters(
CFStringRef theString,
CFRange range,
UniChar * buffer);
/*** Conversion to other encodings ***/
/* These two convert into the provided buffer; they return FALSE if conversion isn't possible
(due to conversion error, or not enough space in the provided buffer).
These functions do zero-terminate or put the length byte; the provided bufferSize should include
space for this (so pass 256 for Str255). More sophisticated usages can go through CFStringGetBytes().
These functions are equivalent to calling CFStringGetBytes() with
the range of the string; lossByte = 0; and isExternalRepresentation = FALSE;
if successful, they then insert the leading length of terminating zero, as desired.
*/
/*
* CFStringGetPascalString()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( Boolean )
CFStringGetPascalString(
CFStringRef theString,
StringPtr buffer,
CFIndex bufferSize,
CFStringEncoding encoding);
/*
* CFStringGetCString()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( Boolean )
CFStringGetCString(
CFStringRef theString,
char * buffer,
CFIndex bufferSize,
CFStringEncoding encoding);
/* These functions attempt to return in O(1) time the desired format for the string.
Note that although this means a pointer to the internal structure is being returned,
this can't always be counted on. Please see note at the top of the file for more
details.
*/
/*
* CFStringGetPascalStringPtr()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( ConstStringPtr )
CFStringGetPascalStringPtr(
CFStringRef theString,
CFStringEncoding encoding);
/* Be prepared for NULL */
/*
* CFStringGetCStringPtr()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( const char * )
CFStringGetCStringPtr(
CFStringRef theString,
CFStringEncoding encoding);
/* Be prepared for NULL */
/*
* CFStringGetCharactersPtr()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( const UniChar * )
CFStringGetCharactersPtr(CFStringRef theString);
/* Be prepared for NULL */
/* The primitive conversion routine; allows you to convert a string piece at a time
into a fixed size buffer. Returns number of characters converted.
Characters that cannot be converted to the specified encoding are represented
with the byte specified by lossByte; if lossByte is 0, then lossy conversion
is not allowed and conversion stops, returning partial results.
Pass buffer==NULL if you don't care about the converted string (but just the convertability,
or number of bytes required).
maxBufLength indicates the maximum number of bytes to generate. It is ignored when buffer==NULL.
Does not zero-terminate. If you want to create Pascal or C string, allow one extra byte at start or end.
Setting isExternalRepresentation causes any extra bytes that would allow
the data to be made persistent to be included; for instance, the Unicode BOM.
*/
/*
* CFStringGetBytes()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFIndex )
CFStringGetBytes(
CFStringRef theString,
CFRange range,
CFStringEncoding encoding,
UInt8 lossByte,
Boolean isExternalRepresentation,
UInt8 * buffer,
CFIndex maxBufLen,
CFIndex * usedBufLen);
/* This one goes the other way by creating a CFString from a bag of bytes.
This is much like CFStringCreateWithPascalString or CFStringCreateWithCString,
except the length is supplied explicitly. In addition, you can 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
*/
/*
* CFStringCreateWithBytes()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateWithBytes(
CFAllocatorRef alloc,
const UInt8 * bytes,
CFIndex numBytes,
CFStringEncoding encoding,
Boolean isExternalRepresentation);
/* Convenience functions String <-> Data. These generate "external" formats, that is, formats that
can be written out to disk. For instance, if the encoding is Unicode, CFStringCreateFromExternalRepresentation()
pays attention to the BOM character (if any) and does byte swapping if necessary.
Similarly CFStringCreateExternalRepresentation() will always include a BOM character if the encoding is
Unicode. See above for description of lossByte.
*/
/*
* CFStringCreateFromExternalRepresentation()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateFromExternalRepresentation(
CFAllocatorRef alloc,
CFDataRef data,
CFStringEncoding encoding);
/* May return NULL on conversion error */
/*
* CFStringCreateExternalRepresentation()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFDataRef )
CFStringCreateExternalRepresentation(
CFAllocatorRef alloc,
CFStringRef theString,
CFStringEncoding encoding,
UInt8 lossByte);
/* May return NULL on conversion error */
/* Hints about the contents of a string
*/
/*
* CFStringGetSmallestEncoding()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringEncoding )
CFStringGetSmallestEncoding(CFStringRef theString);
/* Result in O(n) time max */
/*
* CFStringGetFastestEncoding()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringEncoding )
CFStringGetFastestEncoding(CFStringRef theString);
/* Result in O(1) time max */
/* General encoding info
*/
/*
* CFStringGetSystemEncoding()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringEncoding )
CFStringGetSystemEncoding(void);
/* The default encoding for the system; untagged 8-bit characters are usually in this encoding */
/*
* CFStringGetMaximumSizeForEncoding()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFIndex )
CFStringGetMaximumSizeForEncoding(
CFIndex length,
CFStringEncoding encoding);
/* Max bytes a string of specified length (in UniChars) will take up if encoded */
/*** Comparison functions. ***/
enum CFStringCompareFlags {
/* Flags used in all find and compare operations */
kCFCompareCaseInsensitive = 1,
kCFCompareBackwards = 4, /* Starting from the end of the string */
kCFCompareAnchored = 8, /* Only at the specified starting point */
kCFCompareNonliteral = 16, /* If specified, loose equivalence is performed (o-umlaut == o, umlaut) */
kCFCompareLocalized = 32, /* User's default locale is used for the comparisons */
kCFCompareNumerically = 64 /* Numeric comparison is used; that is, Foo2.txt < Foo7.txt < Foo25.txt */
};
typedef enum CFStringCompareFlags CFStringCompareFlags;
/* The main comparison routine; compares specified range of the string to another.
locale == NULL indicates canonical locale
*/
/*
* CFStringCompareWithOptions()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFComparisonResult )
CFStringCompareWithOptions(
CFStringRef theString1,
CFStringRef theString2,
CFRange rangeToCompare,
CFOptionFlags compareOptions);
/* Comparison convenience suitable for passing as sorting functions.
*/
/*
* CFStringCompare()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFComparisonResult )
CFStringCompare(
CFStringRef theString1,
CFStringRef theString2,
CFOptionFlags compareOptions);
/* Find routines; CFStringFindWithOptions() returns the found range in the CFRange * argument; You can pass NULL for simple discovery check.
CFStringCreateArrayWithFindResults() returns an array of CFRange pointers, or NULL if there are no matches.
*/
/*
* CFStringFindWithOptions()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( Boolean )
CFStringFindWithOptions(
CFStringRef theString,
CFStringRef stringToFind,
CFRange rangeToSearch,
CFOptionFlags searchOptions,
CFRange * result);
/*
* CFStringCreateArrayWithFindResults()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFArrayRef )
CFStringCreateArrayWithFindResults(
CFAllocatorRef alloc,
CFStringRef theString,
CFStringRef stringToFind,
CFRange rangeToSearch,
CFOptionFlags compareOptions);
/* Find conveniences
*/
/*
* CFStringFind()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFRange )
CFStringFind(
CFStringRef theString,
CFStringRef stringToFind,
CFOptionFlags compareOptions);
/*
* CFStringHasPrefix()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( Boolean )
CFStringHasPrefix(
CFStringRef theString,
CFStringRef prefix);
/*
* CFStringHasSuffix()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( Boolean )
CFStringHasSuffix(
CFStringRef theString,
CFStringRef suffix);
/* Find range of bounds of the line(s) that span the indicated range (startIndex, numChars),
taking into account various possible line separator sequences (CR, CRLF, LF, and Unicode LS, PS).
All return values are "optional" (provide NULL if you don't want them)
lineStartIndex: index of first character in line
lineEndIndex: index of first character of the next line (including terminating line separator characters)
contentsEndIndex: index of the first line separator character
Thus, lineEndIndex - lineStartIndex is the number of chars in the line, including the line separators
contentsEndIndex - lineStartIndex is the number of chars in the line w/out the line separators
*/
/*
* CFStringGetLineBounds()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( void )
CFStringGetLineBounds(
CFStringRef theString,
CFRange range,
CFIndex * lineBeginIndex,
CFIndex * lineEndIndex,
CFIndex * contentsEndIndex);
/*** Exploding and joining strings with a separator string ***/
/*
* CFStringCreateByCombiningStrings()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
CFStringCreateByCombiningStrings(
CFAllocatorRef alloc,
CFArrayRef theArray,
CFStringRef separatorString);
/* Empty array returns empty string; one element array returns the element */
/*
* CFStringCreateArrayBySeparatingStrings()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFArrayRef )
CFStringCreateArrayBySeparatingStrings(
CFAllocatorRef alloc,
CFStringRef theString,
CFStringRef separatorString);
/* No separators in the string returns array with that string; string == sep returns two empty strings */
/*** Parsing non-localized numbers from strings ***/
/*
* CFStringGetIntValue()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( SInt32 )
CFStringGetIntValue(CFStringRef str);
/* Skips whitespace; returns 0 on error, MAX or -MAX on overflow */
/*
* CFStringGetDoubleValue()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( double )
CFStringGetDoubleValue(CFStringRef str);
/* Skips whitespace; returns 0.0 on error */
/*** MutableString functions ***/
/* CFStringAppend("abcdef", "xxxxx") -> "abcdefxxxxx"
CFStringDelete("abcdef", CFRangeMake(2, 3)) -> "abf"
CFStringReplace("abcdef", CFRangeMake(2, 3), "xxxxx") -> "abxxxxxf"
CFStringReplaceAll("abcdef", "xxxxx") -> "xxxxx"
*/
/*
* CFStringAppend()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( void )
CFStringAppend(
CFMutableStringRef theString,
CFStringRef appendedString);
/*
* CFStringAppendCharacters()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( void )
CFStringAppendCharacters(
CFMutableStringRef theString,
const UniChar * chars,
CFIndex numChars);
/*
* CFStringAppendPascalString()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( void )
CFStringAppendPascalString(
CFMutableStringRef theString,
ConstStr255Param pStr,
CFStringEncoding encoding);
/*
* CFStringAppendCString()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( void )
CFStringAppendCString(
CFMutableStringRef theString,
const char * cStr,
CFStringEncoding encoding);
/*
* CFStringAppendFormat()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( void )
CFStringAppendFormat(
CFMutableStringRef theString,
CFDictionaryRef formatOptions,
CFStringRef format,
...);
/*
* CFStringAppendFormatAndArguments()
*
* Availability: