[vala] glib-2.0: Add string.splice method
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] glib-2.0: Add string.splice method
- Date: Sat, 19 Dec 2009 09:38:23 +0000 (UTC)
commit 1f718e4f1455b62a61b79fd701975e6c4b48522b
Author: Jürg Billeter <j bitron ch>
Date: Sat Dec 19 10:35:40 2009 +0100
glib-2.0: Add string.splice method
vapi/glib-2.0.vapi | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index ed4d9e9..3adad3f 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -984,6 +984,42 @@ public class string {
return start_string.ndup (((char*) start_string.offset (end - start)) - ((char*) start_string));
}
+ public string splice (long start, long end, string? str = null) {
+ long string_length = this.len ();
+ if (start < 0) {
+ start = string_length + start;
+ }
+ if (end < 0) {
+ end = string_length + end;
+ }
+ GLib.return_val_if_fail (start >= 0 && start <= string_length, null);
+ GLib.return_val_if_fail (end >= 0 && end <= string_length, null);
+ GLib.return_val_if_fail (start <= end, null);
+
+ unowned string start_string = this.offset (start);
+ unowned string end_string = start_string.offset (end - start);
+ size_t str_size;
+ if (str == null) {
+ str_size = 0;
+ } else {
+ str_size = str.size ();
+ }
+
+ string* result = GLib.malloc0 (this.size () - ((char*) end_string - (char*) start_string) + str_size + 1);
+
+ char* dest = result;
+
+ GLib.Memory.copy (dest, this, (char*) start_string - (char*) this);
+ dest += (char*) start_string - (char*) this;
+
+ GLib.Memory.copy (dest, str, str_size);
+ dest += str_size;
+
+ GLib.Memory.copy (dest, end_string, end_string.size ());
+
+ return (owned) result;
+ }
+
public bool contains (string needle) {
return this.str (needle) != null;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]