CoreFW  Diff

Differences From Artifact [6218da6faa]:

To Artifact [61c34032c7]:


164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178







-
+







	new->len = str->len;

	memcpy(new->data, str->data, str->len + 1);

	return new;
}

const char*
char*
cfw_string_c(CFWString *str)
{
	return str->data;
}

size_t
cfw_string_length(CFWString *string)
227
228
229
230
231
232
233


























































234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252























253
254
255
256
257
258
259
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	new[str->len + append->len] = 0;

	str->data = new;
	str->len += append->len;

	return true;
}

bool
cfw_string_append_c(CFWString *str, const char *append)
{
	size_t append_len = strlen(append);
	char *new;

	if ((new = realloc(str->data, str->len + append_len + 1)) == NULL)
		return false;

	memcpy(new + str->len, append, append_len);
	new[str->len + append_len] = 0;

	str->data = new;
	str->len += append_len;

	return true;
}

bool
cfw_string_has_prefix(CFWString *str, CFWString *prefix)
{
	if (prefix->len > str->len)
		return false;

	return !memcmp(str->data, prefix->data, prefix->len);
}

bool
cfw_string_has_prefix_c(CFWString *str, const char *prefix)
{
	size_t prefix_len = strlen(prefix);

	if (prefix_len > str->len)
		return false;

	return !memcmp(str->data, prefix, prefix_len);
}

bool
cfw_string_has_suffix(CFWString *str, CFWString *suffix)
{
	if (suffix->len > str->len)
		return false;

	return !memcmp(str->data, suffix->data, suffix->len);
}

bool
cfw_string_has_suffix_c(CFWString *str, const char *suffix)
{
	size_t suffix_len = strlen(suffix);

	if (suffix_len > str->len)
		return false;

	return !memcmp(str->data, suffix, suffix_len);
}

size_t
cfw_string_find(CFWString *str, CFWString *substr, cfw_range_t range)
{
	size_t i;

	if (range.start > str->len)
		return SIZE_MAX;

	if (range.length == SIZE_MAX)
		range.length = str->len - range.start;

	if (range.start + range.length > str->len || substr->len > range.length)
		return SIZE_MAX;

	for (i = range.start; i <= range.start + range.length - substr->len;
	    i++)
		if (!memcmp(str->data + i, substr->data, substr->len))
			return i;

	return SIZE_MAX;
}

size_t
cfw_string_find_c(CFWString *str, const char *substr, cfw_range_t range)
{
	size_t substr_len = strlen(substr);
	size_t i;

	if (range.start > str->len)
		return SIZE_MAX;

	if (range.length == SIZE_MAX)
		range.length = str->len - range.start;

	if (range.start + range.length > str->len || substr_len > range.length)
		return SIZE_MAX;

	for (i = range.start; i <= range.start + range.length - substr_len;
	    i++)
		if (!memcmp(str->data + i, substr, substr_len))
			return i;

	return SIZE_MAX;
}

static CFWClass class = {
	.name = "CFWString",
	.size = sizeof(CFWString),