[Xfce4-commits] <postler:master> Use substring, not slice because it eats a character

Christian Dywan noreply at xfce.org
Thu Jul 14 02:02:06 CEST 2011


Updating branch refs/heads/master
         to bf3c57aadde78d8b52fef2a4811ab7604a7adc8e (commit)
       from a18f0c63b92e573a0620e049ac07e2b062e54c62 (commit)

commit bf3c57aadde78d8b52fef2a4811ab7604a7adc8e
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed Jul 13 21:42:36 2011 +0200

    Use substring, not slice because it eats a character
    
    So slice and substring are almost identical except slice
    interprets -1 as 'one character before the last'.

 postler/postler-bureau.vala |    2 +-
 postler/postler-client.vala |    1 +
 postler/postler-index.vala  |    7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 1c2df7f..294bcc2 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -185,7 +185,7 @@ public class Postler.Bureau : Gtk.Window {
     }
 
     void search_apply () {
-        if (search.get_text () == search.hint_string || search.get_text () == "") {
+        if (search.get_text () == search.hint_string || search.get_text ().strip () == "") {
             search_options.hide ();
             folders.show ();
             var action = actions.get_action ("SearchSubject") as Gtk.RadioAction;
diff --git a/postler/postler-client.vala b/postler/postler-client.vala
index 59854d3..954a438 100644
--- a/postler/postler-client.vala
+++ b/postler/postler-client.vala
@@ -106,6 +106,7 @@ namespace Postler {
         public signal void got_message (Message message, int64 position);
 
         public async GLib.List<Message> get_messages (string uri) throws GLib.Error {
+            return_val_if_fail (uri != null, new GLib.List<Message> ());
             var messages = new GLib.List<Message> ();
             try {
                 string[] ids = yield client.get_messages (uri);
diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index c006ac5..d21817b 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -235,10 +235,13 @@ namespace Postler {
 
             /* file:// or search:field/value */
             if (folder.has_prefix ("search:")) {
-                string[] parts = folder.slice (7, -1).split ("/", 2);
+                string[] parts = folder.substring (7, -1).split ("/", 2);
                 if (parts[0] == null || parts[1] == null)
-                    throw new GLib.FileError.FAILED (_("Failed to list messages: %s"),
+                    throw new GLib.FileError.FAILED (_("Failed to search messages: %s"),
                                                      "parts[0] == null || parts[1] == null");
+                if (parts[1].strip () == "")
+                    throw new GLib.FileError.FAILED (_("Failed to search messages: %s"),
+                                                     "Empty string");
                 string field = parts[0];
                 if (field == "from")
                     field = "sender";



More information about the Xfce4-commits mailing list