+2003-04-01 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gstring.[hc] (g_string_chunk_insert_len): New function, to
+ insert possible non-nul-terminated byte sequences into a string
+ chunk. (#96279)
+ (g_string_chunk_insert): Implement in terms of
+ g_string_chunk_insert_len() now.
+
2003-03-30 Matthias Clasen <maclas@gmx.de>
* glib/gstring.c (g_string_new): Optimize the common cases
+2003-04-01 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gstring.[hc] (g_string_chunk_insert_len): New function, to
+ insert possible non-nul-terminated byte sequences into a string
+ chunk. (#96279)
+ (g_string_chunk_insert): Implement in terms of
+ g_string_chunk_insert_len() now.
+
2003-03-30 Matthias Clasen <maclas@gmx.de>
* glib/gstring.c (g_string_new): Optimize the common cases
+2003-04-01 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gstring.[hc] (g_string_chunk_insert_len): New function, to
+ insert possible non-nul-terminated byte sequences into a string
+ chunk. (#96279)
+ (g_string_chunk_insert): Implement in terms of
+ g_string_chunk_insert_len() now.
+
2003-03-30 Matthias Clasen <maclas@gmx.de>
* glib/gstring.c (g_string_new): Optimize the common cases
+2003-04-01 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gstring.[hc] (g_string_chunk_insert_len): New function, to
+ insert possible non-nul-terminated byte sequences into a string
+ chunk. (#96279)
+ (g_string_chunk_insert): Implement in terms of
+ g_string_chunk_insert_len() now.
+
2003-03-30 Matthias Clasen <maclas@gmx.de>
* glib/gstring.c (g_string_new): Optimize the common cases
+2003-04-01 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gstring.[hc] (g_string_chunk_insert_len): New function, to
+ insert possible non-nul-terminated byte sequences into a string
+ chunk. (#96279)
+ (g_string_chunk_insert): Implement in terms of
+ g_string_chunk_insert_len() now.
+
2003-03-30 Matthias Clasen <maclas@gmx.de>
* glib/gstring.c (g_string_new): Optimize the common cases
+2003-04-01 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gstring.[hc] (g_string_chunk_insert_len): New function, to
+ insert possible non-nul-terminated byte sequences into a string
+ chunk. (#96279)
+ (g_string_chunk_insert): Implement in terms of
+ g_string_chunk_insert_len() now.
+
2003-03-30 Matthias Clasen <maclas@gmx.de>
* glib/gstring.c (g_string_new): Optimize the common cases
+2003-04-01 Matthias Clasen <maclas@gmx.de>
+
+ * glib/glib-sections.txt: Add g_string_chunk_insert_len.
+
2003-03-28 Matthias Clasen <maclas@gmx.de>
* gobject/tmpl/param_value_types.sgml: Additions.
g_string_chunk_new
g_string_chunk_insert
g_string_chunk_insert_const
+g_string_chunk_insert_len
g_string_chunk_free
</SECTION>
g_string_chunk_insert (GStringChunk *chunk,
const gchar *string)
{
- gsize len = strlen (string);
- char* pos;
-
g_return_val_if_fail (chunk != NULL, NULL);
- if ((chunk->storage_next + len + 1) > chunk->this_size)
- {
- gsize new_size = nearest_power (chunk->default_size, len + 1);
-
- chunk->storage_list = g_slist_prepend (chunk->storage_list,
- g_new (char, new_size));
-
- chunk->this_size = new_size;
- chunk->storage_next = 0;
- }
-
- pos = ((char *) chunk->storage_list->data) + chunk->storage_next;
-
- strcpy (pos, string);
-
- chunk->storage_next += len + 1;
-
- return pos;
+ return g_string_chunk_insert_len (chunk, string, -1);
}
gchar*
return lookup;
}
+/**
+ * g_string_chunk_insert_len:
+ * @chunk: a #GStringChunk
+ * @string: bytes to insert
+ * @len: number of bytes of @string to insert, or -1 to insert a
+ * nul-terminated string.
+ *
+ * Adds a copy of the first @len bytes of @string to the #GStringChunk. The
+ * copy is nul-terminated.
+ *
+ * The characters in the string can be changed, if necessary, though you
+ * should not change anything after the end of the string.
+ *
+ * Return value: a pointer to the copy of @string within the #GStringChunk
+ *
+ * Since: 2.4
+ **/
+gchar*
+g_string_chunk_insert_len (GStringChunk *chunk,
+ const gchar *string,
+ gssize len)
+{
+ gchar* pos;
+
+ g_return_val_if_fail (chunk != NULL, NULL);
+
+ if (len < 0)
+ len = strlen (string);
+
+ if ((chunk->storage_next + len + 1) > chunk->this_size)
+ {
+ gsize new_size = nearest_power (chunk->default_size, len + 1);
+
+ chunk->storage_list = g_slist_prepend (chunk->storage_list,
+ g_new (gchar, new_size));
+
+ chunk->this_size = new_size;
+ chunk->storage_next = 0;
+ }
+
+ pos = ((gchar *) chunk->storage_list->data) + chunk->storage_next;
+
+ *(pos + len) = '\0';
+
+ strncpy (pos, string, len);
+ len = strlen (pos);
+
+ chunk->storage_next += len + 1;
+
+ return pos;
+}
+
/* Strings.
*/
static void
void g_string_chunk_free (GStringChunk *chunk);
gchar* g_string_chunk_insert (GStringChunk *chunk,
const gchar *string);
+gchar* g_string_chunk_insert_len (GStringChunk *chunk,
+ const gchar *string,
+ gssize len);
gchar* g_string_chunk_insert_const (GStringChunk *chunk,
const gchar *string);