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
23 #ifndef SJME_CXX_IS_EXTERNED
24 #define SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_SQUIRRELJME_CHARSEQ_H
27 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
28 #endif /* #ifdef __cplusplus */
30 /*--------------------------------------------------------------------------*/
33 * A character sequence which contains a set of characters within a string,
34 * may be modifiable or not.
38 typedef struct sjme_charSeq sjme_charSeq
;
41 * Returns the character at the given index.
43 * @param inSeq The input character sequence.
44 * @param inIndex The index to get from.
45 * @param outChar The resultant character.
46 * @return Any resultant error, if any.
49 typedef sjme_errorCode (*sjme_charSeq_charAtFunc
)(
50 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
51 sjme_attrInPositive sjme_jint inIndex
,
52 sjme_attrOutNotNull sjme_jchar
* outChar
);
55 * Deletes the given static character sequence.
57 * @param inSeq The input/output sequence.
58 * @return Any resultant error, if any.
61 typedef sjme_errorCode (*sjme_charSeq_deleteFunc
)(
62 sjme_attrInNotNull sjme_charSeq
* inSeq
);
65 * Returns the length of the character sequence.
67 * @param inSeq The input character sequence.
68 * @param outLen The sequence length.
69 * @return Any resultant error, if any.
72 typedef sjme_errorCode (*sjme_charSeq_lengthFunc
)(
73 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
74 sjme_attrOutNotNull sjme_jint
* outLen
);
77 * Functions which are used to process character sequences.
81 typedef struct sjme_charSeq_functions
83 /** The character at the given index. */
84 sjme_charSeq_charAtFunc charAt
;
86 /** Deleting the sequence and freeing any resources. */
87 sjme_charSeq_deleteFunc
delete;
89 /** The length of the character sequence. */
90 sjme_charSeq_lengthFunc length
;
91 } sjme_charSeq_functions
;
95 /** Front end data, if any. */
96 sjme_frontEnd frontEnd
;
98 /** Context pointer, if any. */
101 /** The API for accessing the character sequence. */
102 const sjme_charSeq_functions
* impl
;
106 * Returns the character at the given index.
108 * @param inSeq The input character sequence.
109 * @param inIndex The index to get from.
110 * @param outChar The resultant character.
111 * @return Any resultant error, if any.
114 sjme_errorCode
sjme_charSeq_charAt(
115 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
116 sjme_attrInPositive sjme_jint inIndex
,
117 sjme_attrOutNotNull sjme_jchar
* outChar
);
120 * Deletes the given static character sequence.
122 * @param inOutSeq The input/output sequence.
123 * @return Any resultant error, if any.
126 sjme_errorCode
sjme_charSeq_deleteStatic(
127 sjme_attrInNotNull sjme_charSeq
* inOutSeq
);
130 * Returns the length of the character sequence.
132 * @param inSeq The input character sequence.
133 * @param outLen The sequence length.
134 * @return Any resultant error, if any.
137 sjme_errorCode
sjme_charSeq_length(
138 sjme_attrInNotNull
const sjme_charSeq
* inSeq
,
139 sjme_attrOutNotNull sjme_jint
* outLen
);
142 * Initializes the given static character sequence.
144 * @param inOutSeq The input/output sequence.
145 * @param inFunctions The input functions for the character sequence.
146 * @param inOptContext The context to set.
147 * @param inOptFrontEnd The front end data to copy.
148 * @return Any resultant error, if any.
151 sjme_errorCode
sjme_charSeq_newStatic(
152 sjme_attrInNotNull sjme_charSeq
* inOutSeq
,
153 sjme_attrInNotNull
const sjme_charSeq_functions
* inFunctions
,
154 sjme_attrInNullable sjme_pointer inOptContext
,
155 sjme_attrInNullable sjme_frontEnd
* inOptFrontEnd
);
158 * Creates a character sequence that accesses the given standard C string
161 * @param inOutSeq The resultant sequence.
162 * @param inString The string to wrap.
163 * @return Any resultant error, if any.
166 sjme_errorCode
sjme_charSeq_newUtfStatic(
167 sjme_attrInNotNull sjme_charSeq
* inOutSeq
,
168 sjme_attrInNotNull sjme_lpcstr inString
);
170 /*--------------------------------------------------------------------------*/
174 #ifdef SJME_CXX_SQUIRRELJME_CHARSEQ_H
176 #undef SJME_CXX_SQUIRRELJME_CHARSEQ_H
177 #undef SJME_CXX_IS_EXTERNED
178 #endif /* #ifdef SJME_CXX_SQUIRRELJME_CHARSEQ_H */
179 #endif /* #ifdef __cplusplus */
181 #endif /* SQUIRRELJME_CHARSEQ_H */