diff options
| author | 2009-01-22 22:18:43 +0100 | |
|---|---|---|
| committer | 2009-01-22 22:18:43 +0100 | |
| commit | bfd57eb1cf738ed62e17941e855347772ce48ef2 (patch) | |
| tree | 45eda77468ff586bdd64fd6afcb5452cb0407bad /src/bplist.c | |
| parent | 8da4dac2e65778d1f562f4502c09b16590cfd8e1 (diff) | |
| download | libplist-bfd57eb1cf738ed62e17941e855347772ce48ef2.tar.gz libplist-bfd57eb1cf738ed62e17941e855347772ce48ef2.tar.bz2 | |
Add Unicode support.
Diffstat (limited to 'src/bplist.c')
| -rw-r--r-- | src/bplist.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/bplist.c b/src/bplist.c index fd0280c..67d7f72 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -21,7 +21,6 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | #include "plist.h" | 23 | #include "plist.h" |
| 24 | #include <wchar.h> | ||
| 25 | #include <stdlib.h> | 24 | #include <stdlib.h> |
| 26 | #include <stdio.h> | 25 | #include <stdio.h> |
| 27 | #include <string.h> | 26 | #include <string.h> |
| @@ -152,7 +151,7 @@ static plist_t parse_date_node(char *bnode, uint8_t size) | |||
| 152 | return node; | 151 | return node; |
| 153 | } | 152 | } |
| 154 | 153 | ||
| 155 | static plist_t parse_string_node(char *bnode, uint8_t size) | 154 | static plist_t parse_string_node(char *bnode, uint64_t size) |
| 156 | { | 155 | { |
| 157 | plist_data_t data = plist_new_plist_data(); | 156 | plist_data_t data = plist_new_plist_data(); |
| 158 | 157 | ||
| @@ -165,16 +164,17 @@ static plist_t parse_string_node(char *bnode, uint8_t size) | |||
| 165 | return g_node_new(data); | 164 | return g_node_new(data); |
| 166 | } | 165 | } |
| 167 | 166 | ||
| 168 | static plist_t parse_unicode_node(char *bnode, uint8_t size) | 167 | static plist_t parse_unicode_node(char *bnode, uint64_t size) |
| 169 | { | 168 | { |
| 170 | plist_data_t data = plist_new_plist_data(); | 169 | plist_data_t data = plist_new_plist_data(); |
| 171 | 170 | uint64_t i = 0; | |
| 172 | data->type = PLIST_UNICODE; | 171 | data->type = PLIST_UNICODE; |
| 173 | data->unicodeval = (wchar_t *) malloc(sizeof(wchar_t) * (size + 1)); | 172 | data->unicodeval = (gunichar2 *) malloc(sizeof(gunichar2) * (size + 1)); |
| 174 | memcpy(data->unicodeval, bnode, size); | 173 | memcpy(data->unicodeval, bnode, sizeof(gunichar2) * size); |
| 175 | data->unicodeval[size] = '\0'; | 174 | data->unicodeval[sizeof(gunichar2) * size] = '\0'; |
| 176 | data->length = wcslen(data->unicodeval); | 175 | data->length = size; |
| 177 | 176 | for (i = 0; i <= size; i++) | |
| 177 | byte_convert(data->unicodeval + i, sizeof(gunichar2)); | ||
| 178 | return g_node_new(data); | 178 | return g_node_new(data); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| @@ -338,7 +338,8 @@ static gpointer copy_plist_data(gconstpointer src, gpointer data) | |||
| 338 | dstdata->strval = strdup(srcdata->strval); | 338 | dstdata->strval = strdup(srcdata->strval); |
| 339 | break; | 339 | break; |
| 340 | case PLIST_UNICODE: | 340 | case PLIST_UNICODE: |
| 341 | dstdata->unicodeval = wcsdup(srcdata->unicodeval); | 341 | dstdata->unicodeval = (gunichar2*) malloc(srcdata->length * sizeof(gunichar2)); |
| 342 | memcpy(dstdata->unicodeval, srcdata->unicodeval, srcdata->length * sizeof(gunichar2)); | ||
| 342 | break; | 343 | break; |
| 343 | case PLIST_DATA: | 344 | case PLIST_DATA: |
| 344 | case PLIST_ARRAY: | 345 | case PLIST_ARRAY: |
| @@ -493,7 +494,7 @@ static guint plist_data_hash(gconstpointer key) | |||
| 493 | break; | 494 | break; |
| 494 | case PLIST_UNICODE: | 495 | case PLIST_UNICODE: |
| 495 | buff = (char *) data->unicodeval; | 496 | buff = (char *) data->unicodeval; |
| 496 | size = strlen(buff) * sizeof(wchar_t); | 497 | size = data->length; |
| 497 | break; | 498 | break; |
| 498 | case PLIST_DATA: | 499 | case PLIST_DATA: |
| 499 | case PLIST_ARRAY: | 500 | case PLIST_ARRAY: |
| @@ -544,7 +545,7 @@ static gboolean plist_data_compare(gconstpointer a, gconstpointer b) | |||
| 544 | else | 545 | else |
| 545 | return FALSE; | 546 | return FALSE; |
| 546 | case PLIST_UNICODE: | 547 | case PLIST_UNICODE: |
| 547 | if (!wcscmp(val_a->unicodeval, val_b->unicodeval)) | 548 | if (!memcmp(val_a->unicodeval, val_b->unicodeval,val_a->length)) |
| 548 | return TRUE; | 549 | return TRUE; |
| 549 | else | 550 | else |
| 550 | return FALSE; | 551 | return FALSE; |
| @@ -662,6 +663,17 @@ static void write_string(GByteArray * bplist, char *val) | |||
| 662 | write_raw_data(bplist, BPLIST_STRING, (uint8_t *) val, size); | 663 | write_raw_data(bplist, BPLIST_STRING, (uint8_t *) val, size); |
| 663 | } | 664 | } |
| 664 | 665 | ||
| 666 | static void write_unicode(GByteArray * bplist, gunichar2 *val, uint64_t size) | ||
| 667 | { | ||
| 668 | uint64_t i = 0; | ||
| 669 | uint64_t size2 = size * sizeof(gunichar2); | ||
| 670 | uint8_t* buff = (uint8_t*) malloc(size2); | ||
| 671 | memcpy(buff, val, size2); | ||
| 672 | for (i = 0; i < size; i++) | ||
| 673 | byte_convert(buff + i * sizeof(gunichar2), sizeof(gunichar2)); | ||
| 674 | write_raw_data(bplist, BPLIST_STRING, buff, size2); | ||
| 675 | } | ||
| 676 | |||
| 665 | static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) | 677 | static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) |
| 666 | { | 678 | { |
| 667 | uint64_t size = g_node_n_children(node); | 679 | uint64_t size = g_node_n_children(node); |
| @@ -784,7 +796,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 784 | write_string(bplist_buff, data->strval); | 796 | write_string(bplist_buff, data->strval); |
| 785 | break; | 797 | break; |
| 786 | case PLIST_UNICODE: | 798 | case PLIST_UNICODE: |
| 787 | //TODO | 799 | write_unicode(bplist_buff, data->unicodeval, data->length); |
| 788 | break; | 800 | break; |
| 789 | case PLIST_DATA: | 801 | case PLIST_DATA: |
| 790 | write_data(bplist_buff, data->buff, data->length); | 802 | write_data(bplist_buff, data->buff, data->length); |
