Added g_string_insert[_c]() and g_string_erase().

Sun Mar  1 19:04:40 1998  Owen Taylor  <owt1@cornell.edu>

	* glib.h gstring.c: Added g_string_insert[_c]()
	  and g_string_erase().

	  From: Stefan Wille  <1wille@vsys1.informatik.uni-hamburg.de>
This commit is contained in:
Owen Taylor 1998-03-02 00:07:40 +00:00 committed by Owen Taylor
parent d1f5f06082
commit 80fd0a0c00
3 changed files with 74 additions and 0 deletions

View File

@ -1,3 +1,10 @@
Sun Mar 1 19:04:40 1998 Owen Taylor <owt1@cornell.edu>
* glib.h gstring.c: Added g_string_insert[_c]()
and g_string_erase().
From: Stefan Wille <1wille@vsys1.informatik.uni-hamburg.de>
Mon Feb 16 23:05:06 1998 Owen Taylor <owt1@cornell.edu> Mon Feb 16 23:05:06 1998 Owen Taylor <owt1@cornell.edu>
* glist.c (g_list_insert_sorted): Changed function * glist.c (g_list_insert_sorted): Changed function

View File

@ -715,6 +715,15 @@ GString* g_string_prepend (GString *string,
gchar *val); gchar *val);
GString* g_string_prepend_c (GString *string, GString* g_string_prepend_c (GString *string,
gchar c); gchar c);
GString* g_string_insert (GString *fstring,
gint pos,
gchar *val);
GString* g_string_insert_c (GString *fstring,
gint pos,
gchar c);
GString* g_string_erase (GString *fstring,
gint pos,
gint len);
void g_string_sprintf (GString *string, void g_string_sprintf (GString *string,
gchar *fmt, gchar *fmt,
...); ...);

View File

@ -314,6 +314,64 @@ g_string_prepend_c (GString *fstring, char c)
return fstring; return fstring;
} }
GString *
g_string_insert (GString *fstring, gint pos, gchar *val)
{
GRealString *string = (GRealString*)fstring;
gint len = strlen (val);
g_return_val_if_fail (pos <= string->len, fstring);
g_string_maybe_expand (string, len);
g_memmove (string->str + pos + len, string->str + pos, string->len);
strncpy (string->str + pos, val, len);
string->len += len;
string->str[string->len] = 0;
return fstring;
}
GString *
g_string_insert_c (GString *fstring, gint pos, gchar c)
{
GRealString *string = (GRealString*)fstring;
g_return_val_if_fail (pos <= string->len, fstring);
g_string_maybe_expand (string, 1);
g_memmove (string->str + pos + 1, string->str + pos, string->len);
string->str[pos] = c;
string->len += 1;
string->str[string->len] = 0;
return fstring;
}
GString *
g_string_erase (GString *fstring, gint pos, gint len)
{
GRealString *string = (GRealString*)fstring;
g_return_val_if_fail (pos <= string->len, fstring);
g_return_val_if_fail (pos + len <= string->len, fstring);
g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
string->len -= len;
string->str[string->len] = 0;
return fstring;
}
static int static int
get_length_upper_bound (const gchar* fmt, va_list *args) get_length_upper_bound (const gchar* fmt, va_list *args)
{ {