| 1187 * @param token a pointer to memory where the next token shall be stored |
1187 * @param token a pointer to memory where the next token shall be stored |
| 1188 * @return true if successful, false if the limit or the end of the string |
1188 * @return true if successful, false if the limit or the end of the string |
| 1189 * has been reached |
1189 * has been reached |
| 1190 */ |
1190 */ |
| 1191 cx_attr_nonnull cx_attr_nodiscard cx_attr_access_w(2) |
1191 cx_attr_nonnull cx_attr_nodiscard cx_attr_access_w(2) |
| 1192 CX_EXPORT bool cx_strtok_next(CxStrtokCtx *ctx, cxstring *token); |
1192 CX_EXPORT bool cx_strtok_next_(CxStrtokCtx *ctx, cxstring *token); |
| 1193 |
1193 |
| 1194 /** |
1194 #ifdef __cplusplus |
| 1195 * Returns the next token of a mutable string. |
1195 } // extern "C" |
| |
1196 CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxstring *token) { |
| |
1197 return cx_strtok_next_(ctx, token); |
| |
1198 } |
| |
1199 CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxmutstr *token) { |
| |
1200 // Note: this is actually UB - fixed with start_lifetime_as() in C++23 |
| |
1201 // but it works on all supported platforms |
| |
1202 return cx_strtok_next_(ctx, reinterpret_cast<cxstring*>(token)); |
| |
1203 } |
| |
1204 extern "C" { |
| |
1205 #else // ! __cplusplus |
| |
1206 /** |
| |
1207 * Returns the next token. |
| 1196 * |
1208 * |
| 1197 * The token will point to the source string. |
1209 * The token will point to the source string. |
| 1198 * |
1210 * |
| 1199 * @attention |
1211 * @param ctx (@c CxStrtokCtx*) the tokenization context |
| 1200 * If the context was not initialized over a mutable string, modifying |
1212 * @param token a pointer to either a @c cxstring or @c cxmutstr |
| 1201 * the data of the returned token is undefined behavior. |
1213 * where the next token shall be stored |
| 1202 * |
|
| 1203 * @param ctx the tokenization context |
|
| 1204 * @param token a pointer to memory where the next token shall be stored |
|
| 1205 * @return true if successful, false if the limit or the end of the string |
1214 * @return true if successful, false if the limit or the end of the string |
| 1206 * has been reached |
1215 * has been reached |
| 1207 */ |
1216 */ |
| 1208 cx_attr_nonnull cx_attr_nodiscard cx_attr_access_w(2) |
1217 #define cx_strtok_next(ctx, token) _Generic((token), \ |
| 1209 CX_EXPORT bool cx_strtok_next_m(CxStrtokCtx *ctx, cxmutstr *token); |
1218 cxstring*: cx_strtok_next_, \ |
| |
1219 cxmutstr*: cx_strtok_next_)(ctx, (cxstring*)token) |
| |
1220 #endif |
| 1210 |
1221 |
| 1211 /** |
1222 /** |
| 1212 * Defines an array of more delimiters for the specified tokenization context. |
1223 * Defines an array of more delimiters for the specified tokenization context. |
| 1213 * |
1224 * |
| 1214 * @param ctx the tokenization context |
1225 * @param ctx the tokenization context |