ObjFW
OFUTF8String.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFString.h"
17 
18 OF_ASSUME_NONNULL_BEGIN
19 
20 @interface OFUTF8String: OFString
21 {
22  /*
23  * A pointer to the actual data.
24  *
25  * Since constant strings don't have `_storage`, they have to allocate
26  * it on the first access. Strings created at runtime just set the
27  * pointer to `&_storage`.
28  */
29  struct OFUTF8StringIvars {
30  char *cString;
31  size_t cStringLength;
32  bool isUTF8;
33  size_t length;
34  bool hasHash;
35  unsigned long hash;
36  bool freeWhenDone;
37  } *restrict _s;
38  struct OFUTF8StringIvars _storage;
39 }
40 @end
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 extern int OFUTF8StringCheck(const char *, size_t, size_t *);
46 extern size_t OFUTF8StringIndexToPosition(const char *, size_t, size_t);
47 #ifdef __cplusplus
48 }
49 #endif
50 
51 OF_ASSUME_NONNULL_END
A class for handling strings.
Definition: OFString.h:135