ObjFW  Check-in [04ffb67949]

Overview
Comment:Add +[OFString stringWithUnicodeString:length:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 04ffb67949bf2bfde50f39f690fcddb239d3899495229f1713d89a7c4baed4f8
User & Date: js on 2011-05-02 20:46:25
Other Links: manifest | tags
Context
2011-05-04
22:22
Documentation improvements. check-in: 851e47d743 user: js tags: trunk
2011-05-02
20:46
Add +[OFString stringWithUnicodeString:length:]. check-in: 04ffb67949 user: js tags: trunk
13:01
Don't free ret in -[unicodeString] as it is autoreleased now. check-in: 3a1cd610ed user: js tags: trunk
Changes

Modified src/OFString.h from [1412423068] to [379f8259de].

118
119
120
121
122
123
124










125
126
127
128
129
130
131
 * Creates a new OFString from a unicode string.
 *
 * \param string The unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string;











/**
 * Creates a new OFString from a format string.
 * See printf for the format syntax.
 *
 * \param format A string used as format to initialize the OFString
 * \return A new autoreleased OFString
 */







>
>
>
>
>
>
>
>
>
>







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 * Creates a new OFString from a unicode string.
 *
 * \param string The unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string;

/**
 * Creates a new OFString from a unicode string with the specified length.
 *
 * \param string The unicode string
 * \param length The length of the unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string
		   length: (size_t)length;

/**
 * Creates a new OFString from a format string.
 * See printf for the format syntax.
 *
 * \param format A string used as format to initialize the OFString
 * \return A new autoreleased OFString
 */
238
239
240
241
242
243
244











245
246
247
248
249
250
251
 * Initializes an already allocated OFString with a unicode string.
 *
 * \param string The unicode string
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string;












/**
 * Initializes an already allocated OFString with a format string.
 * See printf for the format syntax.
 *
 * \param format A string used as format to initialize the OFString
 * \return An initialized OFString
 */







>
>
>
>
>
>
>
>
>
>
>







248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
 * Initializes an already allocated OFString with a unicode string.
 *
 * \param string The unicode string
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string;

/**
 * Initializes an already allocated OFString with a unicode string with the
 * specified length.
 *
 * \param string The unicode string
 * \param length The length of the unicode string
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string
		 length: (size_t)length;

/**
 * Initializes an already allocated OFString with a format string.
 * See printf for the format syntax.
 *
 * \param format A string used as format to initialize the OFString
 * \return An initialized OFString
 */

Modified src/OFString.m from [b56b81b94d] to [ed76246fb2].

294
295
296
297
298
299
300







301
302
303
304
305
306
307
	return [[[self alloc] initWithString: string] autorelease];
}

+ stringWithUnicodeString: (of_unichar_t*)string
{
	return [[[self alloc] initWithUnicodeString: string] autorelease];
}








+ stringWithFormat: (OFString*)format, ...
{
	id ret;
	va_list arguments;

	va_start(arguments, format);







>
>
>
>
>
>
>







294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
	return [[[self alloc] initWithString: string] autorelease];
}

+ stringWithUnicodeString: (of_unichar_t*)string
{
	return [[[self alloc] initWithUnicodeString: string] autorelease];
}

+ stringWithUnicodeString: (of_unichar_t*)string
		   length: (size_t)length
{
	return [[[self alloc] initWithUnicodeString: string
					     length: length] autorelease];
}

+ stringWithFormat: (OFString*)format, ...
{
	id ret;
	va_list arguments;

	va_start(arguments, format);
539
540
541
542
543
544
545







546
547
548
549
550
551
552
553
554


555
556
557
558

559
560
561
562
563
564
565
566
567
568
	}

	return self;
}

- initWithUnicodeString: (of_unichar_t*)string_
{







	self = [super init];

	@try {
		char buffer[4];
		size_t i = 0;
		BOOL swap = NO;

		if (*string_ == 0xFEFF)
			string_++;



		if (*string_ == 0xFFFE0000) {
			swap = YES;
			string_++;

		}

		length = of_unicode_string_length(string_);
		string = [self allocMemoryWithSize: length + 1];

		while (*string_ != '\0') {
			size_t characterLen;

			if (swap)
				characterLen = of_string_unicode_to_utf8(







>
>
>
>
>
>
>







|

>
>




>


|







546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
	}

	return self;
}

- initWithUnicodeString: (of_unichar_t*)string_
{
	return [self initWithUnicodeString: string_
				    length: of_unicode_string_length(string_)];
}

- initWithUnicodeString: (of_unichar_t*)string_
		 length: (size_t)length_
{
	self = [super init];

	@try {
		char buffer[4];
		size_t i = 0;
		BOOL swap = NO;

		if (*string_ == 0xFEFF) {
			string_++;
			length_--;
		}

		if (*string_ == 0xFFFE0000) {
			swap = YES;
			string_++;
			length_--;
		}

		length = length_;
		string = [self allocMemoryWithSize: length + 1];

		while (*string_ != '\0') {
			size_t characterLen;

			if (swap)
				characterLen = of_string_unicode_to_utf8(