Repository navigation
Expand file tree
/
Copy pathstring_builder.h
More file actions
146 lines (130 loc) · 4.44 KB
/
Copy pathstring_builder.h
File metadata and controls
146 lines (130 loc) · 4.44 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Licensed under the MIT License.
#include <stdbool.h>
#include <stddef.h>
#include "euler.h"
#include "object.h"
/** Represents a mutable string of characters. */
struct StringBuilder
{
char* buffer;
size_t length;
size_t capacity;
};
/** Represents a mutable string of characters. */
typedef struct StringBuilder* StringBuilder;
/**
* Initializes an `StringBuilder` instance.
*
* @param instance the `StringBuilder` instance.
* @param capacity the required minimum capacity.
* @return `EXCEPTION_OUT_OF_MEMORY` if there is not enough memory to complete
* the operation; otherwise `0`.
*/
Exception string_builder(StringBuilder instance, size_t capacity);
/**
* Initializes a static `StringBuilder` instance using the specified string. Do
* not call `finalize_string_builder`.
*
* @param instance the `StringBuilder` instance.
* @param value the backing string for the builder. The caller is responsible
* for this argument.
*/
void string_builder_from_string(StringBuilder instance, String value);
/**
* Initializes a new `StringBuilder` instance that contains characters copied
* from the specified instance, and has sufficient capacity to accommodate the
* number of characters copied.
*
* @param result the new `StringBuilder` instance.
* @param instance the existing `StringBuilder` instance.
* @return `EXCEPTION_OUT_OF_MEMORY` if there is not enough memory to complete
* the operation; otherwise `0`.
*/
Exception string_builder_copy(StringBuilder result, StringBuilder instance);
/**
* Ensures that the capacity of this instance of `StringBuilder` is at least the
* specified value.
*
* @param instance the `StringBuilder` instance.
* @param value the required minimum capacity.
* @return `EXCEPTION_OUT_OF_MEMORY` if there is not enough memory to complete
* the operation; otherwise `0`.
*/
Exception string_builder_ensure_capacity(
StringBuilder instance,
size_t capacity);
/**
* Appends a specified char to this instance.
*
* @param instance the `StringBuilder` instance.
* @param value the char to append.
* @return An exception; otherwise, `0`.
*/
Exception string_builder_append_char(StringBuilder instance, char value);
/**
* Appends a copy of the specified string to this instance.
*
* @param instance the `StringBuilder` instance.
* @param value the string to append.
* @return An exception; otherwise `0`.
*/
Exception string_builder_append_string(StringBuilder instance, String value);
/**
* Appends the string returned by processing a composite format string, which
* contains zero or more format items, to this instance. Each format item is
* replaced by the string representation of a corresponding object argument.
*
* @param instance the `StringBuilder` instance.
* @param format a composite format string, followed by a variable number of
* template arguments.
* @return An exception; otherwise, `0`.
*/
Exception string_builder_append_format(
StringBuilder instance,
String format,
...);
/**
* Removes all the trailing white-space characters from the current string
* builder.
*
* @param instance the `StringBuilder` instance.
*/
void string_builder_trim_right(StringBuilder instance);
/**
* Removes all characters from this instance.
*
* @param instance the `StringBuilder` instance.
*/
void string_builder_clear(StringBuilder instance);
/**
* Converts the value of an `StringBuilder` to a new `String`.
*
* @param instance the `StringBuilder` instance.
* @return A new string whose value is the same as this instance. The caller is
* responsible.
*/
String string_builder_to_string(StringBuilder instance);
/**
* Returns the hash code for this string builder.
*
* @param item the string builder instance.
* @param size the size of a string builder reference.
* @return An integer hash code.
*/
size_t string_builder_hash(Object item, size_t size);
/**
* Determines whether two `StringBuilders` represent the same string value.
*
* @param left a string builder to compare to `right`.
* @param right a string builder to compare to `left`.
* @return `true` if the two string builders represent the same string values;
* otherwise, `false`.
*/
bool string_builder_equals(Object left, Object right);
/**
* Frees all resources.
*
* @param instance the `StringBuilder` instance. This method corrupts the
* `instance` argument.
*/
void finalize_string_builder(StringBuilder instance);