16 #ifndef OBJFW_OF_STRING_H
17 #define OBJFW_OF_STRING_H
19 #ifndef __STDC_LIMIT_MACROS
20 # define __STDC_LIMIT_MACROS
22 #ifndef __STDC_CONSTANT_MACROS
23 # define __STDC_CONSTANT_MACROS
26 #include "objfw-defs.h"
28 #ifdef OF_HAVE_SYS_TYPES_H
29 # include <sys/types.h>
34 #ifdef OF_HAVE_INTTYPES_H
35 # include <inttypes.h>
40 # import "OFSerialization.h"
41 # import "OFJSONRepresentation.h"
42 # import "OFMessagePackRepresentation.h"
45 OF_ASSUME_NONNULL_BEGIN
56 #if defined(__cplusplus) && __cplusplus >= 201103L
57 typedef char16_t of_char16_t;
58 typedef char32_t of_char32_t;
60 typedef uint_least16_t of_char16_t;
61 typedef uint_least32_t of_char32_t;
63 typedef of_char32_t of_unichar_t;
106 OF_STRING_SEARCH_BACKWARDS = 1,
107 OF_STRING_SKIP_EMPTY = 2
110 #ifdef OF_HAVE_BLOCKS
122 @class OFArray OF_GENERIC(ObjectType);
136 @property (readonly, nonatomic)
size_t length;
145 @property (readonly, nonatomic)
const char *
UTF8String OF_RETURNS_INNER_POINTER;
220 @property (readonly, nonatomic)
const of_unichar_t *
characters
221 OF_RETURNS_INNER_POINTER;
231 OF_RETURNS_INNER_POINTER;
246 OF_RETURNS_INNER_POINTER;
263 # ifdef OF_HAVE_UNICODE_TABLES
272 @property (readonly, nonatomic)
280 @property (readonly, nonatomic)
281 OFString *stringByExpandingWindowsEnvironmentStrings;
297 + (instancetype)stringWithUTF8String: (const
char *)UTF8String;
307 + (instancetype)stringWithUTF8String: (const
char *)UTF8String
308 length: (
size_t)UTF8StringLength;
324 + (instancetype)stringWithUTF8StringNoCopy: (
char *)UTF8String
325 freeWhenDone: (
bool)freeWhenDone;
342 + (instancetype)stringWithUTF8StringNoCopy: (
char *)UTF8String
343 length: (
size_t)UTF8StringLength
344 freeWhenDone: (
bool)freeWhenDone;
353 + (instancetype)stringWithCString: (const
char *)cString
365 + (instancetype)stringWithCString: (const
char *)cString
367 length: (
size_t)cStringLength;
376 + (instancetype)stringWithData: (
OFData *)data
385 + (instancetype)stringWithString: (
OFString *)string;
395 + (instancetype)stringWithCharacters: (const of_unichar_t *)characters
396 length: (
size_t)length;
404 + (instancetype)stringWithUTF16String: (const of_char16_t *)string;
414 + (instancetype)stringWithUTF16String: (const of_char16_t *)string
415 length: (
size_t)length;
425 + (instancetype)stringWithUTF16String: (const of_char16_t *)string
438 + (instancetype)stringWithUTF16String: (const of_char16_t *)string
439 length: (
size_t)length
448 + (instancetype)stringWithUTF32String: (const of_char32_t *)string;
458 + (instancetype)stringWithUTF32String: (const of_char32_t *)string
459 length: (
size_t)length;
469 + (instancetype)stringWithUTF32String: (const of_char32_t *)string
482 + (instancetype)stringWithUTF32String: (const of_char32_t *)string
483 length: (
size_t)length
498 # ifdef OF_HAVE_FILES
506 + (instancetype)stringWithContentsOfFile: (
OFString *)path;
516 + (instancetype)stringWithContentsOfFile: (
OFString *)path
532 + (instancetype)stringWithContentsOfURL: (
OFURL *)URL;
542 + (instancetype)stringWithContentsOfURL: (
OFURL *)URL
552 - (instancetype)initWithUTF8String: (const
char *)UTF8String;
562 - (instancetype)initWithUTF8String: (const
char *)UTF8String
563 length: (
size_t)UTF8StringLength;
579 - (instancetype)initWithUTF8StringNoCopy: (
char *)UTF8String
580 freeWhenDone: (
bool)freeWhenDone;
598 - (instancetype)initWithUTF8StringNoCopy: (
char *)UTF8String
599 length: (
size_t)UTF8StringLength
600 freeWhenDone: (
bool)freeWhenDone;
610 - (instancetype)initWithCString: (const
char *)cString
622 - (instancetype)initWithCString: (const
char *)cString
624 length: (
size_t)cStringLength;
634 - (instancetype)initWithData: (
OFData *)data
643 - (instancetype)initWithString: (
OFString *)string;
653 - (instancetype)initWithCharacters: (const of_unichar_t *)characters
654 length: (
size_t)length;
662 - (instancetype)initWithUTF16String: (const of_char16_t *)string;
672 - (instancetype)initWithUTF16String: (const of_char16_t *)string
673 length: (
size_t)length;
683 - (instancetype)initWithUTF16String: (const of_char16_t *)string
696 - (instancetype)initWithUTF16String: (const of_char16_t *)string
697 length: (
size_t)length
706 - (instancetype)initWithUTF32String: (const of_char32_t *)string;
716 - (instancetype)initWithUTF32String: (const of_char32_t *)string
717 length: (
size_t)length;
727 - (instancetype)initWithUTF32String: (const of_char32_t *)string
740 - (instancetype)initWithUTF32String: (const of_char32_t *)string
741 length: (
size_t)length
768 arguments: (va_list)arguments;
770 # ifdef OF_HAVE_FILES
778 - (instancetype)initWithContentsOfFile: (
OFString *)path;
788 - (instancetype)initWithContentsOfFile: (
OFString *)path
805 - (instancetype)initWithContentsOfURL: (
OFURL *)URL;
815 - (instancetype)initWithContentsOfURL: (
OFURL *)URL
829 - (size_t)getCString: (
char *)cString
830 maxLength: (
size_t)maxLength
845 - (size_t)getLossyCString: (
char *)cString
846 maxLength: (
size_t)maxLength
860 OF_RETURNS_INNER_POINTER;
875 OF_RETURNS_INNER_POINTER;
901 - (of_unichar_t)characterAtIndex: (
size_t)index;
910 - (void)getCharacters: (of_unichar_t *)buffer inRange: (
of_range_t)range;
949 options: (
int)options
959 - (size_t)indexOfCharacterFromSet: (
OFCharacterSet *)characterSet;
974 options: (
int)options;
990 options: (
int)options
999 - (bool)containsString: (
OFString *)string;
1007 - (
OFString *)substringFromIndex: (
size_t)idx;
1015 - (
OFString *)substringToIndex: (
size_t)idx;
1042 - (
long long)longLongValueWithBase: (
int)base;
1062 - (
unsigned long long)unsignedLongLongValueWithBase: (
int)base;
1088 arguments: (va_list)arguments;
1107 withString: (
OFString *)replacement;
1122 withString: (
OFString *)replacement
1123 options: (
int)options
1132 - (bool)hasPrefix: (
OFString *)prefix;
1140 - (bool)hasSuffix: (
OFString *)suffix;
1150 componentsSeparatedByString: (
OFString *)delimiter;
1165 componentsSeparatedByString: (
OFString *)delimiter
1166 options: (
int)options;
1176 componentsSeparatedByCharactersInSet: (
OFCharacterSet *)characterSet;
1191 componentsSeparatedByCharactersInSet: (
OFCharacterSet *)characterSet
1192 options: (
int)options;
1204 - (const of_char16_t *)UTF16StringWithByteOrder: (
of_byte_order_t)byteOrder
1205 OF_RETURNS_INNER_POINTER;
1217 - (const of_char32_t *)UTF32StringWithByteOrder: (
of_byte_order_t)byteOrder
1218 OF_RETURNS_INNER_POINTER;
1228 # ifdef OF_HAVE_FILES
1234 - (void)writeToFile: (
OFString *)path;
1251 - (void)writeToURL: (
OFURL *)URL;
1261 # ifdef OF_HAVE_BLOCKS
1277 extern size_t of_string_utf8_encode(of_unichar_t,
char *);
1278 extern ssize_t of_string_utf8_decode(
const char *,
size_t, of_unichar_t *);
1279 extern size_t of_string_utf16_length(
const of_char16_t *);
1280 extern size_t of_string_utf32_length(
const of_char32_t *);
1285 OF_ASSUME_NONNULL_END
1287 #include "OFConstantString.h"
1288 #include "OFMutableString.h"
1290 # import "OFString+CryptoHashing.h"
1291 # import "OFString+JSONParsing.h"
1292 # ifdef OF_HAVE_FILES
1293 # import "OFString+PathAdditions.h"
1295 # import "OFString+PropertyListParsing.h"
1296 # import "OFString+Serialization.h"
1297 # import "OFString+URLEncoding.h"
1298 # import "OFString+XMLEscaping.h"
1302 #if defined(__OBJC__) && !defined(NSINTEGER_DEFINED) && !__has_feature(modules)
of_byte_order_t
An enum for storing endianess.
Definition: OFObject.h:81
of_comparison_result_t
A result of a comparison.
Definition: OFObject.h:57
void(^ of_string_line_enumeration_block_t)(OFString *line, bool *stop)
A block for enumerating the lines of a string.
Definition: OFString.h:118
of_string_encoding_t
The encoding of a string.
Definition: OFString.h:68
@ OF_STRING_ENCODING_KOI8_R
Definition: OFString.h:98
@ OF_STRING_ENCODING_UTF_8
Definition: OFString.h:74
@ OF_STRING_ENCODING_ISO_8859_3
Definition: OFString.h:82
@ OF_STRING_ENCODING_MAC_ROMAN
Definition: OFString.h:96
@ OF_STRING_ENCODING_ISO_8859_15
Definition: OFString.h:84
@ OF_STRING_ENCODING_WINDOWS_1252
Definition: OFString.h:88
@ OF_STRING_ENCODING_KOI8_U
Definition: OFString.h:100
@ OF_STRING_ENCODING_ISO_8859_1
Definition: OFString.h:78
@ OF_STRING_ENCODING_ISO_8859_2
Definition: OFString.h:80
@ OF_STRING_ENCODING_ASCII
Definition: OFString.h:76
@ OF_STRING_ENCODING_CODEPAGE_858
Definition: OFString.h:94
@ OF_STRING_ENCODING_CODEPAGE_850
Definition: OFString.h:92
@ OF_STRING_ENCODING_CODEPAGE_437
Definition: OFString.h:90
@ OF_STRING_ENCODING_AUTODETECT
Definition: OFString.h:102
@ OF_STRING_ENCODING_WINDOWS_1251
Definition: OFString.h:86
An abstract class for storing objects in an array.
Definition: OFArray.h:92
A class cluster representing a character set.
Definition: OFCharacterSet.h:29
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
A class for storing arbitrary data in an array.
Definition: OFData.h:40
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class for handling strings.
Definition: OFString.h:132
const of_unichar_t * characters
The string as an array of Unicode characters.
Definition: OFString.h:221
OFString * stringByDeletingEnclosingWhitespaces
The string with leading and trailing whitespaces deleted.
Definition: OFString.h:261
const char * UTF8String
The OFString as a UTF-8 encoded C string.
Definition: OFString.h:145
OFString * lowercaseString
The string in lowercase.
Definition: OFString.h:160
unsigned long long unsignedLongLongValue
The decimal value of the string as an unsigned long long.
Definition: OFString.h:195
size_t UTF16StringLength
The length of the string in UTF-16 characters.
Definition: OFString.h:236
double doubleValue
The double value of the string as a double.
Definition: OFString.h:211
OFString * decomposedStringWithCanonicalMapping
The string in Unicode Normalization Form D (NFD).
Definition: OFString.h:267
OFString * uppercaseString
The string in uppercase.
Definition: OFString.h:155
float floatValue
The float value of the string as a float.
Definition: OFString.h:203
OFString * stringByDeletingTrailingWhitespaces
The string with trailing whitespaces deleted.
Definition: OFString.h:256
size_t UTF8StringLength
The number of bytes the string needs in UTF-8 encoding.
Definition: OFString.h:150
const of_char16_t * UTF16String
The string in UTF-16 encoding with native byte order.
Definition: OFString.h:231
size_t length
The length of the string in Unicode codepoints.
Definition: OFString.h:136
const of_char32_t * UTF32String
The string in UTF-32 encoding with native byte order.
Definition: OFString.h:246
long long longLongValue
The decimal value of the string as a long long.
Definition: OFString.h:182
OFString * capitalizedString
The string in capitalized form.
Definition: OFString.h:169
OFString * decomposedStringWithCompatibilityMapping
The string in Unicode Normalization Form KD (NFKD).
Definition: OFString.h:273
instancetype string()
Creates a new OFString.
Definition: OFString.m:634
OFString * stringByDeletingLeadingWhitespaces
The string with leading whitespaces deleted.
Definition: OFString.h:251
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:34
A protocol for comparing objects.
Definition: OFObject.h:1224
A protocol for the creation of copies.
Definition: OFObject.h:1187
A protocol implemented by classes that support encoding to a JSON representation.
Definition: OFJSONRepresentation.h:39
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:29
A protocol for the creation of mutable copies.
Definition: OFObject.h:1208
A protocol for serializing objects.
Definition: OFSerialization.h:29
A range.
Definition: OFObject.h:93