New function, to insert possible non-nul-terminated byte sequences into a

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.
This commit is contained in:
Matthias Clasen 2003-03-31 22:08:08 +00:00 committed by Matthias Clasen
parent 6710fd6e06
commit e4112b8b1b
10 changed files with 109 additions and 21 deletions

View File

@ -1,3 +1,11 @@
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

View File

@ -1,3 +1,11 @@
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

View File

@ -1,3 +1,11 @@
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

View File

@ -1,3 +1,11 @@
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

View File

@ -1,3 +1,11 @@
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

View File

@ -1,3 +1,11 @@
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

View File

@ -1,3 +1,7 @@
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.

View File

@ -1554,6 +1554,7 @@ GStringChunk
g_string_chunk_new
g_string_chunk_insert
g_string_chunk_insert_const
g_string_chunk_insert_len
g_string_chunk_free
</SECTION>

View File

@ -146,29 +146,9 @@ gchar*
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*
@ -193,6 +173,58 @@ g_string_chunk_insert_const (GStringChunk *chunk,
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

View File

@ -48,6 +48,9 @@ GStringChunk* g_string_chunk_new (gsize size);
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);