rpm 4.18.1
rpmstring.h
Go to the documentation of this file.
1#ifndef _RPMSTRING_H_
2#define _RPMSTRING_H_
3
9#include <stddef.h>
10#include <string.h>
11#include <stdarg.h>
12#include <stdint.h>
13
14#include <rpm/rpmutil.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
24static inline int rislower(int c) {
25 return (c >= 'a' && c <= 'z');
26}
27
32static inline int risupper(int c) {
33 return (c >= 'A' && c <= 'Z');
34}
35
40static inline int risalpha(int c) {
41 return (rislower(c) || risupper(c));
42}
43
48static inline int risdigit(int c) {
49 return (c >= '0' && c <= '9');
50}
51
56static inline int risalnum(int c) {
57 return (risalpha(c) || risdigit(c));
58}
59
64static inline int risblank(int c) {
65 return (c == ' ' || c == '\t');
66}
67
72static inline int risspace(int c) {
73 return (risblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
74}
75
80static inline int rtolower(int c) {
81 return ((risupper(c)) ? (c | ('a' - 'A')) : c);
82}
83
88static inline int rtoupper(int c) {
89 return ((rislower(c)) ? (c & ~('a' - 'A')) : c);
90}
91
98static inline unsigned char rnibble(char c)
99{
100 if (c >= '0' && c <= '9')
101 return (c - '0');
102 if (c >= 'a' && c <= 'f')
103 return (c - 'a') + 10;
104 if (c >= 'A' && c <= 'F')
105 return (c - 'A') + 10;
106 return 0;
107}
108
115static inline int rstreq(const char *s1, const char *s2)
116{
117 return (strcmp(s1, s2) == 0);
118}
119
127static inline int rstreqn(const char *s1, const char *s2, size_t n)
128{
129 return (strncmp(s1, s2, n) == 0);
130}
131
136int rstrcasecmp(const char * s1, const char * s2) ;
137
142int rstrncasecmp(const char *s1, const char * s2, size_t n) ;
143
147int rasprintf(char **strp, const char *fmt, ...) RPM_GNUC_PRINTF(2, 3);
148
152int rvasprintf(char **strp, const char *fmt, va_list ap);
153
160char *rstrcat(char **dest, const char *src);
161
168char *rstrscat(char **dest, const char *arg, ...) RPM_GNUC_NULL_TERMINATED;
169
180size_t rstrlcpy(char *dest, const char *src, size_t n);
181
188unsigned int rstrhash(const char * string);
189
196char * rpmhex(const uint8_t *p, size_t plen);
197
205char * pgpHexStr(const uint8_t *p, size_t plen);
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif /* _RPMSTRING_H_ */
static RPM_GNUC_CONST int rtolower(int c)
Locale insensitive tolower(3)
Definition: rpmstring.h:80
RPM_GNUC_PURE unsigned int rstrhash(const char *string)
String hashing function.
static RPM_GNUC_CONST int rtoupper(int c)
Locale insensitive toupper(3)
Definition: rpmstring.h:88
static RPM_GNUC_CONST int risalpha(int c)
Locale insensitive isalpha(3)
Definition: rpmstring.h:40
static RPM_GNUC_CONST int risdigit(int c)
Locale insensitive isdigit(3)
Definition: rpmstring.h:48
char * rstrcat(char **dest, const char *src)
Concatenate two strings with dynamically (re)allocated memory.
int int rvasprintf(char **strp, const char *fmt, va_list ap)
vasprintf() clone
RPM_GNUC_PURE int rstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
static RPM_GNUC_CONST int rislower(int c)
Locale insensitive islower(3)
Definition: rpmstring.h:24
static RPM_GNUC_CONST int risspace(int c)
Locale insensitive isspace(3)
Definition: rpmstring.h:72
size_t rstrlcpy(char *dest, const char *src, size_t n)
strlcpy() clone: Copy src to string dest of size n.
static RPM_GNUC_CONST int risalnum(int c)
Locale insensitive isalnum(3)
Definition: rpmstring.h:56
RPM_GNUC_DEPRECATED char * pgpHexStr(const uint8_t *p, size_t plen)
Deprecated, do not use.
char * rpmhex(const uint8_t *p, size_t plen)
Return hex formatted representation of bytes.
RPM_GNUC_PURE int rstrncasecmp(const char *s1, const char *s2, size_t n)
Locale insensitive strncasecmp(3).
static RPM_GNUC_CONST int risblank(int c)
Locale insensitive isblank(3)
Definition: rpmstring.h:64
static RPM_GNUC_CONST int risupper(int c)
Locale insensitive isupper(3)
Definition: rpmstring.h:32
char * rstrscat(char **dest, const char *arg,...) RPM_GNUC_NULL_TERMINATED
Concatenate multiple strings with dynamically (re)allocated memory.
int rasprintf(char **strp, const char *fmt,...) RPM_GNUC_PRINTF(2
asprintf() clone
static int rstreq(const char *s1, const char *s2)
Test for string equality.
Definition: rpmstring.h:115
static RPM_GNUC_CONST unsigned char rnibble(char c)
Convert hex to binary nibble.
Definition: rpmstring.h:98
static int rstreqn(const char *s1, const char *s2, size_t n)
Test for string equality.
Definition: rpmstring.h:127
Miscellaneous utility macros:
#define RPM_GNUC_DEPRECATED
Definition: rpmutil.h:81
#define RPM_GNUC_CONST
Definition: rpmutil.h:72
#define RPM_GNUC_PURE
Definition: rpmutil.h:34
#define RPM_GNUC_NULL_TERMINATED
Definition: rpmutil.h:49
#define RPM_GNUC_PRINTF(format_idx, arg_idx)
Definition: rpmutil.h:68