CoreFW  Check-in [891f0add23]

Overview
Comment:Add cfw_string_append().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 891f0add2336272616bf35e7d5564217d16718acc72db294b179a723ddedb9b2
User & Date: js on 2012-04-08 19:19:56
Other Links: manifest | tags
Context
2012-04-08
19:21
cstr -> data. check-in: e036a533f1 user: js tags: trunk
19:19
Add cfw_string_append(). check-in: 891f0add23 user: js tags: trunk
19:16
Add -Wall. check-in: 5bb3f2db02 user: js tags: trunk
Changes

Modified src/cfwstring.c from [59f525dc2e] to [12e11ffa26].

124
125
126
127
128
129
130

















131
132
133
134
135
136
137

	if (str->cstr != NULL)
		free(str->cstr);

	str->cstr = copy;
	str->len = strlen(copy);


















	return true;
}

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







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







124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

	if (str->cstr != NULL)
		free(str->cstr);

	str->cstr = copy;
	str->len = strlen(copy);

	return true;
}

bool
cfw_string_append(CFWString *str, CFWString *append)
{
	char *new;

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

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

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

	return true;
}

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

Modified src/cfwstring.h from [3d3ffe349d] to [4630719e18].

30
31
32
33
34
35
36

37
38
#include "cfwclass.h"

typedef struct CFWString CFWString;
extern CFWClass *cfw_string;
extern const char* cfw_string_c(CFWString*);
extern size_t cfw_string_len(CFWString*);
extern bool cfw_string_set(CFWString*, const char*);


#endif







>


30
31
32
33
34
35
36
37
38
39
#include "cfwclass.h"

typedef struct CFWString CFWString;
extern CFWClass *cfw_string;
extern const char* cfw_string_c(CFWString*);
extern size_t cfw_string_len(CFWString*);
extern bool cfw_string_set(CFWString*, const char*);
extern bool cfw_string_append(CFWString*, CFWString*);

#endif

Modified tests/tests.c from [c532ff05d3] to [70b7e88f0b].

34
35
36
37
38
39
40
41
42
43
44
45






46




47


48
49
50
main()
{
	CFWString *s[3];
	CFWArray *a;
	size_t i;

	s[0] = cfw_new(cfw_string, "Hallo");
	s[1] = cfw_new(cfw_string, "Welt");
	s[2] = cfw_new(cfw_string, "!");

	a = cfw_new(cfw_array, s[0], s[1], s[2], NULL);







	for (i = 0; i < cfw_array_size(a); i++)




		puts(cfw_string_c(cfw_array_get(a, i)));



	return 0;
}







|




>
>
>
>
>
>

>
>
>
>
|
>
>



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
main()
{
	CFWString *s[3];
	CFWArray *a;
	size_t i;

	s[0] = cfw_new(cfw_string, "Hallo");
	s[1] = cfw_new(cfw_string, " Welt");
	s[2] = cfw_new(cfw_string, "!");

	a = cfw_new(cfw_array, s[0], s[1], s[2], NULL);

	cfw_unref(s[0]);
	cfw_unref(s[1]);
	cfw_unref(s[2]);

	s[0] = cfw_new(cfw_string, NULL);

	for (i = 0; i < cfw_array_size(a); i++)
		cfw_string_append(s[0], cfw_array_get(a, i));

	cfw_unref(a);

	puts(cfw_string_c(s[0]));

	cfw_unref(s[0]);

	return 0;
}