Revision 1616
| libsylph/utils.c (revision 1616) | ||
|---|---|---|
| 1020 | 1020 |
last = g_list_last(list); |
| 1021 | 1021 |
if (last) {
|
| 1022 | 1022 |
g_free(last->data); |
| 1023 |
g_list_remove(list, last->data); |
|
| 1023 |
list = g_list_remove(list, last->data);
|
|
| 1024 | 1024 |
} |
| 1025 | 1025 |
} |
| 1026 | 1026 |
|
| ... | ... | |
| 1355 | 1355 |
str_array = g_new(gchar*, n); |
| 1356 | 1356 |
|
| 1357 | 1357 |
i = n - 1; |
| 1358 |
|
|
| 1359 | 1358 |
str_array[i--] = NULL; |
| 1360 | 1359 |
for (slist = string_list; slist; slist = slist->next) |
| 1361 | 1360 |
str_array[i--] = slist->data; |
| ... | ... | |
| 1415 | 1414 |
str_array = g_new(gchar*, n); |
| 1416 | 1415 |
|
| 1417 | 1416 |
i = n - 1; |
| 1417 |
str_array[i--] = NULL; |
|
| 1418 |
for (slist = string_list; slist; slist = slist->next) |
|
| 1419 |
str_array[i--] = slist->data; |
|
| 1418 | 1420 |
|
| 1421 |
g_slist_free(string_list); |
|
| 1422 |
|
|
| 1423 |
return str_array; |
|
| 1424 |
} |
|
| 1425 |
|
|
| 1426 |
gchar **strsplit_csv(const gchar *str, gchar delim, gint max_tokens) |
|
| 1427 |
{
|
|
| 1428 |
GSList *string_list = NULL, *slist; |
|
| 1429 |
gchar **str_array, *s, *new_str; |
|
| 1430 |
gchar *tmp, *tmpp, *p; |
|
| 1431 |
guint i, n = 1, len; |
|
| 1432 |
|
|
| 1433 |
g_return_val_if_fail(str != NULL, NULL); |
|
| 1434 |
|
|
| 1435 |
if (max_tokens < 1) |
|
| 1436 |
max_tokens = G_MAXINT; |
|
| 1437 |
|
|
| 1438 |
s = strchr_with_skip_quote(str, '"', delim); |
|
| 1439 |
if (s) {
|
|
| 1440 |
do {
|
|
| 1441 |
len = s - str; |
|
| 1442 |
tmpp = tmp = g_strndup(str, len); |
|
| 1443 |
|
|
| 1444 |
if (tmp[0] == '"' && tmp[len - 1] == tmp[0]) {
|
|
| 1445 |
tmp[len - 1] = '\0'; |
|
| 1446 |
++tmpp; |
|
| 1447 |
p = new_str = g_malloc(len - 1); |
|
| 1448 |
while (*tmpp) {
|
|
| 1449 |
if (*tmpp == '"' && *(tmpp + 1) == '"') |
|
| 1450 |
++tmpp; |
|
| 1451 |
*p++ = *tmpp++; |
|
| 1452 |
} |
|
| 1453 |
*p = '\0'; |
|
| 1454 |
g_free(tmp); |
|
| 1455 |
} else |
|
| 1456 |
new_str = tmp; |
|
| 1457 |
|
|
| 1458 |
string_list = g_slist_prepend(string_list, new_str); |
|
| 1459 |
n++; |
|
| 1460 |
str = s + 1; |
|
| 1461 |
s = strchr_with_skip_quote(str, '"', delim); |
|
| 1462 |
} while (--max_tokens && s); |
|
| 1463 |
} |
|
| 1464 |
|
|
| 1465 |
if (*str) {
|
|
| 1466 |
len = strlen(str); |
|
| 1467 |
tmpp = tmp = g_strdup(str); |
|
| 1468 |
|
|
| 1469 |
if (tmp[0] == '"' && tmp[len - 1] == tmp[0]) {
|
|
| 1470 |
tmp[len - 1] = '\0'; |
|
| 1471 |
++tmpp; |
|
| 1472 |
p = new_str = g_malloc(len - 1); |
|
| 1473 |
while (*tmpp) {
|
|
| 1474 |
if (*tmpp == '"' && *(tmpp + 1) == '"') |
|
| 1475 |
++tmpp; |
|
| 1476 |
*p++ = *tmpp++; |
|
| 1477 |
} |
|
| 1478 |
*p = '\0'; |
|
| 1479 |
g_free(tmp); |
|
| 1480 |
} else |
|
| 1481 |
new_str = tmp; |
|
| 1482 |
|
|
| 1483 |
string_list = g_slist_prepend(string_list, new_str); |
|
| 1484 |
n++; |
|
| 1485 |
} |
|
| 1486 |
|
|
| 1487 |
str_array = g_new(gchar*, n); |
|
| 1488 |
|
|
| 1489 |
i = n - 1; |
|
| 1419 | 1490 |
str_array[i--] = NULL; |
| 1420 | 1491 |
for (slist = string_list; slist; slist = slist->next) |
| 1421 | 1492 |
str_array[i--] = slist->data; |
| libsylph/utils.h (revision 1616) | ||
|---|---|---|
| 337 | 337 |
gchar **strsplit_with_quote (const gchar *str, |
| 338 | 338 |
const gchar *delim, |
| 339 | 339 |
gint max_tokens); |
| 340 |
gchar **strsplit_csv (const gchar *str, |
|
| 341 |
gchar delim, |
|
| 342 |
gint max_tokens); |
|
| 340 | 343 |
|
| 341 | 344 |
gchar *get_abbrev_newsgroup_name (const gchar *group, |
| 342 | 345 |
gint len); |
| src/importcsv.c (revision 1616) | ||
|---|---|---|
| 207 | 207 |
str = g_strdup(buf); |
| 208 | 208 |
else |
| 209 | 209 |
str = conv_localetodisp(buf, NULL); |
| 210 |
strv = g_strsplit(str, ",", 0);
|
|
| 210 |
strv = strsplit_csv(str, ',', 0);
|
|
| 211 | 211 |
fields_len = sizeof(imp_csv_attrib) / sizeof(imp_csv_attrib[0]); |
| 212 | 212 |
while (strv[data_len]) |
| 213 | 213 |
++data_len; |
| ... | ... | |
| 381 | 381 |
str = g_strdup(buf); |
| 382 | 382 |
else |
| 383 | 383 |
str = conv_localetodisp(buf, NULL); |
| 384 |
strv = g_strsplit(str, ",", 0);
|
|
| 384 |
strv = strsplit_csv(str, ',', 0);
|
|
| 385 | 385 |
while (strv[cols]) |
| 386 | 386 |
++cols; |
| 387 | 387 |
|
| ChangeLog.ja (revision 1616) | ||
|---|---|---|
| 1 | 1 |
2007-04-11 |
| 2 | 2 |
|
| 3 |
* libsylph/utils.[ch]: strsplit_csv(): ?ɲá? |
|
| 4 |
* src/importcsv.c: ???֥륯???????դ??? CSV ??Ŭ?ڤ˽????????褦?? |
|
| 5 |
?????? |
|
| 6 |
|
|
| 7 |
2007-04-11 |
|
| 8 |
|
|
| 3 | 9 |
* src/addressbook.c: ?????ݡ??Ȥθ??ե????????ԤåȤ????褦?ˤ????? |
| 4 | 10 |
|
| 5 | 11 |
2007-04-11 |
| ChangeLog (revision 1616) | ||
|---|---|---|
| 1 | 1 |
2007-04-11 |
| 2 | 2 |
|
| 3 |
* libsylph/utils.[ch]: strsplit_csv(): added. |
|
| 4 |
* src/importcsv.c: properly process CSV with double quotations. |
|
| 5 |
|
|
| 6 |
2007-04-11 |
|
| 7 |
|
|
| 3 | 8 |
* src/addressbook.c: set focus row after import. |
| 4 | 9 |
|
| 5 | 10 |
2007-04-11 |
Also available in: Unified diff