Version 8.2.1.
[libpwmd.git] / src / util-string.h
blob89cada2f42d5b1b19cbd9f331f02ba461e14bc88
1 /*
2 Copyright (C) 2012-2018 Ben Kibbey <bjk@luxsci.net>
4 This file is part of pwmd.
6 Pwmd is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 Pwmd is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef UTIL_STRING_H
20 #define UTIL_STRING_H
22 #include <stdarg.h>
24 #ifdef HAVE_SYS_TYPES_H
25 #include <sys/types.h>
26 #endif
28 struct string_s
30 size_t allocated;
31 size_t len;
32 char *str;
35 // These mimic GLib's string utility functions.
36 void string_free (struct string_s *s, int with_data);
37 struct string_s *string_erase (struct string_s *s, ssize_t pos, ssize_t len);
38 struct string_s *string_new (const char *str);
39 struct string_s *string_new_content (char *str);
40 struct string_s *string_append (struct string_s *s, const char *str);
41 struct string_s *string_truncate (struct string_s *s, size_t n);
42 struct string_s *string_prepend (struct string_s *s, const char *str);
43 struct string_s *string_append_printf (struct string_s *s, const char *fmt,
44 ...);
45 struct string_s *string_insert_c (struct string_s *s, ssize_t pos, char c);
47 int strv_printf (char ***array, const char *fmt, ...);
48 void strv_free (char **str);
49 char **strv_cat (char **a, char *str);
50 char **strv_catv (char **dst, char **src);
51 int strv_length (char **a);
52 char **strv_dup (char **src);
53 char *strv_join (char *delim, char **a);
55 char **str_split (const char *str, const char *delim, int count);
56 char **str_split_ws (const char *str, const char *delim, int count);
57 char *str_down (char *str);
58 char *str_chomp (char *str);
59 char *str_dup (const char *);
60 char *str_asprintf (const char *fmt, ...);
61 int str_vasprintf (char **result, const char *fmt, va_list ap);
63 #endif