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 
81 #ifdef OF_HAVE_PROPERTIES
82 @property (readonly) size_t length;
83 #endif
84 
90 + (instancetype)string;
91 
98 + (instancetype)stringWithUTF8String: (const char*)UTF8String;
99 
108 + (instancetype)stringWithUTF8String: (const char*)UTF8String
109  length: (size_t)UTF8StringLength;
110 
118 + (instancetype)stringWithCString: (const char*)cString
119  encoding: (of_string_encoding_t)encoding;
120 
130 + (instancetype)stringWithCString: (const char*)cString
131  encoding: (of_string_encoding_t)encoding
132  length: (size_t)cStringLength;
133 
140 + (instancetype)stringWithString: (OFString*)string;
141 
148 + (instancetype)stringWithUnicodeString: (const of_unichar_t*)string;
149 
158 + (instancetype)stringWithUnicodeString: (const of_unichar_t*)string
159  byteOrder: (of_byte_order_t)byteOrder;
160 
169 + (instancetype)stringWithUnicodeString: (const of_unichar_t*)string
170  length: (size_t)length;
171 
181 + (instancetype)stringWithUnicodeString: (const of_unichar_t*)string
182  byteOrder: (of_byte_order_t)byteOrder
183  length: (size_t)length;
184 
191 + (instancetype)stringWithUTF16String: (const uint16_t*)string;
192 
201 + (instancetype)stringWithUTF16String: (const uint16_t*)string
202  byteOrder: (of_byte_order_t)byteOrder;
203 
212 + (instancetype)stringWithUTF16String: (const uint16_t*)string
213  length: (size_t)length;
214 
225 + (instancetype)stringWithUTF16String: (const uint16_t*)string
226  byteOrder: (of_byte_order_t)byteOrder
227  length: (size_t)length;
228 
238 + (instancetype)stringWithFormat: (OFConstantString*)format, ...;
239 
246 + (instancetype)stringWithPath: (OFString*)firstComponent, ... OF_SENTINEL;
247 
255 + (instancetype)stringWithContentsOfFile: (OFString*)path;
256 
265 + (instancetype)stringWithContentsOfFile: (OFString*)path
266  encoding: (of_string_encoding_t)encoding;
267 
280 + (instancetype)stringWithContentsOfURL: (OFURL*)URL;
281 
290 + (instancetype)stringWithContentsOfURL: (OFURL*)URL
291  encoding: (of_string_encoding_t)encoding;
292 
300 - initWithUTF8String: (const char*)UTF8String;
301 
310 - initWithUTF8String: (const char*)UTF8String
311  length: (size_t)UTF8StringLength;
312 
324 - initWithUTF8StringNoCopy: (const char*)UTF8String
325  freeWhenDone: (BOOL)freeWhenDone;
326 
335 - initWithCString: (const char*)cString
336  encoding: (of_string_encoding_t)encoding;
337 
347 - initWithCString: (const char*)cString
348  encoding: (of_string_encoding_t)encoding
349  length: (size_t)cStringLength;
350 
357 - initWithString: (OFString*)string;
358 
365 - initWithUnicodeString: (const of_unichar_t*)string;
366 
375 - initWithUnicodeString: (const of_unichar_t*)string
376  byteOrder: (of_byte_order_t)byteOrder;
377 
386 - initWithUnicodeString: (const of_unichar_t*)string
387  length: (size_t)length;
388 
399 - initWithUnicodeString: (const of_unichar_t*)string
400  byteOrder: (of_byte_order_t)byteOrder
401  length: (size_t)length;
402 
409 - initWithUTF16String: (const uint16_t*)string;
410 
419 - initWithUTF16String: (const uint16_t*)string
420  byteOrder: (of_byte_order_t)byteOrder;
421 
430 - initWithUTF16String: (const uint16_t*)string
431  length: (size_t)length;
432 
443 - initWithUTF16String: (const uint16_t*)string
444  byteOrder: (of_byte_order_t)byteOrder
445  length: (size_t)length;
446 
456 - initWithFormat: (OFConstantString*)format, ...;
457 
468 - initWithFormat: (OFConstantString*)format
469  arguments: (va_list)arguments;
470 
478 - initWithPath: (OFString*)firstComponent, ... OF_SENTINEL;
479 
488 - initWithPath: (OFString*)firstComponent
489  arguments: (va_list)arguments;
490 
498 - initWithContentsOfFile: (OFString*)path;
499 
508 - initWithContentsOfFile: (OFString*)path
509  encoding: (of_string_encoding_t)encoding;
510 
524 - initWithContentsOfURL: (OFURL*)URL;
525 
534 - initWithContentsOfURL: (OFURL*)URL
535  encoding: (of_string_encoding_t)encoding;
536 
546 - (const char*)UTF8String OF_RETURNS_INNER_POINTER;
547 
558 - (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
560 
566 - (size_t)length;
567 
573 - (size_t)UTF8StringLength;
574 
582 - (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding;
583 
591 - (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString;
592 
599 - (of_unichar_t)characterAtIndex: (size_t)index;
600 
608 - (void)getCharacters: (of_unichar_t*)buffer
609  inRange: (of_range_t)range;
610 
618 - (of_range_t)rangeOfString: (OFString*)string;
619 
630 - (of_range_t)rangeOfString: (OFString*)string
631  options: (int)options;
632 
644 - (of_range_t)rangeOfString: (OFString*)string
645  options: (int)options
646  range: (of_range_t)range;
647 
654 - (BOOL)containsString: (OFString*)string;
655 
662 - (OFString*)substringWithRange: (of_range_t)range;
663 
670 - (OFString*)stringByAppendingString: (OFString*)string;
671 
678 - (OFString*)stringByAppendingPathComponent: (OFString*)component;
679 
686 - (OFString*)stringByPrependingString: (OFString*)string;
687 
696 - (OFString*)stringByReplacingOccurrencesOfString: (OFString*)string
697  withString: (OFString*)replacement;
698 
711 - (OFString*)stringByReplacingOccurrencesOfString: (OFString*)string
712  withString: (OFString*)replacement
713  options: (int)options
714  range: (of_range_t)range;
715 
722 
729 
740 
747 
754 
762 
769 - (BOOL)hasPrefix: (OFString*)prefix;
770 
777 - (BOOL)hasSuffix: (OFString*)suffix;
778 
785 - (OFArray*)componentsSeparatedByString: (OFString*)delimiter;
786 
796 - (OFArray*)componentsSeparatedByString: (OFString*)delimiter
797  options: (int)options;
798 
805 
812 
819 
833 - (intmax_t)decimalValue;
834 
848 - (uintmax_t)hexadecimalValue;
849 
858 - (float)floatValue;
859 
868 - (double)doubleValue;
869 
879 - (const of_unichar_t*)unicodeString OF_RETURNS_INNER_POINTER;
880 
890 - (const uint16_t*)UTF16String OF_RETURNS_INNER_POINTER;
891 
897 - (void)writeToFile: (OFString*)path;
898 
899 #ifdef OF_HAVE_BLOCKS
900 
905 - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block;
906 #endif
907 @end
908 
909 #import "OFConstantString.h"
910 #import "OFMutableString.h"
911 #import "OFString+Hashing.h"
912 #import "OFString+JSONValue.h"
913 #import "OFString+Serialization.h"
914 #import "OFString+URLEncoding.h"
915 #import "OFString+XMLEscaping.h"
916 #import "OFString+XMLUnescaping.h"
917 
918 #ifndef NSINTEGER_DEFINED
919 /* Required for string boxing literals to work */
920 @compatibility_alias NSString OFString;
921 #endif