ObjFW  Check-in [348ac73b77]

Overview
Comment:Don't kill the old string in -[setToCString:] due to invalid encoding.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 348ac73b77f10abfc43b434b17e449106148659ab54edab3b1cdf3d2dac96473
User & Date: js on 2011-07-08 15:34:32
Other Links: manifest | tags
Context
2011-07-08
19:15
Rename ivars in OFString struct to prevent prospective name conflicts. check-in: 3ffa55524a user: js tags: trunk
15:34
Don't kill the old string in -[setToCString:] due to invalid encoding. check-in: 348ac73b77 user: js tags: trunk
15:29
Make it possible to add more ivars to OFConstantString. check-in: 0b846bcc4a user: js tags: trunk
Changes

Modified src/OFMutableString.m from [17605d93c9] to [7a74906b05].

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
	[self freeMemory: s->string];
	s->string = newString;
	s->length = newLength;
}

- (void)setToCString: (const char*)string
{
	size_t length;

	[self freeMemory: s->string];

	length = strlen(string);

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

	switch (of_string_check_utf8(string, length)) {
	case 0:
		s->isUTF8 = NO;
		break;
	case 1:
		s->isUTF8 = YES;
		break;
	case -1:
		s->string = NULL;
		s->length = 0;
		s->isUTF8 = NO;

		@throw [OFInvalidEncodingException newWithClass: isa];
	}


	s->length = length;
	s->string = [self allocMemoryWithSize: length + 1];
	memcpy(s->string, string, length + 1);
}

- (void)appendCString: (const char*)string







<
<
<
<
|














|
<
<
|
<
|
>







131
132
133
134
135
136
137




138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153


154

155
156
157
158
159
160
161
162
163
	[self freeMemory: s->string];
	s->string = newString;
	s->length = newLength;
}

- (void)setToCString: (const char*)string
{




	size_t length = strlen(string);

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

	switch (of_string_check_utf8(string, length)) {
	case 0:
		s->isUTF8 = NO;
		break;
	case 1:
		s->isUTF8 = YES;
		break;
	case -1:
		@throw [OFInvalidEncodingException newWithClass: isa];


	}


	[self freeMemory: s->string];

	s->length = length;
	s->string = [self allocMemoryWithSize: length + 1];
	memcpy(s->string, string, length + 1);
}

- (void)appendCString: (const char*)string