[goffice] go_string_replace: new function.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] go_string_replace: new function.
- Date: Thu, 1 Jul 2010 00:52:00 +0000 (UTC)
commit 75edb146e298a8ec53a7764bb5195d2b5064b2ce
Author: Morten Welinder <terra gnome org>
Date: Wed Jun 30 20:51:39 2010 -0400
go_string_replace: new function.
goffice/utils/go-glib-extras.c | 28 ++++++++++++++++++++++++++++
goffice/utils/go-glib-extras.h | 4 ++++
2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/goffice/utils/go-glib-extras.c b/goffice/utils/go-glib-extras.c
index c06f0d3..98add12 100644
--- a/goffice/utils/go-glib-extras.c
+++ b/goffice/utils/go-glib-extras.c
@@ -330,6 +330,34 @@ go_string_append_c_n (GString *target, char c, gsize n)
memset (target->str + len, c, n);
}
+void
+go_string_replace (GString *target,
+ gsize pos, gssize oldlen,
+ const char *txt, gssize newlen)
+{
+ gsize cplen;
+
+ g_return_if_fail (target != NULL);
+ g_return_if_fail (pos >= 0);
+ g_return_if_fail (pos < target->len);
+
+ if (oldlen < 0)
+ oldlen = target->len - pos;
+ if (newlen < 0)
+ newlen = strlen (txt);
+
+ cplen = MIN (oldlen, newlen);
+ memcpy (target->str + pos, txt, cplen);
+
+ pos += cplen;
+ oldlen -= cplen;
+ txt += cplen;
+ newlen -= cplen;
+
+ g_string_erase (target, pos, oldlen);
+ g_string_insert_len (target, pos, txt, newlen);
+}
+
/* ------------------------------------------------------------------------- */
/**
diff --git a/goffice/utils/go-glib-extras.h b/goffice/utils/go-glib-extras.h
index 2951f26..4733a5d 100644
--- a/goffice/utils/go-glib-extras.h
+++ b/goffice/utils/go-glib-extras.h
@@ -74,6 +74,10 @@ void go_strescape (GString *target, char const *str);
char const *go_strunescape (GString *target, char const *str);
void go_string_append_gstring (GString *target, const GString *src);
void go_string_append_c_n (GString *target, char c, gsize n);
+void go_string_replace (GString *target,
+ gsize pos, gssize oldlen,
+ const char *txt, gssize newlen);
+
char const *go_guess_encoding (char const *raw, gsize len,
char const *user_guess,
char **utf8_str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]