Libecoli 0.11.6
Extensible COmmand LIne library
Loading...
Searching...
No Matches
strvec.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3 */
4
15
16#pragma once
17#include <stdio.h>
18
20struct ec_strvec;
21
28struct ec_strvec *ec_strvec(void);
29
39#define EC_STRVEC(args...) \
40 ({ \
41 const char *_arr[] = {args}; \
42 ec_strvec_from_array(_arr, EC_COUNT_OF(_arr)); \
43 })
44
57struct ec_strvec *ec_strvec_from_array(const char *const *strarr, size_t n);
58
74
80#define EC_STRVEC_ATTR_START "start"
82#define EC_STRVEC_ATTR_END "end"
83
98struct ec_strvec *
99ec_strvec_sh_lex_str(const char *str, ec_strvec_flag_t flags, char *unclosed_quote);
100
113int ec_strvec_set(struct ec_strvec *strvec, size_t idx, const char *s);
114
125int ec_strvec_add(struct ec_strvec *strvec, const char *s);
126
135int ec_strvec_del_last(struct ec_strvec *strvec);
136
147struct ec_strvec *ec_strvec_dup(const struct ec_strvec *strvec);
148
163struct ec_strvec *ec_strvec_ndup(const struct ec_strvec *strvec, size_t off, size_t len);
164
171void ec_strvec_free(struct ec_strvec *strvec);
172
181size_t ec_strvec_len(const struct ec_strvec *strvec);
182
194const char *ec_strvec_val(const struct ec_strvec *strvec, size_t idx);
195
207const struct ec_dict *ec_strvec_get_attrs(const struct ec_strvec *strvec, size_t idx);
208
222int ec_strvec_set_attrs(struct ec_strvec *strvec, size_t idx, struct ec_dict *attrs);
223
234int ec_strvec_cmp(const struct ec_strvec *strvec1, const struct ec_strvec *strvec2);
235
246void ec_strvec_sort(struct ec_strvec *strvec, int (*str_cmp)(const char *s1, const char *s2));
247
256void ec_strvec_dump(FILE *out, const struct ec_strvec *strvec);
257
struct ec_dict * ec_dict(void)
Create a hash table.
int ec_strvec_set(struct ec_strvec *strvec, size_t idx, const char *s)
Set a string in the vector at specified index.
int ec_strvec_cmp(const struct ec_strvec *strvec1, const struct ec_strvec *strvec2)
Compare two string vectors.
struct ec_strvec * ec_strvec_from_array(const char *const *strarr, size_t n)
Allocate a new string vector.
struct ec_strvec * ec_strvec_sh_lex_str(const char *str, ec_strvec_flag_t flags, char *unclosed_quote)
Split a string into multiple tokens following basic shell lexing rules.
struct ec_strvec * ec_strvec_ndup(const struct ec_strvec *strvec, size_t off, size_t len)
Duplicate a part of a string vector.
void ec_strvec_free(struct ec_strvec *strvec)
Free a string vector.
int ec_strvec_set_attrs(struct ec_strvec *strvec, size_t idx, struct ec_dict *attrs)
Set the attributes of a vector element.
const char * ec_strvec_val(const struct ec_strvec *strvec, size_t idx)
Get a string element from a vector.
void ec_strvec_sort(struct ec_strvec *strvec, int(*str_cmp)(const char *s1, const char *s2))
Sort the string vector.
int ec_strvec_del_last(struct ec_strvec *strvec)
Delete the last entry in the string vector.
void ec_strvec_dump(FILE *out, const struct ec_strvec *strvec)
Dump a string vector.
ec_strvec_flag_t
Options for ec_strvec_sh_lex_str().
Definition strvec.h:62
struct ec_strvec * ec_strvec(void)
Allocate a new empty string vector.
int ec_strvec_add(struct ec_strvec *strvec, const char *s)
Add a string in a vector.
const struct ec_dict * ec_strvec_get_attrs(const struct ec_strvec *strvec, size_t idx)
Get the attributes of a vector element.
struct ec_strvec * ec_strvec_dup(const struct ec_strvec *strvec)
Duplicate a string vector.
size_t ec_strvec_len(const struct ec_strvec *strvec)
Get the length of a string vector.
@ EC_STRVEC_STRICT
Fail if a quote is not closed properly or if the provided string ends with an unterminated escape seq...
Definition strvec.h:67
@ EC_STRVEC_TRAILSP
If there is trailing white space, add an empty element to the output string vector.
Definition strvec.h:72