summaryrefslogtreecommitdiff
path: root/include/dom/core/string.h
blob: 37d78d6f83f7b0bffcc7b5aa39d5982320f7fe05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
63
64
65
66
/*
 * This file is part of libdom.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
 */

#ifndef dom_string_h_
#define dom_string_h_

#include <inttypes.h>
#include <stddef.h>

#include <dom/functypes.h>
#include <dom/core/exceptions.h>

typedef struct dom_string dom_string;

/* Claim a reference on a DOM string */
void dom_string_ref(struct dom_string *str);
/* Release a reference on a DOM string */
void dom_string_unref(struct dom_string *str);

/* Create a DOM string from a string of characters */
dom_exception dom_string_create(dom_alloc alloc, void *pw,
		const uint8_t *ptr, size_t len, struct dom_string **str);

/* Case sensitively compare two DOM strings */
int dom_string_cmp(struct dom_string *s1, struct dom_string *s2);
/* Case insensitively compare two DOM strings */
int dom_string_icmp(struct dom_string *s1, struct dom_string *s2);

/* Get the index of the first occurrence of a character in a dom string */
uint32_t dom_string_index(struct dom_string *str, uint32_t chr);
/* Get the index of the last occurrence of a character in a dom string */
uint32_t dom_string_rindex(struct dom_string *str, uint32_t chr);

/* Get the length, in characters, of a dom string */
uint32_t dom_string_length(struct dom_string *str);

/* Concatenate two dom strings */
dom_exception dom_string_concat(struct dom_string *s1, struct dom_string *s2,
		struct dom_string **result);

/* Extract a substring from a dom string */
dom_exception dom_string_substr(struct dom_string *str, 
		uint32_t i1, uint32_t i2, struct dom_string **result);

/* Insert data into a dom string at the given location */
dom_exception dom_string_insert(struct dom_string *target,
		struct dom_string *source, uint32_t offset,
		struct dom_string **result);

/* Replace a section of a dom string */
dom_exception dom_string_replace(struct dom_string *target,
		struct dom_string *source, uint32_t i1, uint32_t i2,
		struct dom_string **result);

/* Duplicate a dom string */
dom_exception dom_string_dup(struct dom_string *str, 
		struct dom_string **result);

/* Calculate a hash value from a dom string */
uint32_t dom_string_hash(struct dom_string *str);

#endif