[4.0] Use strip (instead of eu-strip) to support --strip-debug of *.so at build time
[platform/upstream/rpm.git] / rpmio / rpmstring.h
1 #ifndef _RPMSTRING_H_
2 #define _RPMSTRING_H_
3
4 /** \ingroup rpmstring
5  * \file rpmio/rpmstring.h
6  * String manipulation helper functions
7  */
8
9 #include <stddef.h>
10 #include <string.h>
11
12 #include <rpm/rpmutil.h>
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /** \ingroup rpmstring
19  * Locale insensitive islower(3) 
20  */
21 RPM_GNUC_CONST
22 static inline int rislower(int c)  {
23     return (c >= 'a' && c <= 'z');
24 }
25
26 /** \ingroup rpmstring
27  * Locale insensitive isupper(3)
28  */
29 RPM_GNUC_CONST
30 static inline int risupper(int c)  {
31     return (c >= 'A' && c <= 'Z');
32 }
33
34 /** \ingroup rpmstring
35  * Locale insensitive isalpha(3)
36  */
37 RPM_GNUC_CONST
38 static inline int risalpha(int c)  {
39     return (rislower(c) || risupper(c));
40 }
41
42 /** \ingroup rpmstring
43  * Locale insensitive isdigit(3)
44  */
45 RPM_GNUC_CONST
46 static inline int risdigit(int c)  {
47     return (c >= '0' && c <= '9');
48 }
49
50 /** \ingroup rpmstring
51  * Locale insensitive isalnum(3)
52  */
53 RPM_GNUC_CONST
54 static inline int risalnum(int c)  {
55     return (risalpha(c) || risdigit(c));
56 }
57
58 /** \ingroup rpmstring
59  * Locale insensitive isblank(3)
60  */
61 RPM_GNUC_CONST
62 static inline int risblank(int c)  {
63     return (c == ' ' || c == '\t');
64 }
65
66 /** \ingroup rpmstring
67  * Locale insensitive isspace(3)
68  */
69 RPM_GNUC_CONST
70 static inline int risspace(int c)  {
71     return (risblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
72 }
73
74 /** \ingroup rpmstring
75  * Locale insensitive tolower(3)
76  */
77 RPM_GNUC_CONST
78 static inline int rtolower(int c)  {
79     return ((risupper(c)) ? (c | ('a' - 'A')) : c);
80 }
81
82 /** \ingroup rpmstring
83  * Locale insensitive toupper(3)
84  */
85 RPM_GNUC_CONST
86 static inline int rtoupper(int c)  {
87     return ((rislower(c)) ? (c & ~('a' - 'A')) : c);
88 }
89
90 /**
91  * Convert hex to binary nibble.
92  * @param c            hex character
93  * @return             binary nibble
94  */
95 RPM_GNUC_CONST
96 static inline unsigned char rnibble(char c)
97 {
98     if (c >= '0' && c <= '9')
99         return (c - '0');
100     if (c >= 'a' && c <= 'f')
101         return (c - 'a') + 10;
102     if (c >= 'A' && c <= 'F')
103         return (c - 'A') + 10;
104     return 0;
105 }
106
107 /**
108  * Test for string equality
109  * @param s1            string 1
110  * @param s2            string 2
111  * @return              0 if strings differ, 1 if equal
112  */
113 static inline int rstreq(const char *s1, const char *s2)
114 {
115     return (strcmp(s1, s2) == 0);
116 }
117
118 /**
119  * Test for string equality
120  * @param s1            string 1
121  * @param s2            string 2
122  * @param n             compare at most n characters
123  * @return              0 if strings differ, 1 if equal
124  */
125 static inline int rstreqn(const char *s1, const char *s2, size_t n)
126 {
127     return (strncmp(s1, s2, n) == 0);
128 }
129
130 /** \ingroup rpmstring
131  * Locale insensitive strcasecmp(3).
132  */
133 RPM_GNUC_PURE
134 int rstrcasecmp(const char * s1, const char * s2)               ;
135
136 /** \ingroup rpmstring
137  * Locale insensitive strncasecmp(3).
138  */
139 RPM_GNUC_PURE
140 int rstrncasecmp(const char *s1, const char * s2, size_t n)     ;
141
142 /** \ingroup rpmstring
143  * asprintf() clone
144  */
145 int rasprintf(char **strp, const char *fmt, ...) RPM_GNUC_PRINTF(2, 3);
146
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
152  */
153 char *rstrcat(char **dest, const char *src);
154
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
160  */
161 char *rstrscat(char **dest, const char *arg, ...) RPM_GNUC_NULL_TERMINATED;
162
163 /** \ingroup rpmstring
164  * strlcpy() clone: 
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
172  */
173 size_t rstrlcpy(char *dest, const char *src, size_t n);
174
175 /** \ingroup rpmstring
176  * String hashing function
177  * @param string        string to hash
178  * @return              hash id
179  */
180 RPM_GNUC_PURE
181 unsigned int rstrhash(const char * string);
182
183 #ifdef __cplusplus
184 }
185 #endif
186
187 #endif  /* _RPMSTRING_H_ */