ObjFW
 All Classes Functions Variables
OFString.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #ifndef __STDC_LIMIT_MACROS
18 # define __STDC_LIMIT_MACROS
19 #endif
20 #ifndef __STDC_CONSTANT_MACROS
21 # define __STDC_CONSTANT_MACROS
22 #endif
23 
24 #include <stdarg.h>
25 #include <inttypes.h>
26 
27 #import "OFObject.h"
28 #import "OFSerialization.h"
29 #import "OFJSONRepresentation.h"
30 
31 @class OFConstantString;
32 
33 typedef uint32_t of_unichar_t;
34 
38 typedef enum of_string_encoding_t {
39  OF_STRING_ENCODING_UTF_8,
40  OF_STRING_ENCODING_ASCII,
41  OF_STRING_ENCODING_ISO_8859_1,
42  OF_STRING_ENCODING_ISO_8859_15,
43  OF_STRING_ENCODING_WINDOWS_1252,
44  OF_STRING_ENCODING_AUTODETECT = 0xFF
45 } of_string_encoding_t;
46 
47 enum {
48  OF_STRING_SEARCH_BACKWARDS = 1,
49  OF_STRING_SKIP_EMPTY = 2
50 };
51 
52 /* FIXME */
53 #define OF_STRING_ENCODING_NATIVE OF_STRING_ENCODING_UTF_8
54 
55 #ifdef OF_HAVE_BLOCKS
56 typedef void (^of_string_line_enumeration_block_t)(OFString *line, BOOL *stop);
57 #endif
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 extern int of_string_utf8_check(const char*, size_t, size_t*);
63 extern size_t of_string_utf8_encode(of_unichar_t, char*);
64 extern size_t of_string_utf8_decode(const char*, size_t, of_unichar_t*);
65 extern size_t of_string_utf8_get_index(const char*, size_t);
66 extern size_t of_string_utf8_get_position(const char*, size_t, size_t);
67 extern size_t of_unicode_string_length(const of_unichar_t*);
68 extern size_t of_utf16_string_length(const uint16_t*);
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 @class OFArray;
74 @class OFURL;
75 
87 #ifdef OF_HAVE_PROPERTIES
88 @property (readonly) size_t length;
89 #endif
90 
96 + (instancetype)string;
97 
104 + (instancetype)stringWithUTF8String: (const char*)UTF8String;
105 
114 + (instancetype)stringWithUTF8String: (const char*)UTF8String
115  length: (size_t)UTF8StringLength;
116 
124 + (instancetype)stringWithCString: (const char*)cString
125  encoding: (of_string_encoding_t)encoding;
126 
136 + (instancetype)stringWithCString: (const char*)cString
137  encoding: (of_string_encoding_t)encoding
138  length: (size_t)cStringLength;
139 
146 + (instancetype)stringWithString: (OFString*)string;
147 
154 + (instancetype)stringWithUnicodeString: (const of_unichar_t*)string;
155 
164 + (instancetype)stringWithUnicodeString: (const of_unichar_t*)string
165  byteOrder: (of_byte_order_t)byteOrder;
166 
175 + (instancetype)stringWithUnicodeString: (const of_unichar_t*)string
176  length: (size_t)length;
177 
187 + (instancetype)stringWithUnicodeString: (const of_unichar_t*)string
188  byteOrder: (of_byte_order_t)byteOrder
189  length: (size_t)length;
190 
197 + (instancetype)stringWithUTF16String: (const uint16_t*)string;
198 
207 + (instancetype)stringWithUTF16String: (const uint16_t*)string
208  byteOrder: (of_byte_order_t)byteOrder;
209 
218 + (instancetype)stringWithUTF16String: (const uint16_t*)string
219  length: (size_t)length;
220 
231 + (instancetype)stringWithUTF16String: (const uint16_t*)string
232  byteOrder: (of_byte_order_t)byteOrder
233  length: (size_t)length;
234 
244 + (instancetype)stringWithFormat: (OFConstantString*)format, ...;
245 
252 + (instancetype)stringWithPath: (OFString*)firstComponent, ...;
253 
261 + (instancetype)stringWithContentsOfFile: (OFString*)path;
262 
271 + (instancetype)stringWithContentsOfFile: (OFString*)path
272  encoding: (of_string_encoding_t)encoding;
273 
286 + (instancetype)stringWithContentsOfURL: (OFURL*)URL;
287 
296 + (instancetype)stringWithContentsOfURL: (OFURL*)URL
297  encoding: (of_string_encoding_t)encoding;
298 
306 - initWithUTF8String: (const char*)UTF8String;
307 
316 - initWithUTF8String: (const char*)UTF8String
317  length: (size_t)UTF8StringLength;
318 
330 - initWithUTF8StringNoCopy: (const char*)UTF8String
331  freeWhenDone: (BOOL)freeWhenDone;
332 
341 - initWithCString: (const char*)cString
342  encoding: (of_string_encoding_t)encoding;
343 
353 - initWithCString: (const char*)cString
354  encoding: (of_string_encoding_t)encoding
355  length: (size_t)cStringLength;
356 
363 - initWithString: (OFString*)string;
364 
371 - initWithUnicodeString: (const of_unichar_t*)string;
372 
381 - initWithUnicodeString: (const of_unichar_t*)string
382  byteOrder: (of_byte_order_t)byteOrder;
383 
392 - initWithUnicodeString: (const of_unichar_t*)string
393  length: (size_t)length;
394 
405 - initWithUnicodeString: (const of_unichar_t*)string
406  byteOrder: (of_byte_order_t)byteOrder
407  length: (size_t)length;
408 
415 - initWithUTF16String: (const uint16_t*)string;
416 
425 - initWithUTF16String: (const uint16_t*)string
426  byteOrder: (of_byte_order_t)byteOrder;
427 
436 - initWithUTF16String: (const uint16_t*)string
437  length: (size_t)length;
438 
449 - initWithUTF16String: (const uint16_t*)string
450  byteOrder: (of_byte_order_t)byteOrder
451  length: (size_t)length;
452 
462 - initWithFormat: (OFConstantString*)format, ...;
463 
474 - initWithFormat: (OFConstantString*)format
475  arguments: (va_list)arguments;
476 
484 - initWithPath: (OFString*)firstComponent, ...;
485 
494 - initWithPath: (OFString*)firstComponent
495  arguments: (va_list)arguments;
496 
504 - initWithContentsOfFile: (OFString*)path;
505 
514 - initWithContentsOfFile: (OFString*)path
515  encoding: (of_string_encoding_t)encoding;
516 
530 - initWithContentsOfURL: (OFURL*)URL;
531 
540 - initWithContentsOfURL: (OFURL*)URL
541  encoding: (of_string_encoding_t)encoding;
542 
552 - (const char*)UTF8String OF_RETURNS_INNER_POINTER;
553 
564 - (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
566 
572 - (size_t)length;
573 
579 - (size_t)UTF8StringLength;
580 
588 - (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding;
589 
597 - (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString;
598 
605 - (of_unichar_t)characterAtIndex: (size_t)index;
606 
614 - (void)getCharacters: (of_unichar_t*)buffer
615  inRange: (of_range_t)range;
616 
624 - (of_range_t)rangeOfString: (OFString*)string;
625 
635 - (of_range_t)rangeOfString: (OFString*)string
636  options: (int)options;
637 
648 - (of_range_t)rangeOfString: (OFString*)string
649  options: (int)options
650  range: (of_range_t)range;
651 
658 - (BOOL)containsString: (OFString*)string;
659 
666 - (OFString*)substringWithRange: (of_range_t)range;
667 
674 - (OFString*)stringByAppendingString: (OFString*)string;
675 
682 - (OFString*)stringByAppendingPathComponent: (OFString*)component;
683 
690 - (OFString*)stringByPrependingString: (OFString*)string;
691 
700 - (OFString*)stringByReplacingOccurrencesOfString: (OFString*)string
701  withString: (OFString*)replacement;
702 
714 - (OFString*)stringByReplacingOccurrencesOfString: (OFString*)string
715  withString: (OFString*)replacement
716  options: (int)options
717  range: (of_range_t)range;
718 
725 
732 
743 
750 
757 
765 
772 - (BOOL)hasPrefix: (OFString*)prefix;
773 
780 - (BOOL)hasSuffix: (OFString*)suffix;
781 
788 - (OFArray*)componentsSeparatedByString: (OFString*)delimiter;
789 
798 - (OFArray*)componentsSeparatedByString: (OFString*)delimiter
799  options: (int)options;
800 
807 
814 
821 
835 - (intmax_t)decimalValue;
836 
850 - (uintmax_t)hexadecimalValue;
851 
860 - (float)floatValue;
861 
870 - (double)doubleValue;
871 
881 - (const of_unichar_t*)unicodeString OF_RETURNS_INNER_POINTER;
882 
892 - (const uint16_t*)UTF16String OF_RETURNS_INNER_POINTER;
893 
899 - (void)writeToFile: (OFString*)path;
900 
901 #ifdef OF_HAVE_BLOCKS
902 
907 - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block;
908 #endif
909 @end
910 
911 #import "OFConstantString.h"
912 #import "OFMutableString.h"
913 #import "OFString+Hashing.h"
914 #import "OFString+JSONValue.h"
915 #import "OFString+Serialization.h"
916 #import "OFString+URLEncoding.h"
917 #import "OFString+XMLEscaping.h"
918 #import "OFString+XMLUnescaping.h"
919 
920 #ifndef NSINTEGER_DEFINED
921 /* Required for string boxing literals to work */
922 @compatibility_alias NSString OFString;
923 #endif