mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-21 16:38:54 +02:00
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:
committed by
Matthias Clasen
parent
6710fd6e06
commit
e4112b8b1b
@@ -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>
|
2003-03-30 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
* glib/gstring.c (g_string_new): Optimize the common cases
|
* glib/gstring.c (g_string_new): Optimize the common cases
|
||||||
|
@@ -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>
|
2003-03-30 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
* glib/gstring.c (g_string_new): Optimize the common cases
|
* glib/gstring.c (g_string_new): Optimize the common cases
|
||||||
|
@@ -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>
|
2003-03-30 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
* glib/gstring.c (g_string_new): Optimize the common cases
|
* glib/gstring.c (g_string_new): Optimize the common cases
|
||||||
|
@@ -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>
|
2003-03-30 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
* glib/gstring.c (g_string_new): Optimize the common cases
|
* glib/gstring.c (g_string_new): Optimize the common cases
|
||||||
|
@@ -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>
|
2003-03-30 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
* glib/gstring.c (g_string_new): Optimize the common cases
|
* glib/gstring.c (g_string_new): Optimize the common cases
|
||||||
|
@@ -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>
|
2003-03-30 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
* glib/gstring.c (g_string_new): Optimize the common cases
|
* glib/gstring.c (g_string_new): Optimize the common cases
|
||||||
|
@@ -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>
|
2003-03-28 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
* gobject/tmpl/param_value_types.sgml: Additions.
|
* gobject/tmpl/param_value_types.sgml: Additions.
|
||||||
|
@@ -1554,6 +1554,7 @@ GStringChunk
|
|||||||
g_string_chunk_new
|
g_string_chunk_new
|
||||||
g_string_chunk_insert
|
g_string_chunk_insert
|
||||||
g_string_chunk_insert_const
|
g_string_chunk_insert_const
|
||||||
|
g_string_chunk_insert_len
|
||||||
g_string_chunk_free
|
g_string_chunk_free
|
||||||
|
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
@@ -146,29 +146,9 @@ gchar*
|
|||||||
g_string_chunk_insert (GStringChunk *chunk,
|
g_string_chunk_insert (GStringChunk *chunk,
|
||||||
const gchar *string)
|
const gchar *string)
|
||||||
{
|
{
|
||||||
gsize len = strlen (string);
|
|
||||||
char* pos;
|
|
||||||
|
|
||||||
g_return_val_if_fail (chunk != NULL, NULL);
|
g_return_val_if_fail (chunk != NULL, NULL);
|
||||||
|
|
||||||
if ((chunk->storage_next + len + 1) > chunk->this_size)
|
return g_string_chunk_insert_len (chunk, string, -1);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
@@ -193,6 +173,58 @@ g_string_chunk_insert_const (GStringChunk *chunk,
|
|||||||
return lookup;
|
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.
|
/* Strings.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
|
@@ -48,6 +48,9 @@ GStringChunk* g_string_chunk_new (gsize size);
|
|||||||
void g_string_chunk_free (GStringChunk *chunk);
|
void g_string_chunk_free (GStringChunk *chunk);
|
||||||
gchar* g_string_chunk_insert (GStringChunk *chunk,
|
gchar* g_string_chunk_insert (GStringChunk *chunk,
|
||||||
const gchar *string);
|
const gchar *string);
|
||||||
|
gchar* g_string_chunk_insert_len (GStringChunk *chunk,
|
||||||
|
const gchar *string,
|
||||||
|
gssize len);
|
||||||
gchar* g_string_chunk_insert_const (GStringChunk *chunk,
|
gchar* g_string_chunk_insert_const (GStringChunk *chunk,
|
||||||
const gchar *string);
|
const gchar *string);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user