rpm  4.15.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 
13 #include <rpm/rpmutil.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
23 static inline int rislower(int c) {
24  return (c >= 'a' && c <= 'z');
25 }
26 
31 static inline int risupper(int c) {
32  return (c >= 'A' && c <= 'Z');
33 }
34 
39 static inline int risalpha(int c) {
40  return (rislower(c) || risupper(c));
41 }
42 
47 static inline int risdigit(int c) {
48  return (c >= '0' && c <= '9');
49 }
50 
55 static inline int risalnum(int c) {
56  return (risalpha(c) || risdigit(c));
57 }
58 
63 static inline int risblank(int c) {
64  return (c == ' ' || c == '\t');
65 }
66 
71 static inline int risspace(int c) {
72  return (risblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
73 }
74 
79 static inline int rtolower(int c) {
80  return ((risupper(c)) ? (c | ('a' - 'A')) : c);
81 }
82 
87 static inline int rtoupper(int c) {
88  return ((rislower(c)) ? (c & ~('a' - 'A')) : c);
89 }
90 
97 static inline unsigned char rnibble(char c)
98 {
99  if (c >= '0' && c <= '9')
100  return (c - '0');
101  if (c >= 'a' && c <= 'f')
102  return (c - 'a') + 10;
103  if (c >= 'A' && c <= 'F')
104  return (c - 'A') + 10;
105  return 0;
106 }
107 
114 static inline int rstreq(const char *s1, const char *s2)
115 {
116  return (strcmp(s1, s2) == 0);
117 }
118 
126 static inline int rstreqn(const char *s1, const char *s2, size_t n)
127 {
128  return (strncmp(s1, s2, n) == 0);
129 }
130 
135 int rstrcasecmp(const char * s1, const char * s2) ;
136 
141 int rstrncasecmp(const char *s1, const char * s2, size_t n) ;
142 
146 int rasprintf(char **strp, const char *fmt, ...) RPM_GNUC_PRINTF(2, 3);
147 
151 int rvasprintf(char **strp, const char *fmt, va_list ap);
152 
159 char *rstrcat(char **dest, const char *src);
160 
167 char *rstrscat(char **dest, const char *arg, ...) RPM_GNUC_NULL_TERMINATED;
168 
179 size_t rstrlcpy(char *dest, const char *src, size_t n);
180 
187 unsigned int rstrhash(const char * string);
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif /* _RPMSTRING_H_ */
#define RPM_GNUC_CONST
Definition: rpmutil.h:72
static RPM_GNUC_CONST int rtolower(int c)
Locale insensitive tolower(3)
Definition: rpmstring.h:79
static RPM_GNUC_CONST int risdigit(int c)
Locale insensitive isdigit(3)
Definition: rpmstring.h:47
#define RPM_GNUC_NULL_TERMINATED
Definition: rpmutil.h:49
static RPM_GNUC_CONST int rtoupper(int c)
Locale insensitive toupper(3)
Definition: rpmstring.h:87
RPM_GNUC_PURE unsigned int rstrhash(const char *string)
String hashing function.
RPM_GNUC_PURE int rstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
static RPM_GNUC_CONST unsigned char rnibble(char c)
Convert hex to binary nibble.
Definition: rpmstring.h:97
static int rstreq(const char *s1, const char *s2)
Test for string equality.
Definition: rpmstring.h:114
static int rstreqn(const char *s1, const char *s2, size_t n)
Test for string equality.
Definition: rpmstring.h:126
char * rstrscat(char **dest, const char *arg,...) RPM_GNUC_NULL_TERMINATED
Concatenate multiple strings with dynamically (re)allocated memory.
static RPM_GNUC_CONST int risalpha(int c)
Locale insensitive isalpha(3)
Definition: rpmstring.h:39
int rasprintf(char **strp, const char *fmt,...) RPM_GNUC_PRINTF(2
asprintf() clone
static RPM_GNUC_CONST int risupper(int c)
Locale insensitive isupper(3)
Definition: rpmstring.h:31
static RPM_GNUC_CONST int rislower(int c)
Locale insensitive islower(3)
Definition: rpmstring.h:23
#define RPM_GNUC_PRINTF(format_idx, arg_idx)
Definition: rpmutil.h:68
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 risspace(int c)
Locale insensitive isspace(3)
Definition: rpmstring.h:71
#define RPM_GNUC_PURE
Definition: rpmutil.h:34
static RPM_GNUC_CONST int risblank(int c)
Locale insensitive isblank(3)
Definition: rpmstring.h:63
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
static RPM_GNUC_CONST int risalnum(int c)
Locale insensitive isalnum(3)
Definition: rpmstring.h:55
RPM_GNUC_PURE int rstrncasecmp(const char *s1, const char *s2, size_t n)
Locale insensitive strncasecmp(3).