Don't allow end index to go below start index when extracting the region.
authorHans Petter Jansson <hpj@ximian.com>
Fri, 6 Feb 2004 22:08:29 +0000 (22:08 +0000)
committerHans Petter <hansp@src.gnome.org>
Fri, 6 Feb 2004 22:08:29 +0000 (22:08 +0000)
2004-02-06  Hans Petter Jansson  <hpj@ximian.com>

* libebook/e-address-western.c (e_address_western_extract_region):
Don't allow end index to go below start index when extracting the
region. Also handle the case where there is no whitespace after comma
more gracefully.

addressbook/ChangeLog
addressbook/libebook/e-address-western.c

index 4ef1a63..1babb77 100644 (file)
@@ -1,3 +1,10 @@
+2004-02-06  Hans Petter Jansson  <hpj@ximian.com>
+
+       * libebook/e-address-western.c (e_address_western_extract_region):
+       Don't allow end index to go below start index when extracting the
+       region. Also handle the case where there is no whitespace after comma
+       more gracefully.
+
 2004-02-06  Chris Toshok  <toshok@ximian.com>
 
        * libebook/e-book.c (e_book_activate): if bonobo hasn't been
index b477278..62ecddf 100644 (file)
@@ -223,7 +223,7 @@ e_address_western_extract_locality (gchar *line)
 static gchar *
 e_address_western_extract_region (gchar *line)
 {
-       gint start, end;
+       gint start, end, alt_end;
 
        start = strcspn (line, ",");
        start++;
@@ -234,6 +234,8 @@ e_address_western_extract_region (gchar *line)
        while (isspace (line[end]))
                end--;
 
+       alt_end = end;
+
        while (!isspace (line[end]))
                end--;
 
@@ -241,6 +243,11 @@ e_address_western_extract_region (gchar *line)
                end--;
        end++;
 
+       if (end <= start)
+               end = alt_end;
+       if (end <= start)
+               return g_strdup ("");
+
        /* Between start and end lie the string. */
        return g_strndup ( (line+start), end-start);
 }