Data Accelerator Offload
Loading...
Searching...
No Matches
dao_dynamic_string.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: Marvell-MIT
2 * Copyright (c) 2023 Marvell.
3 */
4
5#ifndef _DAO_DYNAMIC_STRING_H_
6#define _DAO_DYNAMIC_STRING_H_
7
8#include <stdarg.h>
9#include <stdbool.h>
10#include <stddef.h>
11#include <stdint.h>
12#include <stdio.h>
13#include <assert.h>
14
15#include <rte_config.h>
16#include <rte_common.h>
17#include <rte_compat.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
41struct dao_ds {
42 char *string; /*< Null-terminated string. */
43 size_t length; /*< Bytes used, not including null terminator. */
44 size_t allocated; /*< Bytes allocated, not including null terminator. */
45};
46
47#define DS_EMPTY_INITIALIZER { NULL, 0, 0 }
48
55void dao_ds_init(struct dao_ds *ds);
56
64void dao_ds_clear(struct dao_ds *ds);
65
76void dao_ds_truncate(struct dao_ds *ds, size_t new_length);
77
88void dao_ds_reserve(struct dao_ds *ds, size_t min_length);
89
103char *dao_ds_put_uninit(struct dao_ds *ds, size_t n);
104
113void dao_ds_put_utf8(struct dao_ds *ds, int uc);
114
125void dao_ds_put_char_multiple(struct dao_ds *ds, char c, size_t n);
126
137void dao_ds_put_buffer(struct dao_ds *ds, const char *buf, size_t n);
138
147void dao_ds_put_cstr(struct dao_ds *ds, const char *str);
148
157void dao_ds_put_and_free_cstr(struct dao_ds *ds, char *str);
158
168void dao_ds_put_format(struct dao_ds *ds, const char *format, ...);
169
180void dao_ds_put_format_valist(struct dao_ds *ds, const char *format, va_list va);
181
194void dao_ds_put_printable(struct dao_ds *ds, const char *buf, size_t size);
195
207void dao_ds_put_hex(struct dao_ds *ds, const void *buf, size_t size);
208
226void dao_ds_put_hex_dump(struct dao_ds *ds, const void *buf, size_t size,
227 uintptr_t ofs, bool ascii);
228
244void dao_ds_put_sparse_hex_dump(struct dao_ds *ds, const void *buf, size_t size,
245 uintptr_t ofs, bool ascii);
258int dao_ds_get_line(struct dao_ds *ds, FILE *file);
259
279int dao_ds_get_preprocessed_line(struct dao_ds *ds, FILE *file, int *line_numberp);
280
308int dao_ds_get_test_line(struct dao_ds *ds, FILE *file);
309
321char *dao_ds_cstr(struct dao_ds *ds);
322
334char *dao_ds_steal_cstr(struct dao_ds *ds);
335
342void dao_ds_destroy(struct dao_ds *ds);
343
352void dao_ds_swap(struct dao_ds *a, struct dao_ds *b);
353
364int dao_ds_last(const struct dao_ds *ds);
365
380bool dao_ds_chomp(struct dao_ds *ds, int c);
381
390void dao_ds_clone(struct dao_ds *dst, struct dao_ds *source);
391
392void dao_ds_put_char__(struct dao_ds *ds, char c);
393
394/* Inline functions. */
403static inline void
404dao_ds_put_char(struct dao_ds *ds, char c)
405{
406 if (ds->length < ds->allocated) {
407 ds->string[ds->length++] = c;
408 ds->string[ds->length] = '\0';
409 } else {
410 dao_ds_put_char__(ds, c);
411 }
412}
413
414#ifdef __cplusplus
415}
416#endif
417
418#endif /* dao_dynamic_string.h */
int dao_ds_get_test_line(struct dao_ds *ds, FILE *file)
void dao_ds_put_char_multiple(struct dao_ds *ds, char c, size_t n)
void dao_ds_put_format(struct dao_ds *ds, const char *format,...)
void dao_ds_put_cstr(struct dao_ds *ds, const char *str)
void dao_ds_truncate(struct dao_ds *ds, size_t new_length)
int dao_ds_get_preprocessed_line(struct dao_ds *ds, FILE *file, int *line_numberp)
char * dao_ds_put_uninit(struct dao_ds *ds, size_t n)
void dao_ds_clone(struct dao_ds *dst, struct dao_ds *source)
void dao_ds_put_hex_dump(struct dao_ds *ds, const void *buf, size_t size, uintptr_t ofs, bool ascii)
void dao_ds_put_buffer(struct dao_ds *ds, const char *buf, size_t n)
char * dao_ds_cstr(struct dao_ds *ds)
void dao_ds_put_sparse_hex_dump(struct dao_ds *ds, const void *buf, size_t size, uintptr_t ofs, bool ascii)
static void dao_ds_put_char(struct dao_ds *ds, char c)
void dao_ds_put_utf8(struct dao_ds *ds, int uc)
void dao_ds_put_printable(struct dao_ds *ds, const char *buf, size_t size)
void dao_ds_swap(struct dao_ds *a, struct dao_ds *b)
bool dao_ds_chomp(struct dao_ds *ds, int c)
void dao_ds_destroy(struct dao_ds *ds)
void dao_ds_clear(struct dao_ds *ds)
void dao_ds_reserve(struct dao_ds *ds, size_t min_length)
char * dao_ds_steal_cstr(struct dao_ds *ds)
void dao_ds_init(struct dao_ds *ds)
void dao_ds_put_format_valist(struct dao_ds *ds, const char *format, va_list va)
void dao_ds_put_and_free_cstr(struct dao_ds *ds, char *str)
int dao_ds_last(const struct dao_ds *ds)
void dao_ds_put_hex(struct dao_ds *ds, const void *buf, size_t size)
int dao_ds_get_line(struct dao_ds *ds, FILE *file)