ObjFW  Check-in [b55b4ab87b]

Overview
Comment:Fix +[OFString stringWithUTF8StringNoCopy:…].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b55b4ab87be9e4154fdd9ae0f90c8e7f406492deeeb10bb8c052d421443dfb31
User & Date: js on 2012-12-09 12:31:56
Other Links: manifest | tags
Context
2012-12-09
12:33
OFHTTPClient: Don't depend on OFString internals. check-in: 6888885299 user: js tags: trunk
12:31
Fix +[OFString stringWithUTF8StringNoCopy:…]. check-in: b55b4ab87b user: js tags: trunk
12:13
Split OFHTTPRequest into OFHTTP{Client,Request}. check-in: 2b7a70e246 user: js tags: trunk
Changes

Modified src/OFString.h from [2e05b802ef] to [af8955aa05].

104
105
106
107
108
109
110












111
112
113
114
115
116
117
 * @param UTF8String A UTF-8 encoded C string to initialize the OFString with
 * @param UTF8StringLength The length of the UTF-8 encoded C string
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithUTF8String: (const char*)UTF8String
			      length: (size_t)UTF8StringLength;













/*!
 * @brief Creates a new OFString from a C string with the specified encoding.
 *
 * @param cString A C string to initialize the OFString with
 * @param encoding The encoding of the C string
 * @return A new autoreleased OFString
 */







>
>
>
>
>
>
>
>
>
>
>
>







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
 * @param UTF8String A UTF-8 encoded C string to initialize the OFString with
 * @param UTF8StringLength The length of the UTF-8 encoded C string
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithUTF8String: (const char*)UTF8String
			      length: (size_t)UTF8StringLength;

/*!
 * @brief Creates a new OFString from a UTF-8 encoded C string without copying
 *	  the string.
 *
 * @param UTF8String A UTF-8 encoded C string to initialize the OFString with
 * @param freeWhenDone Whether to free the C string when the OFString gets
 *		       deallocated
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithUTF8StringNoCopy: (const char*)UTF8String
			      freeWhenDone: (BOOL)freeWhenDone;

/*!
 * @brief Creates a new OFString from a C string with the specified encoding.
 *
 * @param cString A C string to initialize the OFString with
 * @param encoding The encoding of the C string
 * @return A new autoreleased OFString
 */

Modified src/OFString.m from [376b86841b] to [90ef2353c5].

366
367
368
369
370
371
372








373
374
375
376
377
378
379
+ (instancetype)stringWithUTF8String: (const char*)UTF8String
			      length: (size_t)UTF8StringLength
{
	return [[[self alloc]
	    initWithUTF8String: UTF8String
			length: UTF8StringLength] autorelease];
}









+ (instancetype)stringWithCString: (const char*)cString
			 encoding: (of_string_encoding_t)encoding
{
	return [[[self alloc] initWithCString: cString
				     encoding: encoding] autorelease];
}







>
>
>
>
>
>
>
>







366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
+ (instancetype)stringWithUTF8String: (const char*)UTF8String
			      length: (size_t)UTF8StringLength
{
	return [[[self alloc]
	    initWithUTF8String: UTF8String
			length: UTF8StringLength] autorelease];
}

+ (instancetype)stringWithUTF8StringNoCopy: (const char*)UTF8String
			      freeWhenDone: (BOOL)freeWhenDone
{
	return [[[self alloc]
	    initWithUTF8StringNoCopy: UTF8String
			freeWhenDone: freeWhenDone] autorelease];
}

+ (instancetype)stringWithCString: (const char*)cString
			 encoding: (of_string_encoding_t)encoding
{
	return [[[self alloc] initWithCString: cString
				     encoding: encoding] autorelease];
}

Modified src/OFString_UTF8.m from [7a3937da16] to [b90943c641].

401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428



429
430
431
432
433
434
435
		@throw e;
	}

	return self;
}

- initWithUTF8StringNoCopy: (const char*)UTF8String
	      freeWhenDone: (BOOL)freeWhenDone
{
	self = [super init];

	@try {
		size_t UTF8StringLength = strlen(UTF8String);

		if (freeWhenDone)
			s->freeWhenDone = (char*)UTF8String;

		if (UTF8StringLength >= 3 &&
		    !memcmp(UTF8String, "\xEF\xBB\xBF", 3)) {
			UTF8String += 3;
			UTF8StringLength -= 3;
		}

		s = &s_store;

		s->cString = (char*)UTF8String;
		s->cStringLength = UTF8StringLength;




		switch (of_string_utf8_check(UTF8String, UTF8StringLength,
		    &s->length)) {
		case 1:
			s->isUTF8 = YES;
			break;
		case -1:
			@throw [OFInvalidEncodingException







|





<
<
|












>
>
>







401
402
403
404
405
406
407
408
409
410
411
412
413


414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
		@throw e;
	}

	return self;
}

- initWithUTF8StringNoCopy: (const char*)UTF8String
	      freeWhenDone: (BOOL)freeWhenDone_
{
	self = [super init];

	@try {
		size_t UTF8StringLength = strlen(UTF8String);


		char *freeWhenDone = (char*)UTF8String;

		if (UTF8StringLength >= 3 &&
		    !memcmp(UTF8String, "\xEF\xBB\xBF", 3)) {
			UTF8String += 3;
			UTF8StringLength -= 3;
		}

		s = &s_store;

		s->cString = (char*)UTF8String;
		s->cStringLength = UTF8StringLength;

		if (freeWhenDone_)
			s->freeWhenDone = freeWhenDone;

		switch (of_string_utf8_check(UTF8String, UTF8StringLength,
		    &s->length)) {
		case 1:
			s->isUTF8 = YES;
			break;
		case -1:
			@throw [OFInvalidEncodingException