aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
authorJesse Pavel <jpavel@src.gnome.org>2000-09-12 00:22:36 +0800
committerJesse Pavel <jpavel@src.gnome.org>2000-09-12 00:22:36 +0800
commit86c896a81ddc9c5a58a2ab329777238f153f556e (patch)
tree0ef43b315f86c3d30d152350026cc87fae636132 /addressbook
parent997adfef532fd5fbc98f867d5a09544e241b691f (diff)
downloadgsoc2013-evolution-86c896a81ddc9c5a58a2ab329777238f153f556e.tar
gsoc2013-evolution-86c896a81ddc9c5a58a2ab329777238f153f556e.tar.gz
gsoc2013-evolution-86c896a81ddc9c5a58a2ab329777238f153f556e.tar.bz2
gsoc2013-evolution-86c896a81ddc9c5a58a2ab329777238f153f556e.tar.lz
gsoc2013-evolution-86c896a81ddc9c5a58a2ab329777238f153f556e.tar.xz
gsoc2013-evolution-86c896a81ddc9c5a58a2ab329777238f153f556e.tar.zst
gsoc2013-evolution-86c896a81ddc9c5a58a2ab329777238f153f556e.zip
*** empty log message ***
svn path=/trunk/; revision=5324
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/ChangeLog5
-rw-r--r--addressbook/ename/e-address-western.c94
2 files changed, 90 insertions, 9 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index f888957b47..8cfbc5945a 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,8 @@
+2000-09-11 Jesse Pavel <jpavel@helixcode.com>
+
+ * ename/e-address-western.c: fixed certain address parsing
+ problems.
+
2000-09-11 Christopher James Lahey <clahey@helixcode.com>
* contact-editor/fulladdr.glade: Made this a bit better balanced.
diff --git a/addressbook/ename/e-address-western.c b/addressbook/ename/e-address-western.c
index 3e5d491b90..af1d112fd6 100644
--- a/addressbook/ename/e-address-western.c
+++ b/addressbook/ename/e-address-western.c
@@ -20,9 +20,43 @@
#else
#include <ename/e-address-western.h>
+#include <e-util/e-util.h>
#endif
+/* These are the keywords that will distinguish the start of an extended
+ address. */
+
+static char *extended_keywords[] = {
+ "apt", "apartment", "suite", NULL
+};
+
+
+static const gchar *
+e_address_western_strstrcase (const gchar *haystack, const gchar *needle)
+{
+ /* find the needle in the haystack neglecting case */
+ gchar *ptr;
+ guint len;
+
+ g_return_val_if_fail (haystack != NULL, NULL);
+ g_return_val_if_fail (needle != NULL, NULL);
+
+ len = strlen(needle);
+ if (len > strlen(haystack))
+ return NULL;
+
+ if (len == 0)
+ return (char *)haystack;
+
+ for (ptr = (char *)haystack; *(ptr + len - 1) != '\0'; ptr++)
+ if (!g_strncasecmp(ptr, needle, len))
+ return ptr;
+
+ return NULL;
+}
+
+
static gboolean
e_address_western_is_line_blank (gchar *line)
{
@@ -86,7 +120,7 @@ e_address_western_remove_blank_lines (gchar *lines[], gint *linecntr)
static gboolean
e_address_western_is_po_box (gchar *line)
{
- gboolean retval = FALSE;
+ gboolean retval;
/* In which phase of processing are we? */
enum State { FIRSTCHAR, SECONDCHAR, WHITESPACE } state;
@@ -185,7 +219,19 @@ e_address_western_is_postal (gchar *line)
static gchar *
e_address_western_extract_po_box (gchar *line)
{
- return g_strdup (line);
+ /* Return everything from the beginning of the line to
+ the end of the first word that contains a number. */
+
+ int index;
+
+ index = 0;
+ while (!isdigit(line[index]))
+ index++;
+
+ while (isgraph(line[index]))
+ index++;
+
+ return g_strndup (line, index);
}
static gchar *
@@ -251,6 +297,33 @@ e_address_western_extract_postal_code (gchar *line)
return g_strndup ( (line+start), end-start);
}
+
+
+void
+e_address_western_extract_street (gchar *line, gchar **street, gchar **extended)
+{
+ gchar *split = NULL;
+ gint cntr;
+
+ for (cntr = 0; extended_keywords[cntr] != NULL; cntr++) {
+ split = e_address_western_strstrcase (line, extended_keywords[cntr]);
+ if (split != NULL)
+ break;
+ }
+
+ if (split != NULL) {
+ *street = g_strndup (line, (split - line));
+ *extended = g_strdup (split);
+ }
+ else {
+ *street = g_strdup (line);
+ *extended = NULL;
+ }
+
+}
+
+
+
EAddressWestern *
e_address_western_parse (const gchar *in_address)
{
@@ -261,9 +334,7 @@ e_address_western_parse (const gchar *in_address)
gboolean found_po_box, found_postal;
EAddressWestern *eaw;
-#ifndef NO_WARNINGS
gint start, end; /* To be used to classify address lines. */
-#endif
if (in_address == NULL)
return NULL;
@@ -320,13 +391,17 @@ e_address_western_parse (const gchar *in_address)
for (cntr = 0; cntr < linecntr; cntr++) {
if (e_address_western_is_po_box (lines[cntr])) {
- eaw->po_box = e_address_western_extract_po_box (lines[cntr]);
+ if (eaw->po_box == NULL)
+ eaw->po_box = e_address_western_extract_po_box (lines[cntr]);
found_po_box = TRUE;
}
else if (e_address_western_is_postal (lines[cntr])) {
- eaw->locality = e_address_western_extract_locality (lines[cntr]);
- eaw->region = e_address_western_extract_region (lines[cntr]);
- eaw->postal_code = e_address_western_extract_postal_code (lines[cntr]);
+ if (eaw->locality == NULL)
+ eaw->locality = e_address_western_extract_locality (lines[cntr]);
+ if (eaw->region == NULL)
+ eaw->region = e_address_western_extract_region (lines[cntr]);
+ if (eaw->postal_code == NULL)
+ eaw->postal_code = e_address_western_extract_postal_code (lines[cntr]);
found_postal = TRUE;
}
else {
@@ -342,7 +417,8 @@ e_address_western_parse (const gchar *in_address)
}
else {
if (eaw->street == NULL) {
- eaw->street = g_strdup (lines[cntr]);
+ e_address_western_extract_street (lines[cntr], &eaw->street,
+ &eaw->extended );
}
else {
if (eaw->extended == NULL) {