On Sun, 23 Jul 2006 20:03:59 +0100 Paul LeoNerd Evans <leonerd-gtk leonerd org uk> wrote: > A while ago I submitted some patches to add some extra GString > functions: Oops. Find attached a patch against latest CVS source -- Paul "LeoNerd" Evans leonerd leonerd org uk ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/
diff -u -r1.150 glib-sections.txt
--- docs/reference/glib/glib-sections.txt 2 Jun 2006 02:55:50 -0000 1.150
+++ docs/reference/glib/glib-sections.txt 23 Jul 2006 19:08:15 -0000
@@ -1871,13 +1871,19 @@
<FILE>strings</FILE>
GString
g_string_new
+g_string_clone
g_string_new_len
g_string_sized_new
+g_string_new_printf
+g_string_new_vprintf
+g_string_slice
g_string_assign
g_string_sprintf
g_string_sprintfa
g_string_printf
+g_string_vprintf
g_string_append_printf
+g_string_append_vprintf
g_string_append
g_string_append_c
g_string_append_unichar
diff -u -r1.49 gstring.c
--- glib/gstring.c 5 Dec 2005 15:38:52 -0000 1.49
+++ glib/gstring.c 23 Jul 2006 19:08:16 -0000
@@ -297,6 +297,26 @@
return string;
}
+/**
+ * g_string_clone:
+ * @orig: a #GString object to copy
+ *
+ * Creates a new #GString, initialised to contain the same data as @orig. If
+ * @orig is %NULL then no new string is allocated and %NULL is returned
+ * instead.
+ *
+ * Return value: a new #GString or %NULL
+ */
+
+GString*
+g_string_clone (const GString *orig)
+{
+ if (orig)
+ return g_string_new(orig->str);
+ else
+ return NULL;
+}
+
GString*
g_string_new_len (const gchar *init,
gssize len)
@@ -316,6 +336,49 @@
}
}
+/**
+ * g_string_new_printf:
+ * @format: the string format. See the %printf() documentation.
+ * @...: the parameters to insert into the format string.
+ *
+ * Allocates a new #GString object and fills the buffer with the printed
+ * string.
+ *
+ * Return value: a new #GString
+ */
+GString*
+g_string_new_printf(const gchar *format,
+ ...)
+{
+ va_list args;
+ GString *string;
+
+ va_start (args, format);
+ string = g_string_new_vprintf (format, args);
+ va_end (args);
+
+ return string;
+}
+
+/**
+ * g_string_new_vprintf:
+ * @format: the string format. See the %printf() documentation.
+ * @args: the list of parameters to insert into the format string.
+ *
+ * Allocates a new #GString object and fills the buffer with the printed
+ * string.
+ *
+ * Return value: a new #GString
+ */
+GString*
+g_string_new_vprintf(const gchar *format,
+ va_list args)
+{
+ GString *string = g_string_new (NULL);
+ g_string_append_vprintf (string, format, args);
+ return string;
+}
+
gchar*
g_string_free (GString *string,
gboolean free_segment)
@@ -900,6 +963,44 @@
g_free (buffer);
}
+/**
+ * g_string_append_vprintf:
+ * @string: a #GString.
+ * @format: the string format. See the %printf() documentation.
+ * @args: the list of parameters to insert into the format string.
+ *
+ * Appends a formatted string onto the end of a #GString. This function is
+ * similar to #g_string_vprintf() except that the text is appended to the
+ * #GString
+ */
+void
+g_string_append_vprintf (GString *string,
+ const gchar *format,
+ va_list args)
+{
+ g_string_append_printf_internal (string, format, args);
+}
+
+/**
+ * g_string_vprintf:
+ * @string: a #GString.
+ * @format: the string format. See the %printf() documentation.
+ * @args: the list of parameters to insert into the format string.
+ *
+ * Writes a formatted string into a #GString. This is similar to the standard
+ * %vsprintf() function, except that the #GString buffer automatically expands
+ * to contain the results. The previous contents of the #GString are
+ * destroyed.
+ */
+void
+g_string_vprintf (GString *string,
+ const gchar *format,
+ va_list args)
+{
+ g_string_truncate (string, 0);
+ g_string_append_printf_internal (string, format, args);
+}
+
void
g_string_printf (GString *string,
const gchar *fmt,
@@ -924,6 +1025,38 @@
va_start (args, fmt);
g_string_append_printf_internal (string, fmt, args);
va_end (args);
+}
+
+/**
+ * g_string_slice:
+ * @string: a #GString.
+ * @pos: The zero-based index of the start of the section to copy
+ * @len: The number of bytes to copy
+ *
+ * Creates a new #GString by taking a slice of the given string. The slice
+ * will begin at the @pos character, and contain at most @len bytes. The
+ * returned string will be nul-terminated.
+ *
+ * Return value: a new #GString
+ */
+
+GString*
+g_string_slice (GString* string,
+ guint pos,
+ guint len)
+{
+ GString *ret = g_string_new("");
+
+ if (pos > string->len || len < 1)
+ return ret;
+
+ if (pos + len > string->len)
+ len = string->len - pos;
+
+ g_string_append_len (ret, string->str + pos, len);
+ g_string_append_c (ret, '\0');
+
+ return ret;
}
#define __G_STRING_C__
diff -u -r1.15 gstring.h
--- glib/gstring.h 2 Dec 2004 01:06:17 -0000 1.15
+++ glib/gstring.h 23 Jul 2006 19:08:16 -0000
@@ -59,9 +59,14 @@
/* Strings
*/
GString* g_string_new (const gchar *init);
+GString* g_string_clone (const GString *orig);
GString* g_string_new_len (const gchar *init,
gssize len);
GString* g_string_sized_new (gsize dfl_size);
+GString* g_string_new_printf (const gchar *format,
+ ...) G_GNUC_PRINTF (1, 2);
+GString* g_string_new_vprintf (const gchar *format,
+ va_list args);
gchar* g_string_free (GString *string,
gboolean free_segment);
gboolean g_string_equal (const GString *v,
@@ -112,9 +117,18 @@
void g_string_printf (GString *string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
+void g_string_vprintf (GString *string,
+ const gchar *format,
+ va_list args);
void g_string_append_printf (GString *string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
+void g_string_append_vprintf (GString *string,
+ const gchar *format,
+ va_list args);
+GString* g_string_slice (GString *string,
+ guint pos,
+ guint len);
/* -- optimize g_strig_append_c --- */
#ifdef G_CAN_INLINE
Attachment:
signature.asc
Description: PGP signature