[gimp/metadata-browser] libgimpbase: add gimp_scanner_parse_boolean()
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] libgimpbase: add gimp_scanner_parse_boolean()
- Date: Wed, 12 Sep 2012 22:12:24 +0000 (UTC)
commit 6346881773f4dc7d25a5871bba27087cd9c372af
Author: Michael Natterer <mitch gimp org>
Date: Sat Nov 5 17:02:51 2011 +0100
libgimpbase: add gimp_scanner_parse_boolean()
and complete many api doc stubs.
libgimpconfig/gimpconfig.def | 1 +
libgimpconfig/gimpscanner.c | 111 +++++++++++++++++++++++++++++++-----------
libgimpconfig/gimpscanner.h | 2 +
3 files changed, 85 insertions(+), 29 deletions(-)
---
diff --git a/libgimpconfig/gimpconfig.def b/libgimpconfig/gimpconfig.def
index 1838154..fb3dfd1 100644
--- a/libgimpconfig/gimpconfig.def
+++ b/libgimpconfig/gimpconfig.def
@@ -54,6 +54,7 @@ EXPORTS
gimp_scanner_destroy
gimp_scanner_new_file
gimp_scanner_new_string
+ gimp_scanner_parse_boolean
gimp_scanner_parse_color
gimp_scanner_parse_data
gimp_scanner_parse_float
diff --git a/libgimpconfig/gimpscanner.c b/libgimpconfig/gimpscanner.c
index 2583ed9..228bbd7 100644
--- a/libgimpconfig/gimpscanner.c
+++ b/libgimpconfig/gimpscanner.c
@@ -172,7 +172,8 @@ gimp_scanner_new (const gchar *name,
/**
* gimp_scanner_destroy:
- * @scanner:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
*
* Since: GIMP 2.4
**/
@@ -196,10 +197,11 @@ gimp_scanner_destroy (GScanner *scanner)
/**
* gimp_scanner_parse_token:
- * @scanner:
- * @token:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @token: Return location for the parsed token
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
@@ -217,10 +219,11 @@ gimp_scanner_parse_token (GScanner *scanner,
/**
* gimp_scanner_parse_identifier:
- * @scanner:
- * @identifier:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @identifier: Return location for the parsed identifier
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
@@ -241,10 +244,11 @@ gimp_scanner_parse_identifier (GScanner *scanner,
/**
* gimp_scanner_parse_string:
- * @scanner:
- * @dest:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @dest: Return location for the parsed string
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
@@ -277,10 +281,11 @@ gimp_scanner_parse_string (GScanner *scanner,
/**
* gimp_scanner_parse_string_no_validate:
- * @scanner:
- * @dest:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @dest: Return location for the parsed string
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
@@ -303,11 +308,12 @@ gimp_scanner_parse_string_no_validate (GScanner *scanner,
/**
* gimp_scanner_parse_data:
- * @scanner:
- * @length:
- * @dest:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @length: Length of tha data to parse
+ * @dest: Return location for the parsed data
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
@@ -331,10 +337,11 @@ gimp_scanner_parse_data (GScanner *scanner,
/**
* gimp_scanner_parse_int:
- * @scanner:
- * @dest:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @dest: Return location for the parsed integer
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
@@ -365,10 +372,11 @@ gimp_scanner_parse_int (GScanner *scanner,
/**
* gimp_scanner_parse_float:
- * @scanner:
- * @dest:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @dest: Return location for the parsed float
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
@@ -386,6 +394,49 @@ gimp_scanner_parse_float (GScanner *scanner,
return TRUE;
}
+/**
+ * gimp_scanner_parse_boolean:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @dest: Return location for the parsed boolean
+ *
+ * Return value: %TRUE on success
+ *
+ * Since: GIMP 2.4
+ **/
+gboolean
+gimp_scanner_parse_boolean (GScanner *scanner,
+ gboolean *dest)
+{
+ if (g_scanner_peek_next_token (scanner) != G_TOKEN_IDENTIFIER)
+ return FALSE;
+
+ g_scanner_get_next_token (scanner);
+
+ if (! g_ascii_strcasecmp (scanner->value.v_identifier, "yes") ||
+ ! g_ascii_strcasecmp (scanner->value.v_identifier, "true"))
+ {
+ *dest = TRUE;
+ }
+ else if (! g_ascii_strcasecmp (scanner->value.v_identifier, "no") ||
+ ! g_ascii_strcasecmp (scanner->value.v_identifier, "false"))
+ {
+ *dest = FALSE;
+ }
+ else
+ {
+ g_scanner_error
+ (scanner,
+ /* please don't translate 'yes' and 'no' */
+ _("expected 'yes' or 'no' for boolean token, got '%s'"),
+ scanner->value.v_identifier);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
enum
{
COLOR_RGB = 1,
@@ -396,10 +447,11 @@ enum
/**
* gimp_scanner_parse_color:
- * @scanner:
- * @dest:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @dest: Pointer to a color to store the result
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
@@ -518,10 +570,11 @@ gimp_scanner_parse_color (GScanner *scanner,
/**
* gimp_scanner_parse_matrix2:
- * @scanner:
- * @dest:
+ * @scanner: A #GScanner created by gimp_scanner_new_file() or
+ * gimp_scanner_new_string()
+ * @dest: Pointer to a matrix to store the result
*
- * Return value:
+ * Return value: %TRUE on success
*
* Since: GIMP 2.4
**/
diff --git a/libgimpconfig/gimpscanner.h b/libgimpconfig/gimpscanner.h
index 8dc2690..c2824f0 100644
--- a/libgimpconfig/gimpscanner.h
+++ b/libgimpconfig/gimpscanner.h
@@ -50,6 +50,8 @@ gboolean gimp_scanner_parse_int (GScanner *scanner,
gint *dest);
gboolean gimp_scanner_parse_float (GScanner *scanner,
gdouble *dest);
+gboolean gimp_scanner_parse_boolean (GScanner *scanner,
+ gboolean *dest);
gboolean gimp_scanner_parse_color (GScanner *scanner,
GimpRGB *dest);
gboolean gimp_scanner_parse_matrix2 (GScanner *scanner,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]