mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-02 00:51:14 +00:00
libgimpconfig: gimp_config_(de)serialize_strv() should not be public.
These 2 functions are only used in one file each, there are absolutely zero reasons to make them public. These functions have nothing special.
This commit is contained in:
parent
32034901d2
commit
f965b659eb
6 changed files with 130 additions and 210 deletions
|
@ -1,149 +0,0 @@
|
|||
/* LIBGIMP - The GIMP Library
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
|
||||
*
|
||||
* 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
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cairo.h>
|
||||
#include <gegl.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#include "gimpconfigtypes.h"
|
||||
|
||||
#include "gimpconfig-utils.h"
|
||||
#include "gimpconfig-array.h"
|
||||
#include "gimpscanner.h"
|
||||
|
||||
|
||||
/* GStrv i.e. char** i.e. null terminated array of strings. */
|
||||
|
||||
/**
|
||||
* gimp_config_serialize_strv:
|
||||
* @value: source #GValue holding a #GStrv
|
||||
* @str: destination string
|
||||
*
|
||||
* Appends a string repr of the #GStrv value of #GValue to @str.
|
||||
* Repr is an integer literal greater than or equal to zero,
|
||||
* followed by a possibly empty sequence
|
||||
* of quoted and escaped string literals.
|
||||
*
|
||||
* Returns: %TRUE always
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
gboolean
|
||||
gimp_config_serialize_strv (const GValue *value,
|
||||
GString *str)
|
||||
{
|
||||
GStrv gstrv;
|
||||
|
||||
gstrv = g_value_get_boxed (value);
|
||||
|
||||
if (gstrv)
|
||||
{
|
||||
gint length = g_strv_length (gstrv);
|
||||
|
||||
/* Write length */
|
||||
g_string_append_printf (str, "%d", length);
|
||||
|
||||
for (gint i = 0; i < length; i++)
|
||||
{
|
||||
g_string_append (str, " "); /* separator */
|
||||
gimp_config_string_append_escaped (str, gstrv[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* GValue has NULL value. Not quite the same as an empty GStrv.
|
||||
* But handle it quietly as an empty GStrv: write a length of zero.
|
||||
*/
|
||||
g_string_append (str, "0");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_config_deserialize_strv:
|
||||
* @value: destination #GValue to hold a #GStrv
|
||||
* @scanner: #GScanner positioned in serialization stream
|
||||
*
|
||||
* Sets @value to new #GStrv.
|
||||
* Scans i.e. consumes serialization to fill the GStrv.
|
||||
*
|
||||
* Requires @value to be initialized to hold type #G_TYPE_BOXED.
|
||||
*
|
||||
* Returns:
|
||||
* G_TOKEN_RIGHT_PAREN on success.
|
||||
* G_TOKEN_INT on failure to scan length.
|
||||
* G_TOKEN_STRING on failure to scan enough quoted strings.
|
||||
*
|
||||
* On failure, the value in @value is not touched and could be NULL.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
GTokenType
|
||||
gimp_config_deserialize_strv (GValue *value,
|
||||
GScanner *scanner)
|
||||
{
|
||||
gint n_values;
|
||||
GTokenType result_token = G_TOKEN_RIGHT_PAREN;
|
||||
GStrvBuilder *builder;
|
||||
|
||||
/* Scan length of array. */
|
||||
if (! gimp_scanner_parse_int (scanner, &n_values))
|
||||
return G_TOKEN_INT;
|
||||
|
||||
builder = g_strv_builder_new ();
|
||||
|
||||
for (gint i = 0; i < n_values; i++)
|
||||
{
|
||||
gchar *scanned_string;
|
||||
|
||||
if (! gimp_scanner_parse_string (scanner, &scanned_string))
|
||||
{
|
||||
/* Error, missing a string. */
|
||||
result_token = G_TOKEN_STRING;
|
||||
break;
|
||||
}
|
||||
|
||||
g_strv_builder_add (builder, scanned_string ? scanned_string : "");
|
||||
g_free (scanned_string);
|
||||
}
|
||||
|
||||
/* assert result_token is G_TOKEN_RIGHT_PAREN OR G_TOKEN_STRING */
|
||||
if (result_token == G_TOKEN_RIGHT_PAREN)
|
||||
{
|
||||
GStrv gstrv;
|
||||
|
||||
/* Allocate new GStrv. */
|
||||
gstrv = g_strv_builder_end (builder);
|
||||
/* Transfer ownership of the array and all strings it points to. */
|
||||
g_value_take_boxed (value, gstrv);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No GStrv to unref. */
|
||||
g_scanner_error (scanner, "Missing string.");
|
||||
}
|
||||
|
||||
g_strv_builder_unref (builder);
|
||||
|
||||
return result_token;
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/* LIBGIMP - The GIMP Library
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpconfig-array.h
|
||||
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
|
||||
*
|
||||
* 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
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if !defined (__GIMP_CONFIG_H_INSIDE__) && !defined (GIMP_CONFIG_COMPILATION)
|
||||
#error "Only <libgimpconfig/gimpconfig.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __GIMP_CONFIG_ARRAY_H__
|
||||
#define __GIMP_CONFIG_ARRAY_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* For information look into the C source or the html documentation */
|
||||
|
||||
/* Functions to ser/des arrays. */
|
||||
|
||||
/* FIXME: move gimp_config_serialize_value_array here.
|
||||
* FIXME: implement other arrays for which plugins can declare args e.g. int32 array.
|
||||
* FIXME: doesn't need to be introspected, these are internal
|
||||
*/
|
||||
|
||||
gboolean gimp_config_serialize_strv (const GValue *value,
|
||||
GString *str);
|
||||
GTokenType gimp_config_deserialize_strv (GValue *value,
|
||||
GScanner *scanner);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GIMP_CONFIG_ARRAY_H__ */
|
|
@ -32,7 +32,6 @@
|
|||
#include "gimpconfigtypes.h"
|
||||
|
||||
#include "gimpconfigwriter.h"
|
||||
#include "gimpconfig-array.h"
|
||||
#include "gimpconfig-iface.h"
|
||||
#include "gimpconfig-deserialize.h"
|
||||
#include "gimpconfig-params.h"
|
||||
|
@ -86,6 +85,8 @@ static GTokenType gimp_config_deserialize_value_array (GValue *value,
|
|||
GimpConfig *config,
|
||||
GParamSpec *prop_spec,
|
||||
GScanner *scanner);
|
||||
static GTokenType gimp_config_deserialize_strv (GValue *value,
|
||||
GScanner *scanner);
|
||||
static GimpUnit * gimp_config_get_unit_from_identifier (const gchar *identifier);
|
||||
static GTokenType gimp_config_deserialize_unit (GValue *value,
|
||||
GParamSpec *prop_spec,
|
||||
|
@ -856,6 +857,75 @@ gimp_config_deserialize_value_array (GValue *value,
|
|||
return G_TOKEN_RIGHT_PAREN;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_config_deserialize_strv:
|
||||
* @value: destination #GValue to hold a #GStrv
|
||||
* @scanner: #GScanner positioned in serialization stream
|
||||
*
|
||||
* Sets @value to new #GStrv.
|
||||
* Scans i.e. consumes serialization to fill the GStrv.
|
||||
*
|
||||
* Requires @value to be initialized to hold type #G_TYPE_BOXED.
|
||||
*
|
||||
* Returns:
|
||||
* G_TOKEN_RIGHT_PAREN on success.
|
||||
* G_TOKEN_INT on failure to scan length.
|
||||
* G_TOKEN_STRING on failure to scan enough quoted strings.
|
||||
*
|
||||
* On failure, the value in @value is not touched and could be NULL.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
static GTokenType
|
||||
gimp_config_deserialize_strv (GValue *value,
|
||||
GScanner *scanner)
|
||||
{
|
||||
gint n_values;
|
||||
GTokenType result_token = G_TOKEN_RIGHT_PAREN;
|
||||
GStrvBuilder *builder;
|
||||
|
||||
/* Scan length of array. */
|
||||
if (! gimp_scanner_parse_int (scanner, &n_values))
|
||||
return G_TOKEN_INT;
|
||||
|
||||
builder = g_strv_builder_new ();
|
||||
|
||||
for (gint i = 0; i < n_values; i++)
|
||||
{
|
||||
gchar *scanned_string;
|
||||
|
||||
if (! gimp_scanner_parse_string (scanner, &scanned_string))
|
||||
{
|
||||
/* Error, missing a string. */
|
||||
result_token = G_TOKEN_STRING;
|
||||
break;
|
||||
}
|
||||
|
||||
g_strv_builder_add (builder, scanned_string ? scanned_string : "");
|
||||
g_free (scanned_string);
|
||||
}
|
||||
|
||||
/* assert result_token is G_TOKEN_RIGHT_PAREN OR G_TOKEN_STRING */
|
||||
if (result_token == G_TOKEN_RIGHT_PAREN)
|
||||
{
|
||||
GStrv gstrv;
|
||||
|
||||
/* Allocate new GStrv. */
|
||||
gstrv = g_strv_builder_end (builder);
|
||||
/* Transfer ownership of the array and all strings it points to. */
|
||||
g_value_take_boxed (value, gstrv);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No GStrv to unref. */
|
||||
g_scanner_error (scanner, "Missing string.");
|
||||
}
|
||||
|
||||
g_strv_builder_unref (builder);
|
||||
|
||||
return result_token;
|
||||
}
|
||||
|
||||
static GimpUnit *
|
||||
gimp_config_get_unit_from_identifier (const gchar *identifier)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include "gimpconfigtypes.h"
|
||||
|
||||
#include "gimpconfigwriter.h"
|
||||
#include "gimpconfig-array.h"
|
||||
#include "gimpconfig-iface.h"
|
||||
#include "gimpconfig-params.h"
|
||||
#include "gimpconfig-path.h"
|
||||
|
@ -49,6 +48,10 @@
|
|||
**/
|
||||
|
||||
|
||||
static gboolean gimp_config_serialize_strv (const GValue *value,
|
||||
GString *str);
|
||||
|
||||
|
||||
/**
|
||||
* gimp_config_serialize_properties:
|
||||
* @config: a #GimpConfig.
|
||||
|
@ -425,14 +428,7 @@ gimp_config_serialize_property (GimpConfig *config,
|
|||
{
|
||||
GString *str = g_string_new (NULL);
|
||||
|
||||
if (G_VALUE_TYPE (&value) == G_TYPE_STRV)
|
||||
{
|
||||
success = gimp_config_serialize_strv (&value, str);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = gimp_config_serialize_value (&value, str, TRUE);
|
||||
}
|
||||
success = gimp_config_serialize_value (&value, str, TRUE);
|
||||
|
||||
if (success)
|
||||
{
|
||||
|
@ -511,6 +507,11 @@ gimp_config_serialize_value (const GValue *value,
|
|||
GString *str,
|
||||
gboolean escaped)
|
||||
{
|
||||
if (G_VALUE_TYPE (value) == G_TYPE_STRV)
|
||||
{
|
||||
return gimp_config_serialize_strv (value, str);
|
||||
}
|
||||
|
||||
if (G_VALUE_HOLDS_BOOLEAN (value))
|
||||
{
|
||||
gboolean bool;
|
||||
|
@ -679,3 +680,52 @@ gimp_config_serialize_value (const GValue *value,
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* Private functions */
|
||||
|
||||
/**
|
||||
* gimp_config_serialize_strv:
|
||||
* @value: source #GValue holding a #GStrv
|
||||
* @str: destination string
|
||||
*
|
||||
* Appends a string repr of the #GStrv value of #GValue to @str.
|
||||
* Repr is an integer literal greater than or equal to zero,
|
||||
* followed by a possibly empty sequence
|
||||
* of quoted and escaped string literals.
|
||||
*
|
||||
* Returns: %TRUE always
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
static gboolean
|
||||
gimp_config_serialize_strv (const GValue *value,
|
||||
GString *str)
|
||||
{
|
||||
GStrv gstrv;
|
||||
|
||||
gstrv = g_value_get_boxed (value);
|
||||
|
||||
if (gstrv)
|
||||
{
|
||||
gint length = g_strv_length (gstrv);
|
||||
|
||||
/* Write length */
|
||||
g_string_append_printf (str, "%d", length);
|
||||
|
||||
for (gint i = 0; i < length; i++)
|
||||
{
|
||||
g_string_append (str, " "); /* separator */
|
||||
gimp_config_string_append_escaped (str, gstrv[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* GValue has NULL value. Not quite the same as an empty GStrv.
|
||||
* But handle it quietly as an empty GStrv: write a length of zero.
|
||||
*/
|
||||
g_string_append (str, "0");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ EXPORTS
|
|||
gimp_config_deserialize_return
|
||||
gimp_config_deserialize_stream
|
||||
gimp_config_deserialize_string
|
||||
gimp_config_deserialize_strv
|
||||
gimp_config_diff
|
||||
gimp_config_duplicate
|
||||
gimp_config_error_quark
|
||||
|
@ -49,7 +48,6 @@ EXPORTS
|
|||
gimp_config_serialize_properties
|
||||
gimp_config_serialize_property
|
||||
gimp_config_serialize_property_by_name
|
||||
gimp_config_serialize_strv
|
||||
gimp_config_serialize_to_fd
|
||||
gimp_config_serialize_to_file
|
||||
gimp_config_serialize_to_parasite
|
||||
|
|
|
@ -21,7 +21,6 @@ stamp_config_enums = custom_target('stamp-gimpconfigenums.h',
|
|||
|
||||
libgimpconfig_sources_introspectable = files(
|
||||
'gimpcolorconfig.c',
|
||||
'gimpconfig-array.c',
|
||||
'gimpconfig-deserialize.c',
|
||||
'gimpconfig-error.c',
|
||||
'gimpconfig-iface.c',
|
||||
|
@ -43,7 +42,6 @@ libgimpconfig_sources = [
|
|||
|
||||
libgimpconfig_headers_introspectable = files(
|
||||
'gimpcolorconfig.h',
|
||||
'gimpconfig-array.h',
|
||||
'gimpconfig-deserialize.h',
|
||||
'gimpconfig-error.h',
|
||||
'gimpconfig-iface.h',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue