glib-2.0.vapi 211 KB
Newer Older
1
/* glib-2.0.vala
2
 *
3
 * Copyright (C) 2006-2014  Jürg Billeter
4
 * Copyright (C) 2006-2008  Raffaele Sandrini
5
 * Copyright (C) 2007  Mathias Hasselmann
6 7 8 9
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12 13 14 15
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
16
 *
17 18 19 20
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
21 22 23
 * As a special exception, if you use inline functions from this file, this
 * file does not by itself cause the resulting executable to be covered by
 * the GNU Lesser General Public License.
24
 *
25 26
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
27
 *	Raffaele Sandrini <rasa@gmx.ch>
28
 *	Mathias Hasselmann <mathias.hasselmann@gmx.de>
29 30
 */

31
[SimpleType]
32
[GIR (name = "gboolean")]
33
[CCode (cname = "gboolean", cheader_filename = "glib.h", type_id = "G_TYPE_BOOLEAN", marshaller_type_name = "BOOLEAN", get_value_function = "g_value_get_boolean", set_value_function = "g_value_set_boolean", default_value = "FALSE", type_signature = "b")]
34
[BooleanType]
35
public struct bool {
36 37 38 39 40 41 42
	public string to_string () {
		if (this) {
			return "true";
		} else {
			return "false";
		}
	}
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

	public static bool parse (string str) {
		if (str == "true") {
			return true;
		} else {
			return false;
		}
	}
	public static bool try_parse (string str, out bool result = null) {
		if (str == "true") {
			result = true;
			return true;
		} else if (str == "false") {
			result = false;
			return true;
		} else {
			result = false;
			return false;
		}
	}
63 64
}

