5 * \file rpmio/rpmstring.h
6 * String manipulation helper functions
12 #include <rpm/rpmutil.h>
18 /** \ingroup rpmstring
19 * Locale insensitive islower(3)
22 static inline int rislower(int c) {
23 return (c >= 'a' && c <= 'z');
26 /** \ingroup rpmstring
27 * Locale insensitive isupper(3)
30 static inline int risupper(int c) {
31 return (c >= 'A' && c <= 'Z');
34 /** \ingroup rpmstring
35 * Locale insensitive isalpha(3)
38 static inline int risalpha(int c) {
39 return (rislower(c) || risupper(c));
42 /** \ingroup rpmstring
43 * Locale insensitive isdigit(3)
46 static inline int risdigit(int c) {
47 return (c >= '0' && c <= '9');
50 /** \ingroup rpmstring
51 * Locale insensitive isalnum(3)
54 static inline int risalnum(int c) {
55 return (risalpha(c) || risdigit(c));
58 /** \ingroup rpmstring
59 * Locale insensitive isblank(3)
62 static inline int risblank(int c) {
63 return (c == ' ' || c == '\t');
66 /** \ingroup rpmstring
67 * Locale insensitive isspace(3)
70 static inline int risspace(int c) {
71 return (risblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
74 /** \ingroup rpmstring
75 * Locale insensitive tolower(3)
78 static inline int rtolower(int c) {
79 return ((risupper(c)) ? (c | ('a' - 'A')) : c);
82 /** \ingroup rpmstring
83 * Locale insensitive toupper(3)
86 static inline int rtoupper(int c) {
87 return ((rislower(c)) ? (c & ~('a' - 'A')) : c);
91 * Convert hex to binary nibble.
92 * @param c hex character
93 * @return binary nibble
96 static inline unsigned char rnibble(char c)
98 if (c >= '0' && c <= '9')
100 if (c >= 'a' && c <= 'f')
101 return (c - 'a') + 10;
102 if (c >= 'A' && c <= 'F')
103 return (c - 'A') + 10;
108 * Test for string equality
111 * @return 0 if strings differ, 1 if equal
113 static inline int rstreq(const char *s1, const char *s2)
115 return (strcmp(s1, s2) == 0);
119 * Test for string equality
122 * @param n compare at most n characters
123 * @return 0 if strings differ, 1 if equal
125 static inline int rstreqn(const char *s1, const char *s2, size_t n)
127 return (strncmp(s1, s2, n) == 0);
130 /** \ingroup rpmstring
131 * Locale insensitive strcasecmp(3).
134 int rstrcasecmp(const char * s1, const char * s2) ;
136 /** \ingroup rpmstring
137 * Locale insensitive strncasecmp(3).
140 int rstrncasecmp(const char *s1, const char * s2, size_t n) ;
142 /** \ingroup rpmstring
145 int rasprintf(char **strp, const char *fmt, ...) RPM_GNUC_PRINTF(2, 3);
147 /** \ingroup rpmstring
148 * Concatenate two strings with dynamically (re)allocated memory.
149 * @param dest pointer to destination string
150 * @param src source string
151 * @return realloc'd dest with src appended
153 char *rstrcat(char **dest, const char *src);
155 /** \ingroup rpmstring
156 * Concatenate multiple strings with dynamically (re)allocated memory.
157 * @param dest pointer to destination string
158 * @param arg NULL terminated list of strings to concatenate
159 * @return realloc'd dest with strings appended
161 char *rstrscat(char **dest, const char *arg, ...) RPM_GNUC_NULL_TERMINATED;
163 /** \ingroup rpmstring
165 * Copy src to string dest of size n. At most n-1 characters
166 * will be copied. Always zero-terminates (unless n == 0).
167 * Length of src is returned; if retval >= n, truncation occurred.
168 * @param dest destination buffer
169 * @param src string to copy
170 * @param n destination buffer size
171 * @return length of src string
173 size_t rstrlcpy(char *dest, const char *src, size_t n);
175 /** \ingroup rpmstring
176 * String hashing function
177 * @param string string to hash
181 unsigned int rstrhash(const char * string);
187 #endif /* _RPMSTRING_H_ */