]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Map given end == 0 for string.slice/splice() to string.length f844ad1c02fb5b17e923a7ba4e69cf2a7df96a14
authorwb9688 <36312-wb9688@users.noreply.gitlab.gnome.org>
Thu, 21 May 2020 08:52:01 +0000 (10:52 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 22 May 2020 22:41:11 +0000 (00:41 +0200)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/179

tests/basic-types/strings.vala
vapi/glib-2.0.vapi

index a4fcda4f7afca151dbcb3b4a0cfd2aab9c2027bc..7ae03ef974414699507eb2709dad15d652a56584 100644 (file)
@@ -70,6 +70,12 @@ void test_string_slice () {
 
        r = s.slice (-7, -5);
        assert (r == "my");
+
+       r = s.slice (-7, 0);
+       assert (r == "myworld");
+
+       r = s.slice (5, 0);
+       assert (r == "myworld");
 }
 
 void test_string_splice () {
@@ -89,6 +95,12 @@ void test_string_splice () {
 
        s = s.splice (-14, -5);
        assert (s == "helloworld");
+
+       s = s.splice (-5, 0, "wide");
+       assert (s == "hellowide");
+
+       s = s.splice (5, 0, "world");
+       assert (s == "helloworld");
 }
 
 void test_string_substring () {
index c3df0f7ec5fc4e681cb266f3511b869b2f1e5c00..4da3873b6c3162e65075b2fea0f34108386a8b12 100644 (file)
@@ -1484,6 +1484,8 @@ public class string {
                }
                if (end < 0) {
                        end = string_length + end;
+               } else if (end == 0) {
+                       end = string_length;
                }
                GLib.return_val_if_fail (start >= 0 && start <= string_length, null);
                GLib.return_val_if_fail (end >= 0 && end <= string_length, null);
@@ -1498,6 +1500,8 @@ public class string {
                }
                if (end < 0) {
                        end = string_length + end;
+               } else if (end == 0) {
+                       end = string_length;
                }
                GLib.return_val_if_fail (start >= 0 && start <= string_length, null);
                GLib.return_val_if_fail (end >= 0 && end <= string_length, null);