diff options
author | Milan Crha <mcrha@redhat.com> | 2008-06-23 21:49:31 +0800 |
---|---|---|
committer | Milan Crha <mcrha@src.gnome.org> | 2008-06-23 21:49:31 +0800 |
commit | b99bf8e323e53a5aa5e6ea6761427095799261e9 (patch) | |
tree | 2ef16c49125e39ccf99e3aec002eda907660d468 | |
parent | 1fe8e825d48cf2ba5bf11374ce7c4a95f0b6e4eb (diff) | |
download | gsoc2013-evolution-b99bf8e323e53a5aa5e6ea6761427095799261e9.tar.gz gsoc2013-evolution-b99bf8e323e53a5aa5e6ea6761427095799261e9.tar.zst gsoc2013-evolution-b99bf8e323e53a5aa5e6ea6761427095799261e9.zip |
** Fix for bug #440818 (patch by Rodrigo Castro)
2008-06-23 Milan Crha <mcrha@redhat.com>
** Fix for bug #440818 (patch by Rodrigo Castro)
* importers/evolution-csv-importer.c: (parseLine): Convert line
to UTF-8 if not a valid one. Pretend it to be an ISO-8859-1 line.
* importers/evolution-csv-importer.c: (getNextCSVEntry):
Append char-by-char and check for EOF too.
svn path=/trunk/; revision=35677
-rw-r--r-- | addressbook/ChangeLog | 9 | ||||
-rw-r--r-- | addressbook/importers/evolution-csv-importer.c | 44 |
2 files changed, 34 insertions, 19 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 58c8e9631a..e7e0e06fa8 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,12 @@ +2008-06-23 Milan Crha <mcrha@redhat.com> + + ** Fix for bug #440818 (patch by Rodrigo Castro) + + * importers/evolution-csv-importer.c: (parseLine): Convert line + to UTF-8 if not a valid one. Pretend it to be an ISO-8859-1 line. + * importers/evolution-csv-importer.c: (getNextCSVEntry): + Append char-by-char and check for EOF too. + 2008-06-13 Tor Lillqvist <tml@novell.com> * gui/component/Makefile.am (libevolution_addressbook_la_LIBADD): diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c index 9b6df77f7c..d29b1419f0 100644 --- a/addressbook/importers/evolution-csv-importer.c +++ b/addressbook/importers/evolution-csv-importer.c @@ -343,22 +343,28 @@ parseLine (CSVImporter *gci, EContact *contact, char **buf) { other_address = g_new0(EContactAddress, 1); bday = g_new0(EContactDate, 1); + if (!g_utf8_validate (ptr, -1, NULL)) + ptr = g_convert (ptr, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); + while(*ptr != '\n') { value = g_string_new(""); while(*ptr != delimiter) { if(*ptr == '\n') break; if(*ptr != '"') { - g_string_append_unichar(value, *ptr); + g_string_append_unichar (value, g_utf8_get_char (ptr)); } else { - ptr++; - while (*ptr != '"') { - g_string_append_unichar(value, *ptr); - ptr++; + ptr = g_utf8_next_char (ptr); + while (*ptr && *ptr != '"') { + g_string_append_unichar (value, g_utf8_get_char (ptr)); + ptr = g_utf8_next_char (ptr); } + + if (!*ptr) + break; } - ptr++; + ptr = g_utf8_next_char (ptr); } if(importer == OUTLOOK_IMPORTER) { contact_field = csv_fields_outlook[i].contact_field; @@ -481,7 +487,7 @@ parseLine (CSVImporter *gci, EContact *contact, char **buf) { i++; g_string_free(value, TRUE); if(*ptr != '\n') - ptr++; + ptr = g_utf8_next_char (ptr); } if(strlen(home_street->str) != 0) home_address->street = g_strdup(home_street->str); @@ -536,20 +542,20 @@ getNextCSVEntry(CSVImporter *gci, FILE *f) { if (c == EOF) return NULL; if (c == '\n') { - g_string_append_unichar(line, c); + g_string_append_c (line, c); break ; } if (c == '"') { - g_string_append_unichar(line, c); + g_string_append_c (line, c); c = fgetc (f); - while (c != '"') { - g_string_append_unichar(line, c); + while (!feof (f) && c != '"') { + g_string_append_c (line, c); c = fgetc (f); } - g_string_append_unichar(line, c); + g_string_append_c (line, c); } else - g_string_append_unichar(line, c); + g_string_append_c (line, c); } if(gci->count == 0 && importer != MOZILLA_IMPORTER) { @@ -560,20 +566,20 @@ getNextCSVEntry(CSVImporter *gci, FILE *f) { if (c == EOF) return NULL; if (c == '\n') { - g_string_append_unichar(line, c); + g_string_append_c (line, c); break ; } if (c == '"') { - g_string_append_unichar(line, c); + g_string_append_c (line, c); c = fgetc (f); - while (c != '"') { - g_string_append_unichar(line, c); + while (!feof (f) && c != '"') { + g_string_append_c (line, c); c = fgetc (f); } - g_string_append_unichar(line, c); + g_string_append_c (line, c); } else - g_string_append_unichar(line, c); + g_string_append_c (line, c); } gci->count ++; } |