ObjFW  Diff

Differences From Artifact [ad8cbdf010]:

To Artifact [31ec44e41b]:

  • File src/OFString.h — part of check-in [9d3cd5e5fe] at 2013-01-07 22:07:58 on branch trunk — OFString: Zero-terminate UTF-16 strings.

    This partly reverts e8502c7.

    The rationale behind this is that, on some OSes, native APIs (on e.g.
    Windows) take UTF-16 strings that are zero-terminated.

    However, forcing zero-termination for every string so that -[characters]
    returns a zero-terminated UTF-32 string does not make sense. Therefore,
    in the future, -[UTF32String] will be added, which will include
    zero-termination. OFString subclasses can then just return their
    internal representation if it includes a terminating zero or create a
    copy that has a terminating zero if not. (user: js, size: 28671) [annotate] [blame] [check-ins using]


158
159
160
161
162
163
164
165








166
167
168
169
170
171
172
173
174











175
176
177
178
179
180
181
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithCharacters: (const of_unichar_t*)characters
			      length: (size_t)length
			   byteOrder: (of_byte_order_t)byteOrder;

/*!
 * @brief Creates a new OFString from a big endian UTF-16 encoded string with








 *	  the specified length.
 *
 * @param string The UTF-16 string
 * @param length The length of the unicode string
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithUTF16String: (const uint16_t*)string
			       length: (size_t)length;












/*!
 * @brief Creates a new OFString from a UTF-16 encoded string with the
 *	  specified length, assuming the specified byte order if no BOM is
 *	  found.
 *
 * @param string The UTF-16 string
 * @param length The length of the unicode string







|
>
>
>
>
>
>
>
>
|








>
>
>
>
>
>
>
>
>
>
>







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
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithCharacters: (const of_unichar_t*)characters
			      length: (size_t)length
			   byteOrder: (of_byte_order_t)byteOrder;

/*!
 * @brief Creates a new OFString from a UTF-16 encoded string.
 *
 * @param string The UTF-16 string
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithUTF16String: (const uint16_t*)string;

/*!
 * @brief Creates a new OFString from a UTF-16 encoded string with the specified
 *	  length.
 *
 * @param string The UTF-16 string
 * @param length The length of the unicode string
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithUTF16String: (const uint16_t*)string
			       length: (size_t)length;

/*!
 * @brief Creates a new OFString from a UTF-16 encoded string, assuming the
 *	  specified byte order if no BOM is found.
 *
 * @param string The UTF-16 string
 * @param byteOrder The byte order to assume if there is no BOM
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithUTF16String: (const uint16_t*)string
			    byteOrder: (of_byte_order_t)byteOrder;

/*!
 * @brief Creates a new OFString from a UTF-16 encoded string with the
 *	  specified length, assuming the specified byte order if no BOM is
 *	  found.
 *
 * @param string The UTF-16 string
 * @param length The length of the unicode string
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
 * @param byteOrder The byte order to assume if there is no BOM
 * @return An initialized OFString
 */
- initWithCharacters: (const of_unichar_t*)characters
	      length: (size_t)length
	   byteOrder: (of_byte_order_t)byteOrder;









/*!
 * @brief Initializes an already allocated OFString with a UTF-16 string with
 *	  the specified length.
 *
 * @param string The UTF-16 string
 * @param length The length of the UTF-16 string
 * @return An initialized OFString
 */
- initWithUTF16String: (const uint16_t*)string
	       length: (size_t)length;












/*!
 * @brief Initializes an already allocated OFString with a UTF-16 string with
 *	  the specified length, assuming the specified byte order if no BOM is
 *	  found.
 *
 * @param string The UTF-16 string
 * @param length The length of the UTF-16 string







>
>
>
>
>
>
>
>











>
>
>
>
>
>
>
>
>
>
>







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
 * @param byteOrder The byte order to assume if there is no BOM
 * @return An initialized OFString
 */
- initWithCharacters: (const of_unichar_t*)characters
	      length: (size_t)length
	   byteOrder: (of_byte_order_t)byteOrder;

/*!
 * @brief Initializes an already allocated OFString with a UTF-16 string.
 *
 * @param string The UTF-16 string
 * @return An initialized OFString
 */
- initWithUTF16String: (const uint16_t*)string;

/*!
 * @brief Initializes an already allocated OFString with a UTF-16 string with
 *	  the specified length.
 *
 * @param string The UTF-16 string
 * @param length The length of the UTF-16 string
 * @return An initialized OFString
 */
- initWithUTF16String: (const uint16_t*)string
	       length: (size_t)length;

/*!
 * @brief Initializes an already allocated OFString with a UTF-16 string,
 *	  assuming the specified byte order if no BOM is found.
 *
 * @param string The UTF-16 string
 * @param byteOrder The byte order to assume if there is no BOM
 * @return An initialized OFString
 */
- initWithUTF16String: (const uint16_t*)string
	    byteOrder: (of_byte_order_t)byteOrder;

/*!
 * @brief Initializes an already allocated OFString with a UTF-16 string with
 *	  the specified length, assuming the specified byte order if no BOM is
 *	  found.
 *
 * @param string The UTF-16 string
 * @param length The length of the UTF-16 string
898
899
900
901
902
903
904

905
906
907
#endif

#ifdef __cplusplus
extern "C" {
#endif
extern size_t of_string_utf8_encode(of_unichar_t, char*);
extern size_t of_string_utf8_decode(const char*, size_t, of_unichar_t*);

#ifdef __cplusplus
}
#endif







>



936
937
938
939
940
941
942
943
944
945
946
#endif

#ifdef __cplusplus
extern "C" {
#endif
extern size_t of_string_utf8_encode(of_unichar_t, char*);
extern size_t of_string_utf8_decode(const char*, size_t, of_unichar_t*);
extern size_t of_string_utf16_length(const uint16_t*);
#ifdef __cplusplus
}
#endif