1 /*
2  * Distributed under the Boost Software License, Version 1.0.
3  *    (See accompanying file LICENSE_1_0.txt or copy at
4  *          http://www.boost.org/LICENSE_1_0.txt)
5  */
6 module glib.gstrfuncs;
7 
8 import glib.gtypes;
9 import core.stdc.stdarg;
10 
11 
12 enum GAsciiType {
13   G_ASCII_ALNUM  = 1 << 0,
14   G_ASCII_ALPHA  = 1 << 1,
15   G_ASCII_CNTRL  = 1 << 2,
16   G_ASCII_DIGIT  = 1 << 3,
17   G_ASCII_GRAPH  = 1 << 4,
18   G_ASCII_LOWER  = 1 << 5,
19   G_ASCII_PRINT  = 1 << 6,
20   G_ASCII_PUNCT  = 1 << 7,
21   G_ASCII_SPACE  = 1 << 8,
22   G_ASCII_UPPER  = 1 << 9,
23   G_ASCII_XDIGIT = 1 << 10
24 }
25 
26 
27 extern (C) extern __gshared
28 const(guint16*) g_ascii_table;
29 
30 auto g_ascii_isalnum(C)(C c) {
31     return (g_ascii_table[c & 0xff] & G_ASCII_ALNUM) != 0;
32 }
33 
34 auto g_ascii_isalpha(C)(C c) {
35     return (g_ascii_table[c & 0xff] & G_ASCII_ALPHA) != 0;
36 }
37 
38 auto g_ascii_iscntrl(C)(C c) {
39     return (g_ascii_table[c & 0xff] & G_ASCII_CNTRL) != 0;
40 }
41 
42 auto g_ascii_isdigit(C)(C c) {
43     return (g_ascii_table[c & 0xff] & G_ASCII_DIGIT) != 0;
44 }
45 
46 auto g_ascii_isgraph(C)(C c) {
47     return (g_ascii_table[c & 0xff] & G_ASCII_GRAPH) != 0;
48 }
49 
50 auto g_ascii_islower(C)(C c) {
51     return (g_ascii_table[c & 0xff] & G_ASCII_LOWER) != 0;
52 }
53 
54 auto g_ascii_isprint(C)(C c) {
55     return (g_ascii_table[c & 0xff] & G_ASCII_PRINT) != 0;
56 }
57 
58 auto g_ascii_ispunct(C)(C c) {
59     return (g_ascii_table[c & 0xff] & G_ASCII_PUNCT) != 0;
60 }
61 
62 auto g_ascii_isspace(C)(C c) {
63     return (g_ascii_table[c & 0xff] & G_ASCII_SPACE) != 0;
64 }
65 
66 auto g_ascii_isupper(C)(C c) {
67     return (g_ascii_table[c & 0xff] & G_ASCII_UPPER) != 0;
68 }
69 
70 auto g_ascii_isxdigit(C)(C c) {
71     return (g_ascii_table[c & 0xff] & G_ASCII_XDIGIT) != 0;
72 }
73 
74 enum	 G_STR_DELIMITERS = "_-|> <.";
75 
76 /* 29 bytes should enough for all possible values that
77  * g_ascii_dtostr can produce.
78  * Then add 10 for good measure */
79 enum G_ASCII_DTOSTR_BUF_SIZE = 29 + 10;
80 
81 extern (C) {
82 
83 
84     pure gchar                 g_ascii_tolower  (gchar        c);
85 
86     pure gchar                 g_ascii_toupper  (gchar        c);
87 
88 
89     pure gint                  g_ascii_digit_value  (gchar    c);
90 
91     pure gint                  g_ascii_xdigit_value (gchar    c);
92 
93 
94     gchar*	              g_strdelimit     (gchar	     *str,
95                         const(gchar)  *delimiters,
96                         gchar	      new_delimiter);
97 
98     gchar*	              g_strcanon       (gchar        *str,
99                         const(gchar)  *valid_chars,
100                         gchar         substitutor);
101 
102     pure const(gchar) *         g_strerror       (gint	      errnum);
103 
104     pure const(gchar) *         g_strsignal      (gint	      signum);
105 
106     gchar *	              g_strreverse     (gchar	     *str);
107 
108     gsize	              g_strlcpy	       (gchar	     *dest,
109                         const(gchar)  *src,
110                         gsize         dest_size);
111 
112     gsize	              g_strlcat        (gchar	     *dest,
113                         const(gchar)  *src,
114                         gsize         dest_size);
115 
116     gchar *               g_strstr_len     (const(gchar)  *haystack,
117                         gssize        haystack_len,
118                         const(gchar)  *needle);
119 
120     gchar *               g_strrstr        (const(gchar)  *haystack,
121                         const(gchar)  *needle);
122 
123     gchar *               g_strrstr_len    (const(gchar)  *haystack,
124                         gssize        haystack_len,
125                         const(gchar)  *needle);
126 
127 
128     gboolean              g_str_has_suffix (const(gchar)  *str,
129                         const(gchar)  *suffix);
130 
131     gboolean              g_str_has_prefix (const(gchar)  *str,
132                         const(gchar)  *prefix);
133 
134 
135     gdouble	              g_strtod         (const(gchar)  *nptr,
136                         gchar	    **endptr);
137 
138     gdouble	              g_ascii_strtod   (const(gchar)  *nptr,
139                         gchar	    **endptr);
140 
141     guint64		      g_ascii_strtoull (const(gchar) *nptr,
142                         gchar      **endptr,
143                         guint        base);
144 
145     gint64		      g_ascii_strtoll  (const(gchar) *nptr,
146                         gchar      **endptr,
147                         guint        base);
148 
149     gchar *               g_ascii_dtostr   (gchar        *buffer,
150                         gint          buf_len,
151                         gdouble       d);
152 
153     gchar *               g_ascii_formatd  (gchar        *buffer,
154                         gint          buf_len,
155                         const(gchar)  *format,
156                         gdouble       d);
157 
158 
159     gchar*                g_strchug        (gchar        *str);
160 
161     gchar*                g_strchomp       (gchar        *str);
162 
163     extern(D) gchar* g_strstrip(gchar * str) { return g_strchomp(g_strchug(str)); }
164 
165 
166     gint                  g_ascii_strcasecmp  (const(gchar) *s1,
167                            const(gchar) *s2);
168 
169     gint                  g_ascii_strncasecmp (const(gchar) *s1,
170                            const(gchar) *s2,
171                            gsize        n);
172 
173     gchar*                g_ascii_strdown     (const(gchar) *str,
174                            gssize       len);
175 
176     gchar*                g_ascii_strup       (const(gchar) *str,
177                            gssize       len);
178 
179 
180     gboolean              g_str_is_ascii      (const(gchar) *str);
181 
182     deprecated
183     gint                  g_strcasecmp     (const(gchar) *s1,
184                                             const(gchar) *s2);
185     deprecated
186     gint                  g_strncasecmp    (const(gchar) *s1,
187                                             const(gchar) *s2,
188                                             guint        n);
189     deprecated
190     gchar*                g_strdown        (gchar       *str);
191     deprecated
192     gchar*                g_strup          (gchar       *str);
193 
194 
195 
196     gchar*	              g_strdup	       (const(gchar) *str);
197 
198     gchar*	              g_strdup_printf  (const(gchar) *format,
199                         ...);
200 
201     gchar*	              g_strdup_vprintf (const(gchar) *format,
202                         va_list      args);
203 
204     gchar*	              g_strndup	       (const(gchar) *str,
205                         gsize        n);
206 
207     gchar*	              g_strnfill       (gsize        length,
208                         gchar        fill_char);
209 
210     gchar*	              g_strconcat      (const(gchar) *string1,
211                         ...);
212 
213     gchar*                g_strjoin	       (const(gchar)  *separator,
214                         ...);
215 
216 
217     gchar*                g_strcompress    (const (gchar) *source);
218 
219 
220     gchar*                g_strescape      (const(gchar) *source,
221                         const(gchar) *exceptions);
222 
223 
224     gpointer              g_memdup	       (gconstpointer mem,
225                         guint	       byte_size);
226 
227 
228     gchar**	              g_strsplit       (const(gchar)  *string,
229                         const(gchar)  *delimiter,
230                         gint          max_tokens);
231 
232     gchar **	      g_strsplit_set   (const(gchar) *string,
233                         const(gchar) *delimiters,
234                         gint         max_tokens);
235 
236     gchar*                g_strjoinv       (const(gchar)  *separator,
237                         gchar       **str_array);
238 
239     void                  g_strfreev       (gchar       **str_array);
240 
241     gchar**               g_strdupv        (gchar       **str_array);
242 
243     guint                 g_strv_length    (gchar       **str_array);
244 
245 
246     gchar*                g_stpcpy         (gchar        *dest,
247                                             const(char)   *src);
248 
249 
250     gchar *                 g_str_to_ascii                                  (const(gchar)   *str,
251                                                                              const(gchar)   *from_locale);
252 
253 
254     gchar **                g_str_tokenize_and_fold                         (const(gchar)   *string,
255                                                                              const(gchar)   *translit_locale,
256                                                                              gchar       ***ascii_alternates);
257 
258 
259     gboolean                g_str_match_string                              (const(gchar)   *search_term,
260                                                                              const(gchar)   *potential_hit,
261                                                                              gboolean       accept_alternates);
262 
263 }
264