CoreFW  Check-in [8f1f410978]

Overview
Comment:Add cfw_string_find().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8f1f410978f5cd1e78d669c5e38a0b861f16fe2f483353ac8b72394b8b2871bc
User & Date: js on 2012-04-08 21:10:39
Other Links: manifest | tags
Context
2012-04-09
14:06
Add hashing. check-in: a2613e09be user: js tags: trunk
2012-04-08
21:10
Add cfw_string_find(). check-in: 8f1f410978 user: js tags: trunk
21:08
Don't always build a static lib. check-in: 83b94fbdaf user: js tags: trunk
Changes

Modified src/string.c from [99bade167a] to [33cb49edea].

21
22
23
24
25
26
27

28
29
30
31
32
33
34
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>

#include <string.h>

#include "object.h"
#include "string.h"

struct CFWString {
	CFWObject obj;







>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#include "object.h"
#include "string.h"

struct CFWString {
	CFWObject obj;
143
144
145
146
147
148
149






















150
151
152
153
154
155
156
157
158
159
	new[str->len + append->len] = 0;

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

	return true;
}























static CFWClass class = {
	.name = "CFWString",
	.size = sizeof(CFWString),
	.ctor = ctor,
	.dtor = dtor,
	.equal = equal,
	.copy = copy
};
CFWClass *cfw_string = &class;







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










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
170
171
172
173
174
175
176
177
178
179
180
181
182
	new[str->len + append->len] = 0;

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

	return true;
}

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;
}

static CFWClass class = {
	.name = "CFWString",
	.size = sizeof(CFWString),
	.ctor = ctor,
	.dtor = dtor,
	.equal = equal,
	.copy = copy
};
CFWClass *cfw_string = &class;

Modified src/string.h from [1b82e73c57] to [2d77f73a91].

24
25
26
27
28
29
30

31
32
33
34
35
36
37

38
39
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __COREFW_STRING_H__
#define __COREFW_STRING_H__

#include "class.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







>







>


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __COREFW_STRING_H__
#define __COREFW_STRING_H__

#include "class.h"
#include "range.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*);
extern size_t cfw_string_find(CFWString*, CFWString*, cfw_range_t);

#endif

Modified tests/tests.c from [33cbcd9d9d] to [fede98c922].

51
52
53
54
55
56
57




58
59
60
61
62

	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;
}







>
>
>
>





51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

	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]));

	s[1] = cfw_new(cfw_string, "ll");
	printf("%zd\n", cfw_string_find(s[0], s[1], cfw_range_all));
	cfw_unref(s[1]);

	cfw_unref(s[0]);

	return 0;
}