libdom
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1/*
2 * This file is part of libdom.
3 * Licensed under the MIT License,
4 * http://www.opensource.org/licenses/mit-license.php
5 * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
6 */
7
8#ifndef dom_string_h_
9#define dom_string_h_
10
11#include <inttypes.h>
12#include <stddef.h>
13#include <libwapcaplet/libwapcaplet.h>
14
15#include <dom/functypes.h>
16#include <dom/core/exceptions.h>
17
18typedef struct dom_string dom_string;
19struct dom_string {
20 uint32_t refcnt;
21};
22
23
24/* Claim a reference on a DOM string */
25static inline dom_string *dom_string_ref(dom_string *str)
26{
27 if (str != NULL)
28 str->refcnt++;
29 return str;
30}
31
32/* Destroy a DOM string */
34
35/* Release a reference on a DOM string */
36static inline void dom_string_unref(dom_string *str)
37{
38 if ((str != NULL) && (--(str->refcnt) == 0)) {
40 }
41}
42
43/* Create a DOM string from a string of characters */
44dom_exception dom_string_create(const uint8_t *ptr, size_t len,
45 dom_string **str);
46dom_exception dom_string_create_interned(const uint8_t *ptr, size_t len,
47 dom_string **str);
48
49/* Obtain an interned representation of a dom string */
51 struct lwc_string_s **lwcstr);
52
53/* Case sensitively compare two DOM strings */
54bool dom_string_isequal(const dom_string *s1, const dom_string *s2);
55/* Case insensitively compare two DOM strings */
56bool dom_string_caseless_isequal(const dom_string *s1, const dom_string *s2);
57
58/* Case sensitively compare DOM string and lwc_string */
59bool dom_string_lwc_isequal(const dom_string *s1, lwc_string *s2);
60/* Case insensitively compare DOM string and lwc_string */
61bool dom_string_caseless_lwc_isequal(const dom_string *s1, lwc_string *s2);
62
63/* Get the index of the first occurrence of a character in a dom string */
64uint32_t dom_string_index(dom_string *str, uint32_t chr);
65/* Get the index of the last occurrence of a character in a dom string */
66uint32_t dom_string_rindex(dom_string *str, uint32_t chr);
67
68/* Get the length, in characters, of a dom string */
69uint32_t dom_string_length(dom_string *str);
70
76const char *dom_string_data(const dom_string *str);
77
78/* Get the byte length of this dom_string */
79size_t dom_string_byte_length(const dom_string *str);
80
81/* Get the UCS-4 character at position index, the index should be in
82 * [0, length), and length can be get by calling dom_string_length
83 */
84dom_exception dom_string_at(dom_string *str, uint32_t index,
85 uint32_t *ch);
86
87/* Concatenate two dom strings */
89 dom_string **result);
90
91/* Extract a substring from a dom string */
93 uint32_t i1, uint32_t i2, dom_string **result);
94
95/* Insert data into a dom string at the given location */
97 dom_string *source, uint32_t offset,
98 dom_string **result);
99
100/* Replace a section of a dom string */
102 dom_string *source, uint32_t i1, uint32_t i2,
103 dom_string **result);
104
105/* Generate an uppercase version of the given string */
106dom_exception dom_string_toupper(dom_string *source, bool ascii_only,
107 dom_string **upper);
108
109/* Generate an lowercase version of the given string */
110dom_exception dom_string_tolower(dom_string *source, bool ascii_only,
111 dom_string **lower);
112
113/* Calculate a hash value from a dom string */
114uint32_t dom_string_hash(dom_string *str);
115
116#endif
dom_exception
Definition exceptions.h:24
const char * dom_string_data(const dom_string *str)
Definition string.c:898
dom_exception dom_string_create(const uint8_t *ptr, size_t len, dom_string **str)
Definition string.c:91
dom_exception dom_string_create_interned(const uint8_t *ptr, size_t len, dom_string **str)
Definition string.c:139
bool dom_string_caseless_lwc_isequal(const dom_string *s1, lwc_string *s2)
Definition string.c:346
bool dom_string_isequal(const dom_string *s1, const dom_string *s2)
Definition string.c:209
bool dom_string_caseless_isequal(const dom_string *s1, const dom_string *s2)
Definition string.c:256
uint32_t dom_string_hash(dom_string *str)
Definition string.c:852
dom_exception dom_string_concat(dom_string *s1, dom_string *s2, dom_string **result)
Definition string.c:546
dom_exception dom_string_tolower(dom_string *source, bool ascii_only, dom_string **lower)
Definition string.c:979
void dom_string_destroy(dom_string *str)
Definition string.c:57
uint32_t dom_string_length(dom_string *str)
Definition string.c:471
size_t dom_string_byte_length(const dom_string *str)
Definition string.c:912
uint32_t dom_string_rindex(dom_string *str, uint32_t chr)
Definition string.c:430
dom_exception dom_string_toupper(dom_string *source, bool ascii_only, dom_string **upper)
Definition string.c:933
dom_exception dom_string_substr(dom_string *str, uint32_t i1, uint32_t i2, dom_string **result)
Definition string.c:602
dom_exception dom_string_insert(dom_string *target, dom_string *source, uint32_t offset, dom_string **result)
Definition string.c:663
dom_exception dom_string_at(dom_string *str, uint32_t index, uint32_t *ch)
Definition string.c:495
dom_exception dom_string_intern(dom_string *str, struct lwc_string_s **lwcstr)
Definition string.c:175
uint32_t dom_string_index(dom_string *str, uint32_t chr)
Definition string.c:393
dom_exception dom_string_replace(dom_string *target, dom_string *source, uint32_t i1, uint32_t i2, dom_string **result)
Definition string.c:756
bool dom_string_lwc_isequal(const dom_string *s1, lwc_string *s2)
Definition string.c:311
Definition string.h:19
uint32_t refcnt
Definition string.h:20