65
[SimpleType]
66
[GIR (name = "gint8")]
67
[CCode (cname = "gchar", cprefix = "g_ascii_", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_schar", set_value_function = "g_value_set_schar", default_value = "\'\\0\'", type_signature = "y")]
68
[IntegerType (rank = 2, min = 0, max = 127)]
69
public struct char {
70
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
71
	public string to_string (string format = "%c");
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	public bool isalnum ();
	public bool isalpha ();
	public bool iscntrl ();
	public bool isdigit ();
	public bool isgraph ();
	public bool islower ();
	public bool isprint ();
	public bool ispunct ();
	public bool isspace ();
	public bool isupper ();
	public bool isxdigit ();
	public int digit_value ();
	public int xdigit_value ();
	public char tolower ();
	public char toupper ();
87

88 89 90 91
	[CCode (cname = "MIN")]
	public static char min (char a, char b);
	[CCode (cname = "MAX")]
	public static char max (char a, char b);
92 93
	[CCode (cname = "CLAMP")]
	public char clamp (char low, char high);
94 95
}

96
[SimpleType]
97
[GIR (name = "guint8")]
98
[CCode (cname = "guchar", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "\'\\0\'", type_signature = "y")]
99
[IntegerType (rank = 3, min = 0, max = 255)]
100
public struct uchar {
101
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
102
	public string to_string (string format = "%hhu");
103

104 105 106 107
	[CCode (cname = "MIN")]
	public static uchar min (uchar a, uchar b);
	[CCode (cname = "MAX")]
	public static uchar max (uchar a, uchar b);
108 109
	[CCode (cname = "CLAMP")]
	public uchar clamp (uchar low, uchar high);
110 111
}

112
[SimpleType]
113
[GIR (name = "gint")]
114
[CCode (cname = "gint", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0", default_value_on_error = "-1", type_signature = "i")]
115
[IntegerType (rank = 6)]
116
public struct int {
117
	[CCode (cname = "G_MININT")]
118
	public const int MIN;
119
	[CCode (cname = "G_MAXINT")]
120
	public const int MAX;
121

122
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
123
	public string to_string (string format = "%i");
124

125 126 127 128
	[CCode (cname = "MIN")]
	public static int min (int a, int b);
	[CCode (cname = "MAX")]
	public static int max (int a, int b);
129 130
	[CCode (cname = "CLAMP")]
	public int clamp (int low, int high);
131

Jürg Billeter's avatar
Jürg Billeter committed
132
	[CCode (cname = "GINT_TO_POINTER")]
133
	public void* to_pointer ();
134 135
	[CCode (cname = "GPOINTER_TO_INT")]
	public static int from_pointer (void* p);
136

137
	[CCode (cname = "abs", cheader_filename = "stdlib.h")]
138
	public int abs ();
139 140 141 142 143 144 145 146 147 148

	[CCode (cname = "GINT_TO_BE")]
	public int to_big_endian ();
	[CCode (cname = "GINT_TO_LE")]
	public int to_little_endian ();

	[CCode (cname = "GINT_FROM_BE")]
	public static int from_big_endian (int val);
	[CCode (cname = "GINT_FROM_LE")]
	public static int from_little_endian (int val);
149 150 151

	[CCode (cname = "atoi", cheader_filename = "stdlib.h")]
	public static int parse (string str);
152 153
}

154
[SimpleType]
155
[GIR (name = "guint")]
156
[CCode (cname = "guint", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
157
[IntegerType (rank = 7)]
158
public struct uint {
159
	[CCode (cname = "0")]
160
	public const uint MIN;
161
	[CCode (cname = "G_MAXUINT")]
162
	public const uint MAX;
163

164
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
165
	public string to_string (string format = "%u");
166

167 168 169 170
	[CCode (cname = "MIN")]
	public static uint min (uint a, uint b);
	[CCode (cname = "MAX")]
	public static uint max (uint a, uint b);
171 172
	[CCode (cname = "CLAMP")]
	public uint clamp (uint low, uint high);
173

Jürg Billeter's avatar
Jürg Billeter committed
174
	[CCode (cname = "GUINT_TO_POINTER")]
175
	public void* to_pointer ();
176 177
	[CCode (cname = "GPOINTER_TO_UINT")]
	public static uint from_pointer (void* p);
178 179 180 181 182 183 184 185 186 187

	[CCode (cname = "GUINT_TO_BE")]
	public uint to_big_endian ();
	[CCode (cname = "GUINT_TO_LE")]
	public uint to_little_endian ();

	[CCode (cname = "GUINT_FROM_BE")]
	public static uint from_big_endian (uint val);
	[CCode (cname = "GUINT_FROM_LE")]
	public static uint from_little_endian (uint val);
188 189
}

190
[SimpleType]
191
[GIR (name = "gshort")]
192
[CCode (cname = "gshort", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0", default_value_on_error = "-1", type_signature = "n")]
193
[IntegerType (rank = 4, min = -32768, max = 32767)]
194
public struct short {
195
	[CCode (cname = "G_MINSHORT")]
196
	public const short MIN;
197
	[CCode (cname = "G_MAXSHORT")]
198
	public const short MAX;
199

200
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
201
	public string to_string (string format = "%hi");
202

203 204 205 206
	[CCode (cname = "MIN")]
	public static short min (short a, short b);
	[CCode (cname = "MAX")]
	public static short max (short a, short b);
207 208
	[CCode (cname = "CLAMP")]
	public short clamp (short low, short high);
209
	[CCode (cname = "abs", cheader_filename = "stdlib.h")]
210
	public short abs ();
211 212
}

213
[SimpleType]
214
[GIR (name = "gushort")]
215
[CCode (cname = "gushort", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "q")]
216
[IntegerType (rank = 5, min = 0, max = 65535)]
217
public struct ushort {
218
	[CCode (cname = "0U")]
219
	public const ushort MIN;
220
	[CCode (cname = "G_MAXUSHORT")]
221
	public const ushort MAX;
222

223
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
224
	public string to_string (string format = "%hu");
225

226 227 228 229
	[CCode (cname = "MIN")]
	public static ushort min (ushort a, ushort b);
	[CCode (cname = "MAX")]
	public static ushort max (ushort a, ushort b);
230 231
	[CCode (cname = "CLAMP")]
	public ushort clamp (ushort low, ushort high);
232 233
}

234
[SimpleType]
235
[GIR (name = "glong")]
236
[CCode (cname = "glong", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L", default_value_on_error = "-1L")]
237
[IntegerType (rank = 8)]
238
public struct long {
239
	[CCode (cname = "G_MINLONG")]
240
	public const long MIN;
241
	[CCode (cname = "G_MAXLONG")]
242
	public const long MAX;
243

244
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
245
	public string to_string (string format = "%li");
246

247 248 249 250
	[CCode (cname = "MIN")]
	public static long min (long a, long b);
	[CCode (cname = "MAX")]
	public static long max (long a, long b);
251 252
	[CCode (cname = "CLAMP")]
	public long clamp (long low, long high);
253
	[CCode (cname = "labs", cheader_filename = "stdlib.h")]
254
	public long abs ();
255 256 257 258 259 260 261 262 263 264

	[CCode (cname = "GLONG_TO_BE")]
	public long to_big_endian ();
	[CCode (cname = "GLONG_TO_LE")]
	public long to_little_endian ();

	[CCode (cname = "GLONG_FROM_BE")]
	public static long from_big_endian (long val);
	[CCode (cname = "GLONG_FROM_LE")]
	public static long from_little_endian (long val);
265

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
	[CCode (cname = "strtol", cheader_filename = "stdlib.h")]
	static long strtol (string nptr, out char* endptr, uint _base);

	public static long parse (string str) {
		return strtol (str, null, 0);
	}

	public static bool try_parse (string str, out long result = null, out unowned string unparsed = null) {
		char* endptr;
		result = strtol (str, out endptr, 0);
		if (endptr == (char*) str + str.length) {
			unparsed = "";
			return true;
		} else {
			unparsed = (string) endptr;
			return false;
		}
	}
284 285
}

286
[SimpleType]
287
[GIR (name = "gulong")]
288
[CCode (cname = "gulong", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")]
289
[IntegerType (rank = 9)]
290
public struct ulong {
291
	[CCode (cname = "0UL")]
292
	public const ulong MIN;
293
	[CCode (cname = "G_MAXULONG")]
294
	public const ulong MAX;
295

296
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
297
	public string to_string (string format = "%lu");
298

299 300 301 302
	[CCode (cname = "MIN")]
	public static ulong min (ulong a, ulong b);
	[CCode (cname = "MAX")]
	public static ulong max (ulong a, ulong b);
303 304
	[CCode (cname = "CLAMP")]
	public ulong clamp (ulong low, ulong high);
305 306 307 308 309 310 311 312 313 314

	[CCode (cname = "GULONG_TO_BE")]
	public ulong to_big_endian ();
	[CCode (cname = "GULONG_TO_LE")]
	public ulong to_little_endian ();

	[CCode (cname = "GULONG_FROM_BE")]
	public static ulong from_big_endian (ulong val);
	[CCode (cname = "GULONG_FROM_LE")]
	public static ulong from_little_endian (ulong val);
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333

	[CCode (cname = "strtoul", cheader_filename = "stdlib.h")]
	static ulong strtoul (string nptr, out char* endptr, uint _base);

	public static ulong parse (string str) {
		return strtoul (str, null, 0);
	}

	public static bool try_parse (string str, out ulong result = null, out unowned string unparsed = null) {
		char* endptr;
		result = strtoul (str, out endptr, 0);
		if (endptr == (char*) str + str.length) {
			unparsed = "";
			return true;
		} else {
			unparsed = (string) endptr;
			return false;
		}
	}
334 335
}

Jürg Billeter's avatar
Jürg Billeter committed
336
[SimpleType]
337
[GIR (name = "gulong")]
Jürg Billeter's avatar
Jürg Billeter committed
338
[CCode (cname = "gsize", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")]
339
[IntegerType (rank = 9)]
Jürg Billeter's avatar
Jürg Billeter committed
340 341
public struct size_t {
	[CCode (cname = "0UL")]
342
	public const ulong MIN;
343
	[Version (since = "2.4")]
Jürg Billeter's avatar
Jürg Billeter committed
344
	[CCode (cname = "G_MAXSIZE")]
345
	public const ulong MAX;
Jürg Billeter's avatar
Jürg Billeter committed
346

347
	[Version (since = "2.6")]
348 349
	[CCode (cname = "G_GSIZE_FORMAT")]
	public const string FORMAT;
350
	[Version (since = "2.6")]
351 352 353
	[CCode (cname = "G_GSIZE_MODIFIER")]
	public const string FORMAT_MODIFIER;

354
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
355
	public string to_string (string format = "%" + FORMAT);
Jürg Billeter's avatar
Jürg Billeter committed
356 357

	[CCode (cname = "GSIZE_TO_POINTER")]
358
	public void* to_pointer ();
359 360
	[CCode (cname = "GPOINTER_TO_SIZE")]
	public static size_t from_pointer (void* p);
361

362 363 364 365
	[CCode (cname = "MIN")]
	public static size_t min (size_t a, size_t b);
	[CCode (cname = "MAX")]
	public static size_t max (size_t a, size_t b);
366 367
	[CCode (cname = "CLAMP")]
	public size_t clamp (size_t low, size_t high);
Jürg Billeter's avatar
Jürg Billeter committed
368 369 370
}

[SimpleType]
371
[GIR (name = "glong")]
372
[CCode (cname = "gssize", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L", default_value_on_error = "-1L")]
373
[IntegerType (rank = 8)]
Jürg Billeter's avatar
Jürg Billeter committed
374
public struct ssize_t {
375
	[Version (since = "2.14")]
Jürg Billeter's avatar
Jürg Billeter committed
376
	[CCode (cname = "G_MINSSIZE")]
377
	public const long MIN;
378
	[Version (since = "2.14")]
Jürg Billeter's avatar
Jürg Billeter committed
379
	[CCode (cname = "G_MAXSSIZE")]
380
	public const long MAX;
Jürg Billeter's avatar
Jürg Billeter committed
381

382
	[Version (since = "2.6")]
383 384 385 386 387
	[CCode (cname = "G_GSSIZE_FORMAT")]
	public const string FORMAT;
	[CCode (cname = "G_GSIZE_MODIFIER")]
	public const string FORMAT_MODIFIER;

388
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
389
	public string to_string (string format = "%" + FORMAT);
390

391 392 393 394
	[CCode (cname = "MIN")]
	public static ssize_t min (ssize_t a, ssize_t b);
	[CCode (cname = "MAX")]
	public static ssize_t max (ssize_t a, ssize_t b);
395 396
	[CCode (cname = "CLAMP")]
	public ssize_t clamp (ssize_t low, ssize_t high);
Jürg Billeter's avatar
Jürg Billeter committed
397 398
}

399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
[SimpleType]
[GIR (name = "gulong")]
[CCode (cname = "guintptr", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")]
[IntegerType (rank = 9)]
public struct uintptr {
	[CCode (cname = "0UL")]
	public const ulong MIN;
	[CCode (cname = "G_MAXSIZE")]
	public const ulong MAX;

	[CCode (cname = "G_GUINTPTR_FORMAT")]
	public const string FORMAT;
	[CCode (cname = "G_GINTPTR_MODIFIER")]
	public const string FORMAT_MODIFIER;

	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
	public string to_string (string format = "%" + FORMAT);

	[CCode (cname = "GSIZE_TO_POINTER")]
	public void* to_pointer ();
419 420
	[CCode (cname = "GPOINTER_TO_SIZE")]
	public static uintptr from_pointer (void* p);
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455

	[CCode (cname = "MIN")]
	public static uintptr min (uintptr a, uintptr b);
	[CCode (cname = "MAX")]
	public static uintptr max (uintptr a, uintptr b);
	[CCode (cname = "CLAMP")]
	public uintptr clamp (uintptr low, uintptr high);
}

[SimpleType]
[GIR (name = "glong")]
[CCode (cname = "gintptr", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L")]
[IntegerType (rank = 8)]
public struct intptr {
	[CCode (cname = "G_MINSSIZE")]
	public const long MIN;
	[CCode (cname = "G_MAXSSIZE")]
	public const long MAX;

	[CCode (cname = "G_GINTPTR_FORMAT")]
	public const string FORMAT;
	[CCode (cname = "G_GINTPTR_MODIFIER")]
	public const string FORMAT_MODIFIER;

	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
	public string to_string (string format = "%" + FORMAT);

	[CCode (cname = "MIN")]
	public static intptr min (intptr a, intptr b);
	[CCode (cname = "MAX")]
	public static intptr max (intptr a, intptr b);
	[CCode (cname = "CLAMP")]
	public intptr clamp (intptr low, intptr high);
}

456
[SimpleType]
457
[GIR (name = "gint8")]
458
[CCode (cname = "gint8", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "0", default_value_on_error = "-1", type_signature = "y")]
459
[IntegerType (rank = 1, min = -128, max = 127)]
460
public struct int8 {
461
	[Version (since = "2.4")]
462
	[CCode (cname = "G_MININT8")]
463
	public const int8 MIN;
464
	[Version (since = "2.4")]
465
	[CCode (cname = "G_MAXINT8")]
466
	public const int8 MAX;
467

468
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
469
	public string to_string (string format = "%hhi");
470

471 472 473 474
	[CCode (cname = "MIN")]
	public static int8 min (int8 a, int8 b);
	[CCode (cname = "MAX")]
	public static int8 max (int8 a, int8 b);
475 476
	[CCode (cname = "CLAMP")]
	public int8 clamp (int8 low, int8 high);
477 478
}

479
[SimpleType]
480
[GIR (name = "guint8")]
481
[CCode (cname = "guint8", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "0U", type_signature = "y")]
482
[IntegerType (rank = 3, min = 0, max = 255)]
483 484
public struct uint8 {
	[CCode (cname = "0U")]
485
	public const uint8 MIN;
486
	[Version (since = "2.4")]
487
	[CCode (cname = "G_MAXUINT8")]
488
	public const uint8 MAX;
489

490
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
491
	public string to_string (string format = "%hhu");
492

493 494 495 496
	[CCode (cname = "MIN")]
	public static uint8 min (uint8 a, uint8 b);
	[CCode (cname = "MAX")]
	public static uint8 max (uint8 a, uint8 b);
497 498
	[CCode (cname = "CLAMP")]
	public uint8 clamp (uint8 low, uint8 high);
499 500
}

501
[SimpleType]
502
[GIR (name = "gint16")]
503
[CCode (cname = "gint16", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0", default_value_on_error = "-1", type_signature = "n")]
504
[IntegerType (rank = 4, min = -32768, max = 32767)]
505
public struct int16 {
506
	[Version (since = "2.4")]
507
	[CCode (cname = "G_MININT16")]
508
	public const int16 MIN;
509
	[Version (since = "2.4")]
510
	[CCode (cname = "G_MAXINT16")]
511
	public const int16 MAX;
512

513 514
	[CCode (cname = "G_GINT16_FORMAT")]
	public const string FORMAT;
515
	[Version (since = "2.4")]
516 517 518
	[CCode (cname = "G_GINT16_MODIFIER")]
	public const string FORMAT_MODIFIER;

519
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
520
	public string to_string (string format = "%" + FORMAT);
521

522 523 524 525
	[CCode (cname = "MIN")]
	public static int16 min (int16 a, int16 b);
	[CCode (cname = "MAX")]
	public static int16 max (int16 a, int16 b);
526 527
	[CCode (cname = "CLAMP")]
	public int16 clamp (int16 low, int16 high);
528 529 530 531 532 533 534 535 536 537

	[CCode (cname = "GINT16_TO_BE")]
	public int16 to_big_endian ();
	[CCode (cname = "GINT16_TO_LE")]
	public int16 to_little_endian ();

	[CCode (cname = "GINT16_FROM_BE")]
	public static int16 from_big_endian (int16 val);
	[CCode (cname = "GINT16_FROM_LE")]
	public static int16 from_little_endian (int16 val);
538 539
}

540
[SimpleType]
541
[GIR (name = "guint16")]
542
[CCode (cname = "guint16", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "q")]
543
[IntegerType (rank = 5, min = 0, max = 65535)]
544
public struct uint16 {
545
	[CCode (cname = "0U")]
546
	public const uint16 MIN;
547
	[Version (since = "2.4")]
548
	[CCode (cname = "G_MAXUINT16")]
549
	public const uint16 MAX;
550

551 552 553 554 555
	[CCode (cname = "G_GUINT16_FORMAT")]
	public const string FORMAT;
	[CCode (cname = "G_GINT16_MODIFIER")]
	public const string FORMAT_MODIFIER;

556
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
557
	public string to_string (string format = "%hu");
558

559 560 561 562
	[CCode (cname = "MIN")]
	public static uint16 min (uint16 a, uint16 b);
	[CCode (cname = "MAX")]
	public static uint16 max (uint16 a, uint16 b);
563 564
	[CCode (cname = "CLAMP")]
	public uint16 clamp (uint16 low, uint16 high);
565 566 567 568 569 570 571 572 573 574

	[CCode (cname = "GUINT16_TO_BE")]
	public uint16 to_big_endian ();
	[CCode (cname = "GUINT16_TO_LE")]
	public uint16 to_little_endian ();

	[CCode (cname = "GUINT16_FROM_BE")]
	public static uint16 from_big_endian (uint16 val);
	[CCode (cname = "GUINT16_FROM_LE")]
	public static uint16 from_little_endian (uint16 val);
575

576 577 578 579 580
	[CCode (cname = "g_htons")]
	public static uint16 to_network (uint16 val);
	[CCode (cname = "g_ntohs")]
	public static uint16 from_network (uint16 val);

581 582 583 584 585 586
	[CCode (cname = "GUINT16_SWAP_BE_PDP")]
	public uint16 swap_big_endian_pdp ();
	[CCode (cname = "GUINT16_SWAP_LE_BE")]
	public uint16 swap_little_endian_big_endian ();
	[CCode (cname = "GUINT16_SWAP_LE_PDP")]
	public uint16 swap_little_endian_pdp ();
587 588
}

589
[SimpleType]
590
[GIR (name = "gint32")]
591
[CCode (cname = "gint32", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0", default_value_on_error = "-1", type_signature = "i")]
592
[IntegerType (rank = 6)]
593
public struct int32 {
594
	[Version (since = "2.4")]
595
	[CCode (cname = "G_MININT32")]
596
	public const int32 MIN;
597
	[Version (since = "2.4")]
598
	[CCode (cname = "G_MAXINT32")]
599
	public const int32 MAX;
600

601 602
	[CCode (cname = "G_GINT32_FORMAT")]
	public const string FORMAT;
603
	[Version (since = "2.4")]
604 605 606
	[CCode (cname = "G_GINT32_MODIFIER")]
	public const string FORMAT_MODIFIER;

607
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
608
	public string to_string (string format = "%i");
609

610 611 612 613
	[CCode (cname = "MIN")]
	public static int32 min (int32 a, int32 b);
	[CCode (cname = "MAX")]
	public static int32 max (int32 a, int32 b);
614 615
	[CCode (cname = "CLAMP")]
	public int32 clamp (int32 low, int32 high);
616 617 618 619 620 621 622 623 624 625

	[CCode (cname = "GINT32_TO_BE")]
	public int32 to_big_endian ();
	[CCode (cname = "GINT32_TO_LE")]
	public int32 to_little_endian ();

	[CCode (cname = "GINT32_FROM_BE")]
	public static int32 from_big_endian (int32 val);
	[CCode (cname = "GINT32_FROM_LE")]
	public static int32 from_little_endian (int32 val);
626 627
}

628
[SimpleType]
629
[GIR (name = "guint32")]
630
[CCode (cname = "guint32", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
631
[IntegerType (rank = 7)]
632
public struct uint32 {
633
	[CCode (cname = "0U")]
634
	public const uint32 MIN;
635
	[Version (since = "2.4")]
636
	[CCode (cname = "G_MAXUINT32")]
637
	public const uint32 MAX;
638

639 640 641 642 643
	[CCode (cname = "G_GUINT32_FORMAT")]
	public const string FORMAT;
	[CCode (cname = "G_GINT32_MODIFIER")]
	public const string FORMAT_MODIFIER;

644
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
645
	public string to_string (string format = "%u");
646

647 648 649 650
	[CCode (cname = "MIN")]
	public static uint32 min (uint32 a, uint32 b);
	[CCode (cname = "MAX")]
	public static uint32 max (uint32 a, uint32 b);
651 652
	[CCode (cname = "CLAMP")]
	public uint32 clamp (uint32 low, uint32 high);
653 654 655 656 657 658 659 660 661 662

	[CCode (cname = "GUINT32_TO_BE")]
	public uint32 to_big_endian ();
	[CCode (cname = "GUINT32_TO_LE")]
	public uint32 to_little_endian ();

	[CCode (cname = "GUINT32_FROM_BE")]
	public static uint32 from_big_endian (uint32 val);
	[CCode (cname = "GUINT32_FROM_LE")]
	public static uint32 from_little_endian (uint32 val);
663

664 665 666 667 668
	[CCode (cname = "g_htonl")]
	public static uint32 to_network (uint32 val);
	[CCode (cname = "g_ntohl")]
	public static uint32 from_network (uint32 val);

669 670 671 672 673 674
	[CCode (cname = "GUINT32_SWAP_BE_PDP")]
	public uint32 swap_big_endian_pdp ();
	[CCode (cname = "GUINT32_SWAP_LE_BE")]
	public uint32 swap_little_endian_big_endian ();
	[CCode (cname = "GUINT32_SWAP_LE_PDP")]
	public uint32 swap_little_endian_pdp ();
675 676
}

677
[SimpleType]
678
[GIR (name = "gint64")]
679
[CCode (cname = "gint64", cheader_filename = "glib.h", type_id = "G_TYPE_INT64", marshaller_type_name = "INT64", get_value_function = "g_value_get_int64", set_value_function = "g_value_set_int64", default_value = "0LL", default_value_on_error = "-1LL", type_signature = "x")]
680
[IntegerType (rank = 10)]
681
public struct int64 {
682
	[CCode (cname = "G_MININT64")]
683
	public const int64 MIN;
684
	[CCode (cname = "G_MAXINT64")]
685
	public const int64 MAX;
686

687 688
	[CCode (cname = "G_GINT64_FORMAT")]
	public const string FORMAT;
689
	[Version (since = "2.4")]
690 691 692
	[CCode (cname = "G_GINT64_MODIFIER")]
	public const string FORMAT_MODIFIER;

693
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
694
	public string to_string (string format = "%" + FORMAT);
695

696 697 698 699
	[CCode (cname = "MIN")]
	public static int64 min (int64 a, int64 b);
	[CCode (cname = "MAX")]
	public static int64 max (int64 a, int64 b);
700 701
	[CCode (cname = "CLAMP")]
	public int64 clamp (int64 low, int64 high);
702
	[CCode (cname = "llabs", cheader_filename = "stdlib.h")]
703
	public int64 abs ();
704 705 706 707 708 709 710 711 712 713

	[CCode (cname = "GINT64_TO_BE")]
	public int64 to_big_endian ();
	[CCode (cname = "GINT64_TO_LE")]
	public int64 to_little_endian ();

	[CCode (cname = "GINT64_FROM_BE")]
	public static int64 from_big_endian (int64 val);
	[CCode (cname = "GINT64_FROM_LE")]
	public static int64 from_little_endian (int64 val);
714 715 716

	[CCode (cname = "GUINT64_SWAP_LE_BE")]
	public uint64 swap_little_endian_big_endian ();
717 718 719 720

	[CCode (cname = "g_ascii_strtoll")]
	static int64 ascii_strtoll (string nptr, out char* endptr, uint _base);

721
	[Version (since = "2.12")]
722 723 724
	public static int64 parse (string str) {
		return ascii_strtoll (str, null, 0);
	}
725 726

	[Version (since = "2.12")]
727
	public static bool try_parse (string str, out int64 result = null, out unowned string unparsed = null) {
728 729 730
		char* endptr;
		result = ascii_strtoll (str, out endptr, 0);
		if (endptr == (char*) str + str.length) {
731
			unparsed = "";
732 733
			return true;
		} else {
734
			unparsed = (string) endptr;
735 736 737
			return false;
		}
	}
738 739 740 741

	[CCode (cname = "g_ascii_string_to_signed")]
	[Version (since = "2.54")]
	public static bool from_string (string str, [CCode (pos = 5.1)] out int64 out_num = null, uint @base = 10U, int64 min = int64.MIN, int64 max = int64.MAX) throws GLib.NumberParserError;
742 743
}

744
[SimpleType]
745
[GIR (name = "guint64")]
746
[CCode (cname = "guint64", cheader_filename = "glib.h", type_id = "G_TYPE_UINT64", marshaller_type_name = "UINT64", get_value_function = "g_value_get_uint64", set_value_function = "g_value_set_uint64", default_value = "0ULL", type_signature = "t")]
747
[IntegerType (rank = 11)]
748
public struct uint64 {
749
	[CCode (cname = "0ULL")]
750
	public const uint64 MIN;
751
	[CCode (cname = "G_MAXUINT64")]
752
	public const uint64 MAX;
753

754 755 756 757 758
	[CCode (cname = "G_GUINT64_FORMAT")]
	public const string FORMAT;
	[CCode (cname = "G_GINT64_MODIFIER")]
	public const string FORMAT_MODIFIER;

759
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
760
	public string to_string (string format = "%" + FORMAT);
761

762 763 764 765
	[CCode (cname = "MIN")]
	public static uint64 min (uint64 a, uint64 b);
	[CCode (cname = "MAX")]
	public static uint64 max (uint64 a, uint64 b);
766 767
	[CCode (cname = "CLAMP")]
	public uint64 clamp (uint64 low, uint64 high);
768 769 770 771 772 773 774 775 776 777

	[CCode (cname = "GUINT64_TO_BE")]
	public uint64 to_big_endian ();
	[CCode (cname = "GUINT64_TO_LE")]
	public uint64 to_little_endian ();

	[CCode (cname = "GUINT64_FROM_BE")]
	public static uint64 from_big_endian (uint64 val);
	[CCode (cname = "GUINT64_FROM_LE")]
	public static uint64 from_little_endian (uint64 val);
778 779 780 781 782 783 784

	[CCode (cname = "g_ascii_strtoull")]
	static uint64 ascii_strtoull (string nptr, out char* endptr, uint _base);

	public static uint64 parse (string str) {
		return ascii_strtoull (str, null, 0);
	}
785

786
	public static bool try_parse (string str, out uint64 result = null, out unowned string unparsed = null) {
787 788 789
		char* endptr;
		result = ascii_strtoull (str, out endptr, 0);
		if (endptr == (char*) str + str.length) {
790
			unparsed = "";
791 792
			return true;
		} else {
793
			unparsed = (string) endptr;
794 795 796
			return false;
		}
	}
797 798 799 800

	[CCode (cname = "g_ascii_string_to_unsigned")]
	[Version (since = "2.54")]
	public static bool from_string (string str, [CCode (pos = 5.1)] out uint64 out_num = null, uint @base = 10U, uint64 min = uint64.MIN, uint64 max = uint64.MAX) throws GLib.NumberParserError;
801 802
}

803
[SimpleType]
804
[GIR (name = "gfloat")]
805
[CCode (cname = "gfloat", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_FLOAT", marshaller_type_name = "FLOAT", get_value_function = "g_value_get_float", set_value_function = "g_value_set_float", default_value = "0.0F", default_value_on_error = "-1.0F")]
806
[FloatingType (rank = 1)]
807
public struct float {
808
	[CCode (cname = "FLT_ROUNDS")]
809
	public const int ROUNDS;
810
	[CCode (cname = "FLT_RADIX")]
811
	public const int RADIX;
812
	[CCode (cname = "FLT_MANT_DIG")]
813
	public const int MANT_DIG;
814
	[CCode (cname = "FLT_DIG")]
815
	public const int DIG;
816 817

	[CCode (cname = "FLT_MIN_EXP")]
818
	public const int MIN_EXP;
819
	[CCode (cname = "FLT_MAX_EXP")]
820
	public const int MAX_EXP;
821 822

	[CCode (cname = "FLT_MIN_10_EXP")]
823
	public const int MIN_10_EXP;
824
	[CCode (cname = "FLT_MAX_10_EXP")]
825
	public const int MAX_10_EXP;
826 827

	[CCode (cname = "FLT_EPSILON")]
828
	public const float EPSILON;
829
	[CCode (cname = "FLT_MIN")]
830
	public const float MIN;
831
	[CCode (cname = "FLT_MAX")]
832
	public const float MAX;
833 834

	[CCode (cname = "NAN")]
835
	public const float NAN;
836
	[CCode (cname = "INFINITY")]
837
	public const float INFINITY;
838 839 840 841 842 843 844 845 846 847

	[CCode (cname = "isnan")]
	public bool is_nan ();
	[CCode (cname = "isfinite")]
	public bool is_finite ();
	[CCode (cname = "isnormal")]
	public bool is_normal ();
	[CCode (cname = "isinf")]
	public int is_infinity ();

848
	[CCode (cname = "g_strdup_printf", instance_pos = -1)]
849
	public string to_string (string format = "%g");
850

851 852 853 854
	[CCode (cname = "MIN")]
	public static float min (float a, float b);
	[CCode (cname = "MAX")]
	public static float max (float a, float b);
855 856
	[CCode (cname = "CLAMP")]
	public float clamp (float low, float high);
857 858
	[CCode (cname = "fabsf")]
	public float abs ();
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877

	[CCode (cname = "strtof", cheader_filename = "stdlib.h")]
	static float strtof (string nptr, out char* endptr);

	public static float parse (string str) {
		return strtof (str, null);
	}

	public static bool try_parse (string str, out float result = null, out unowned string unparsed = null) {
		char* endptr;
		result = strtof (str, out endptr);
		if (endptr == (char*) str + str.length) {
			unparsed = "";
			return true;
		} else {
			unparsed = (string) endptr;
			return false;
		}
	}
878 879
}

880
[SimpleType]
881
[GIR (name = "gdouble")]
882
[CCode (cname = "gdouble", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_DOUBLE", marshaller_type_name = "DOUBLE", get_value_function = "g_value_get_double", set_value_function = "g_value_set_double", default_value = "0.0", default_value_on_error = "-1.0", type_signature = "d")]
883
[FloatingType (rank = 2)]
884
public struct double {
885
	[CCode (cname = "DBL_MANT_DIG")]
886
	public const int MANT_DIG;
887
	[CCode (cname = "DBL_DIG")]
888
	public const int DIG;
889 890

	[CCode (cname = "DBL_MIN_EXP")]
891
	public const int MIN_EXP;
892
	[CCode (cname = "DBL_MAX_EXP")]
893
	public const int MAX_EXP;
894 895

	[CCode (cname = "DBL_MIN_10_EXP")]
896
	public const int MIN_10_EXP;
897
	[CCode (cname = "DBL_MAX_10_EXP")]
898
	public const int MAX_10_EXP;
899 900

	[CCode (cname = "DBL_EPSILON")]
901
	public const double EPSILON;
902
	[CCode (cname = "DBL_MIN")]
903
	public const double MIN;
904
	[CCode (cname = "DBL_MAX")]
905
	public const double MAX;
906 907

	[CCode (cname = "((double) NAN)")]
908
	public const double NAN;
909
	[CCode (cname = "((double) INFINITY)")]
910
	public const double INFINITY;
911 912 913 914 915 916 917 918 919 920

	[CCode (cname = "isnan")]
	public bool is_nan ();
	[CCode (cname = "isfinite")]
	public bool is_finite ();
	[CCode (cname = "isnormal")]
	public bool is_normal ();
	[CCode (cname = "isinf")]
	public int is_infinity ();

921 922 923 924
	[CCode (cname = "MIN")]
	public static double min (double a, double b);
	[CCode (cname = "MAX")]
	public static double max (double a, double b);
925 926
	[CCode (cname = "CLAMP")]
	public double clamp (double low, double high);
927 928
	[CCode (cname = "fabs")]
	public double abs ();
929 930 931 932

	[CCode (cname = "G_ASCII_DTOSTR_BUF_SIZE")]
	public const int DTOSTR_BUF_SIZE;
	[CCode (cname = "g_ascii_dtostr", instance_pos = -1)]
933
	public unowned string to_str (char[] buffer);
934
	[CCode (cname = "g_ascii_formatd", instance_pos = -1)]
935
	public unowned string format (char[] buffer, string format = "%g");
936 937 938 939

	public string to_string () {
		return this.to_str(new char[DTOSTR_BUF_SIZE]);
	}
940 941 942 943 944 945 946

	[CCode (cname = "g_ascii_strtod")]
	static double ascii_strtod (string nptr, out char* endptr);

	public static double parse (string str) {
		return ascii_strtod (str, null);
	}
947

948
	public static bool try_parse (string str, out double result = null, out unowned string unparsed = null) {
949 950 951
		char* endptr;
		result = ascii_strtod (str, out endptr);
		if (endptr == (char*) str + str.length) {
952
			unparsed = "";
953 954
			return true;
		} else {
955
			unparsed = (string) endptr;
956 957 958
			return false;
		}
	}
959 960
}

961
[GIR (name = "glong")]
962
[CCode (cheader_filename = "time.h", has_type_id = false, default_value = "0")]
963
[IntegerType (rank = 8)]
964 965
public struct time_t {
	[CCode (cname = "time")]
Jürg Billeter's avatar
Jürg Billeter committed
966
	public time_t (out time_t result = null);
967 968
}

Jürg Billeter's avatar
Jürg Billeter committed
969
[SimpleType]
970
[CCode (cheader_filename="stdarg.h", cprefix="va_", has_type_id = false, destroy_function = "va_end", lvalue_access = false)]
Jürg Billeter's avatar
Jürg Billeter committed
971 972 973 974 975
public struct va_list {
	[CCode (cname = "va_start")]
	public va_list ();
	[CCode (cname = "va_copy")]
	public va_list.copy (va_list src);
976
	[CCode (generic_type_pos = 1.1, simple_generics = true)]
Jürg Billeter's avatar
Jürg Billeter committed
977 978 979
	public unowned G arg<G> ();
}

980
[SimpleType]
981
[GIR (name = "gunichar")]
982
[CCode (cname = "gunichar", cprefix = "g_unichar_", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
983
[IntegerType (rank = 7)]
984
public struct unichar {
985
	public bool validate ();
986
	public bool isalnum ();
987 988
	public bool isalpha ();
	public bool iscntrl ();
989
	public bool isdigit ();
990 991
	public bool isgraph ();
	public bool islower ();
992
	[Version (since = "2.14")]
993
	public bool ismark ();
994 995
	public bool isprint ();
	public bool ispunct ();
996
	public bool isspace ();
997
	public bool isupper ();
998
	public bool isxdigit ();
999 1000 1001
	public bool istitle ();
	public bool isdefined ();
	public bool iswide ();
1002
	[Version (since = "2.12")]
1003
	public bool iswide_cjk ();
1004
	[Version (since = "2.14")]
1005
	public bool iszerowidth ();
1006
	public unichar toupper ();
1007
	public unichar tolower ();
1008
	public unichar totitle ();
1009 1010
	public int digit_value ();
	public int xdigit_value ();
1011 1012
	public GLib.UnicodeType type ();
	public GLib.UnicodeBreakType break_type ();
1013
	[Version (since = "2.14")]
1014
	public GLib.UnicodeScript get_script();
1015

1016
	public int to_utf8 (string? outbuf);
1017

1018
	public string to_string () {
1019 1020 1021 1022 1023
		string str = (string) new char[7];
		this.to_utf8 (str);
		return str;
	}

1024
	[Version (since = "2.30")]
1025
	public bool compose (unichar b, out unichar ch);
1026
	[Version (since = "2.30")]
1027
	public bool decompose (out unichar a, out unichar b);
1028
	[Version (since = "2.30")]
1029 1030
	public size_t fully_decompose (bool compat, unichar[] result);

1031 1032 1033 1034
	[CCode (cname = "MIN")]
	public static unichar min (unichar a, unichar b);
	[CCode (cname = "MAX")]
	public static unichar max (unichar a, unichar b);
1035 1036
	[CCode (cname = "CLAMP")]
	public unichar clamp (unichar low, unichar high);
1037 1038 1039

	[CCode (cname = "G_UNICHAR_MAX_DECOMPOSITION_LENGTH")]
	public const int MAX_DECOMPOSITION_LENGTH;
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055

	[CCode (cname = "G_GUINT32_FORMAT")]
	public const string FORMAT;
	[CCode (cname = "G_GINT32_MODIFIER")]
	public const string FORMAT_MODIFIER;
}

[SimpleType]
[GIR (name = "guint16")]
[CCode (cname = "gunichar2", cheader_filename = "glib.h", default_value = "0U", type_signature = "q", has_type_id = false)]
[IntegerType (rank = 5)]
public struct unichar2 {
	[CCode (cname = "G_GUINT16_FORMAT")]
	public const string FORMAT;
	[CCode (cname = "G_GINT16_MODIFIER")]
	public const string FORMAT_MODIFIER;
1056 1057
}

1058
[Compact]
1059
[Immutable]
1060
[GIR (name = "utf8")]
1061
[CCode (cname = "gchar", const_cname = "const gchar", copy_function = "g_strdup", free_function = "g_free", cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING", param_spec_function = "g_param_spec_string", get_value_function = "g_value_get_string", set_value_function = "g_value_set_string", take_value_function = "g_value_take_string", type_signature = "s")]
1062
public class string {
1063
	[Version (replacement = "string.index_of")]
1064
	[CCode (cname = "strstr")]
1065
	public unowned string? str (string needle);
1066
	[Version (replacement = "string.last_index_of")]
1067 1068 1069 1070
	[CCode (cname = "g_strrstr")]
	public unowned string? rstr (string needle);
	[CCode (cname = "g_strrstr_len")]
	public unowned string? rstr_len (ssize_t haystack_len, string needle);
1071 1072 1073

	[CCode (cname = "strstr")]
	static char* strstr (char* haystack, char* needle);
1074 1075
	[CCode (cname = "g_strrstr")]
	static char* strrstr (char* haystack, char* needle);
1076 1077
	[CCode (cname = "g_utf8_strchr")]
	static char* utf8_strchr (char* str, ssize_t len, unichar c);
1078 1079
	[CCode (cname = "g_utf8_strrchr")]
	static char* utf8_strrchr (char* str, ssize_t len, unichar c);
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090

	public int index_of (string needle, int start_index = 0) {
		char* result = strstr ((char*) this + start_index, (char*) needle);

		if (result != null) {
			return (int) (result - (char*) this);
		} else {
			return -1;
		}
	}

1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
	public int last_index_of (string needle, int start_index = 0) {
		char* result = strrstr ((char*) this + start_index, (char*) needle);

		if (result != null) {
			return (int) (result - (char*) this);
		} else {
			return -1;
		}
	}

1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
	public int index_of_char (unichar c, int start_index = 0) {
		char* result = utf8_strchr ((char*) this + start_index, -1, c);

		if (result != null) {
			return (int) (result - (char*) this);
		} else {
			return -1;
		}
	}

1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
	public int last_index_of_char (unichar c, int start_index = 0) {
		char* result = utf8_strrchr ((char*) this + start_index, -1, c);

		if (result != null) {
			return (int) (result - (char*) this);
		} else {
			return -1;
		}
	}

1121
	[Version (since = "2.2")]
1122
	[CCode (cname = "g_str_has_prefix")]
1123
	public bool has_prefix (string prefix);
1124
	[Version (since = "2.2")]
1125
	[CCode (cname = "g_str_has_suffix")]
1126
	public bool has_suffix (string suffix);
1127
	[CCode (cname = "g_strdup_printf"), PrintfFormat]
1128
	public string printf (...);
1129 1130
	[CCode (cname = "g_strdup_vprintf")]
	public string vprintf (va_list args);
1131
	[CCode (cname = "sscanf", cheader_filename = "stdio.h"), ScanfFormat]
1132
	public int scanf (string format, ...);
1133
	[CCode (cname = "g_strconcat")]
1134
	public string concat (string string2, ...);
1135
	[CCode (cname = "g_strescape")]
1136
	public string escape (string? exceptions = null);
1137
	[CCode (cname = "g_strcompress")]
1138
	public string compress ();
1139
	[CCode (cname = "g_strsplit", array_length = false, array_null_terminated = true)]
1140
	public string[] split (string delimiter, int max_tokens = 0);
1141
	[Version (since = "2.4")]
1142
	[CCode (cname = "g_strsplit_set", array_length = false, array_null_terminated = true)]
1143
	public string[] split_set (string delimiters, int max_tokens = 0);
1144 1145 1146
	[CCode (cname = "g_stpcpy")]
	private static void* copy_to_buffer (void* dest, string src);
	[CCode (cname = "_vala_g_strjoinv")]
1147
	public static string joinv (string? separator, string?[]? str_array) {
1148 1149 1150
		if (separator == null) {
			separator = "";
		}
1151
		if (str_array != null && (str_array.length > 0 || (str_array.length == -1 && str_array[0] != null))) {
1152 1153 1154
			int i;
			size_t len = 1;
			for (i = 0 ; (str_array.length != -1 && i < str_array.length) || (str_array.length == -1 && str_array[i] != null) ; i++) {
1155
				len += (str_array[i] != null) ? ((!) str_array[i]).length : 0;
1156
			}
1157 1158 1159 1160
			if (i == 0) {
				return "";
			}
			str_array.length = i;
1161
			len += ((!) separator).length * (i - 1);
1162 1163

			string* res = GLib.malloc (len);
1164
			void* ptr = string.copy_to_buffer ((void*) res, (!) str_array[0]);
1165
			for (i = 1 ; i < str_array.length ; i++) {
1166 1167
				ptr = string.copy_to_buffer (ptr, (!) separator);
				ptr = string.copy_to_buffer (ptr, (str_array[i] != null) ? ((!) str_array[i]) : "");
1168 1169 1170 1171 1172 1173 1174
			}

			return (owned) res;
		} else {
			return "";
		}
	}
1175 1176
	[CCode (cname = "g_strjoin")]
	public static string join (string separator, ...);
Jürg Billeter's avatar
Jürg Billeter committed
1177
	[CCode (cname = "g_strnfill")]
1178
	public static string nfill (size_t length, char fill_char);
Jürg Billeter's avatar
Jürg Billeter committed
1179

1180 1181 1182 1183
	public char get (long index) {
		return ((char*) this)[index];
	}

1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
	// checks whether valid string character starts at specified index
	// embedded NULs are not supported by the string class
	public bool valid_char (int index) {
		uint8 c = ((uint8*) this)[index];
		if (c == 0x00 || (c >= 0x80 && c < 0xc2) || c >= 0xf5) {
			return false;
		} else {
			return true;
		}
	}

1195
	[CCode (cname = "g_utf8_next_char")]
1196
	public unowned string next_char ();
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
	[CCode (cname = "g_utf8_next_char")]
	static char* utf8_next_char (char* str);
	public bool get_next_char (ref int index, out unichar c) {
		c = utf8_get_char ((char*) this + index);
		if (c != 0) {
			index = (int) (utf8_next_char ((char*) this + index) - (char*) this);
			return true;
		} else {
			return false;
		}
	}
1208
	[CCode (cname = "g_utf8_get_char")]
1209
	static unichar utf8_get_char (char* str);
1210
	public unichar get_char (long index = 0) {
1211 1212
		return utf8_get_char ((char*) this + index);
	}
1213
	[CCode (cname = "g_utf8_get_char_validated")]
1214
	public unichar get_char_validated (ssize_t max_len = -1);
1215

1216
	[Version (replacement = "string.index_of_nth_char")]
1217 1218
	[CCode (cname = "g_utf8_offset_to_pointer")]
	public unowned string utf8_offset (long offset);
1219 1220 1221
	public unowned string offset (long offset) {
		return (string) ((char*) this + offset);
	}
1222
	[Version (replacement = "string.char_count")]
1223 1224 1225
	public long pointer_to_offset (string pos) {
		return (long) ((char*) pos - (char*) this);
	}
1226 1227 1228 1229 1230 1231 1232 1233

	[CCode (cname = "g_utf8_offset_to_pointer")]
	char* utf8_offset_to_pointer (long offset);

	public int index_of_nth_char (long c) {
		return (int) (this.utf8_offset_to_pointer (c) - (char*) this);
	}

1234
	[CCode (cname = "g_utf8_prev_char")]
1235
	public unowned string prev_char ();
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
	[CCode (cname = "g_utf8_prev_char")]
	static char* utf8_prev_char (char* str);
	public bool get_prev_char (ref int index, out unichar c) {
		if (0 < index) {
			index = (int) (utf8_prev_char ((char*) this + index) - (char*) this);
			c = utf8_get_char ((char*) this + index);
			return true;
		} else {
			c = 0;
			return false;
		}
	}

1249
	[Version (replacement = "string.length")]
1250 1251
	[CCode (cname = "strlen")]
	public long len ();
1252
	[Version (replacement = "string.index_of_char")]
1253
	[CCode (cname = "g_utf8_strchr")]
1254
	public unowned string chr (ssize_t len, unichar c);
1255
	[Version (replacement = "string.last_index_of_char")]
1256
	[CCode (cname = "g_utf8_strrchr")]
1257
	public unowned string rchr (ssize_t len, unichar c);
1258
	[Version (since = "2.2")]
1259
	[CCode (cname = "g_utf8_strreverse")]
1260
	public string reverse (ssize_t len = -1);
1261
	[CCode (cname = "g_utf8_validate")]