dpkg 1.21.11
string.h
Go to the documentation of this file.
1/*
2 * libdpkg - Debian packaging suite library routines
3 * string.h - string handling routines
4 *
5 * Copyright © 2008-2015 Guillem Jover <guillem@debian.org>
6 *
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef LIBDPKG_STRING_H
22#define LIBDPKG_STRING_H
23
24#include <stddef.h>
25#include <stdbool.h>
26
27#include <dpkg/macros.h>
28
30
40static inline bool
41str_is_unset(const char *str)
42{
43 return str == DPKG_NULL || str[0] == '\0';
44}
45
49static inline bool
50str_is_set(const char *str)
51{
52 return str != DPKG_NULL && str[0] != '\0';
53}
54
55bool str_match_end(const char *str, const char *end);
56
57unsigned int str_fnv_hash(const char *str);
58
59char *str_concat(char *dst, ...) DPKG_ATTR_SENTINEL;
60char *str_fmt(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
61char *str_escape_fmt(char *dest, const char *src, size_t n);
62char *str_quote_meta(const char *src);
63char *str_strip_quotes(char *str);
64char *str_rtrim_spaces(const char *str, char *str_end);
65
69};
70
71int str_width(const char *str);
72void str_gen_crop(const char *str, int max_width, struct str_crop_info *crop);
73
77
78#endif /* LIBDPKG_STRING_H */
#define DPKG_BEGIN_DECLS
Definition: macros.h:86
#define DPKG_NULL
A null pointer constant that works on C or C++.
Definition: macros.h:102
#define DPKG_ATTR_PRINTF(n)
Definition: macros.h:56
#define DPKG_END_DECLS
Definition: macros.h:87
#define DPKG_ATTR_SENTINEL
Definition: macros.h:71
char * str_concat(char *dst,...) DPKG_ATTR_SENTINEL
Definition: string.c:32
char * str_escape_fmt(char *dest, const char *src, size_t n)
Escape format characters from a string.
Definition: string.c:102
char * str_quote_meta(const char *src)
Quote shell metacharacters in a string.
Definition: string.c:137
char * str_fmt(const char *fmt,...) DPKG_ATTR_PRINTF(1)
Print formatted output to an allocated string.
Definition: string.c:80
bool str_match_end(const char *str, const char *end)
Match the end of a string.
Definition: string.c:59
char * str_rtrim_spaces(const char *str, char *str_end)
Trim possible ending spaces in string.
Definition: string.c:188
char * str_strip_quotes(char *str)
Check and strip possible surrounding quotes in string.
Definition: string.c:163
void str_gen_crop(const char *str, int max_width, struct str_crop_info *crop)
Generate the crop values for a string given a maximum screen width.
Definition: strwide.c:94
int str_width(const char *str)
Compute the screen width of a string.
Definition: strwide.c:43
unsigned int str_fnv_hash(const char *str)
Fowler/Noll/Vo – FNV-1a simple string hash.
Definition: strhash.c:39
Definition: string.h:66
int str_bytes
Definition: string.h:67
int max_bytes
Definition: string.h:68