1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
11 * Character sequences.
16 #ifndef SQUIRRELJME_CHARSEQ_H
17 #define SQUIRRELJME_CHARSEQ_H
19 #include "sjme/frontEnd.h"
20 #include "sjme/stdTypes.h"
21 #include "sjme/error.h"
25 #ifndef SJME_CXX_IS_EXTERNED
26 #define SJME_CXX_IS_EXTERNED
27 #define SJME_CXX_SQUIRRELJME_CHARSEQ_H
29 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
30 #endif /* #ifdef __cplusplus */
32 /*--------------------------------------------------------------------------*/
35 * A character sequence which contains a set of characters within a string,
36 * may be modifiable or not.
40 typedef struct sjme_charSeq sjme_charSeq
;
43 * Returns the character at the given index.
45 * @param inSeq The input character sequence.
46 * @param inIndex The index to get from.
47 * @param outChar The resultant character.
48 * @return Any resultant error, if any.
51 typedef sjme_errorCode (*sjme_charSeq_charAtFunc
)(
52 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
53 sjme_attrInPositive sjme_jint inIndex
,
54 sjme_attrOutNotNull sjme_jchar
* outChar
);
57 * Deletes the given static character sequence.
59 * @param inSeq The input/output sequence.
60 * @return Any resultant error, if any.
63 typedef sjme_errorCode (*sjme_charSeq_deleteFunc
)(
64 sjme_attrInNotNull sjme_charSeq
* inSeq
);
67 * Returns the length of the character sequence.
69 * @param inSeq The input character sequence.
70 * @param outLen The sequence length.
71 * @return Any resultant error, if any.
74 typedef sjme_errorCode (*sjme_charSeq_lengthFunc
)(
75 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
76 sjme_attrOutNotNull sjme_jint
* outLen
);
79 * Functions which are used to process character sequences.
83 typedef struct sjme_charSeq_functions
85 /** The character at the given index. */
86 sjme_charSeq_charAtFunc charAt
;
88 /** Deleting the sequence and freeing any resources. */
89 sjme_charSeq_deleteFunc
delete;
91 /** The length of the character sequence. */
92 sjme_charSeq_lengthFunc length
;
93 } sjme_charSeq_functions
;
97 /** Front end data, if any. */
98 sjme_frontEnd frontEnd
;
100 /** Context pointer, if any. */
101 sjme_pointer context
;
103 /** The API for accessing the character sequence. */
104 const sjme_charSeq_functions
* impl
;
108 * Returns the character at the given index.
110 * @param inSeq The input character sequence.
111 * @param inIndex The index to get from.
112 * @param outChar The resultant character.
113 * @return Any resultant error, if any.
116 sjme_errorCode
sjme_charSeq_charAt(
117 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
118 sjme_attrInPositive sjme_jint inIndex
,
119 sjme_attrOutNotNull sjme_jchar
* outChar
);
122 * Deletes the given static character sequence.
124 * @param inOutSeq The input/output sequence.
125 * @return Any resultant error, if any.
128 sjme_errorCode
sjme_charSeq_deleteStatic(
129 sjme_attrInNotNull sjme_charSeq
* inOutSeq
);
132 * Returns the length of the character sequence.
134 * @param inSeq The input character sequence.
135 * @param outLen The sequence length.
136 * @return Any resultant error, if any.
139 sjme_errorCode
sjme_charSeq_length(
140 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
141 sjme_attrOutNotNull sjme_jint
* outLen
);
144 * Checks if the given character sequence equals the given character sequence.
146 * @param inSeq The sequence to check.
147 * @param outResult The result of the check.
148 * @param equalsSeq The char sequence to check for equality against.
149 * @return Any resultant error, if any.
152 sjme_errorCode
sjme_charSeq_equalsCharSeq(
153 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
154 sjme_attrOutNotNull sjme_jboolean
* outResult
,
155 sjme_attrInNotNull
const sjme_charSeq
* equalsSeq
);
158 * Checks if the given character sequence equals the given UTF string.
160 * @param inSeq The sequence to check.
161 * @param outResult The result of the check.
162 * @param equalsUtf The UTF sequence to check for equality against.
163 * @return Any resultant error, if any.
166 sjme_errorCode
sjme_charSeq_equalsUtf(
167 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
168 sjme_attrOutNotNull sjme_jboolean
* outResult
,
169 sjme_attrInNotNull sjme_lpcstr equalsUtf
);
172 * Checks if the given character sequence equals the given UTF string.
174 * @param inSeq The sequence to check.
175 * @param equalsUtf The UTF sequence to check for equality against.
176 * @return Returns whether it matches, note that if there is an error
177 * then @c SJME_JNI_FALSE will be returned and the error will be hidden.
180 sjme_jboolean
sjme_charSeq_equalsUtfR(
181 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
182 sjme_attrInNotNull sjme_lpcstr equalsUtf
);
185 * Initializes the given static character sequence.
187 * @param inOutSeq The input/output sequence.
188 * @param inFunctions The input functions for the character sequence.
189 * @param inOptContext The context to set.
190 * @param inOptFrontEnd The front end data to copy.
191 * @return Any resultant error, if any.
194 sjme_errorCode
sjme_charSeq_newStatic(
195 sjme_attrInNotNull sjme_charSeq
* inOutSeq
,
196 sjme_attrInNotNull
const sjme_charSeq_functions
* inFunctions
,
197 sjme_attrInNullable sjme_pointer inOptContext
,
198 sjme_attrInNullable sjme_frontEnd
* inOptFrontEnd
);
201 * Creates a character sequence that accesses the given standard C string
204 * @param inOutSeq The resultant sequence.
205 * @param inString The string to wrap.
206 * @return Any resultant error, if any.
209 sjme_errorCode
sjme_charSeq_newUtfStatic(
210 sjme_attrInNotNull sjme_charSeq
* inOutSeq
,
211 sjme_attrInNotNull sjme_lpcstr inString
);
214 * Checks if the given character sequence starts with the given character
217 * @param inSeq The sequence to check.
218 * @param outResult The result of the check.
219 * @param startsWithSeq The char sequence to check the start for.
220 * @return Any resultant error, if any.
223 sjme_errorCode
sjme_charSeq_startsWithCharSeq(
224 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
225 sjme_attrOutNotNull sjme_jboolean
* outResult
,
226 sjme_attrInNotNull
const sjme_charSeq
* startsWithSeq
);
229 * Checks if the given character sequence starts with the given UTF string.
231 * @param inSeq The sequence to check.
232 * @param outResult The result of the check.
233 * @param startsWithSeq The UTF sequence to check the start for.
234 * @return Any resultant error, if any.
237 sjme_errorCode
sjme_charSeq_startsWithUtf(
238 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
239 sjme_attrOutNotNull sjme_jboolean
* outResult
,
240 sjme_attrInNotNull sjme_lpcstr startsWithUtf
);
243 * Checks if the given character sequence starts with the given UTF string.
245 * @param inSeq The sequence to check.
246 * @param startsWithUtf The UTF sequence to check the start for.
247 * @return Returns whether it matches, note that if there is an error
248 * then @c SJME_JNI_FALSE will be returned and the error will be hidden.
251 sjme_jboolean
sjme_charSeq_startsWithUtfR(
252 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
253 sjme_attrInNotNull sjme_lpcstr startsWithUtf
);
255 /*--------------------------------------------------------------------------*/
259 #ifdef SJME_CXX_SQUIRRELJME_CHARSEQ_H
261 #undef SJME_CXX_SQUIRRELJME_CHARSEQ_H
262 #undef SJME_CXX_IS_EXTERNED
263 #endif /* #ifdef SJME_CXX_SQUIRRELJME_CHARSEQ_H */
264 #endif /* #ifdef __cplusplus */
266 #endif /* SQUIRRELJME_CHARSEQ_H */