diff options
| author | 2009-04-28 22:15:39 +0200 | |
|---|---|---|
| committer | 2009-04-28 22:15:39 +0200 | |
| commit | 07b8041d44c6b43da1b0c55d140999cb3137d040 (patch) | |
| tree | 4808d49c714036faff2104ad2c3a656618b9e035 /src/plist.c | |
| parent | 0d301b693a84db6f6a751722359e602172da94b3 (diff) | |
| download | libplist-07b8041d44c6b43da1b0c55d140999cb3137d040.tar.gz libplist-07b8041d44c6b43da1b0c55d140999cb3137d040.tar.bz2 | |
Merge ascii and unicode handling in PLIST_STRING using UTF-8. Remove unicode related declaration in API (breaks API&ABI)
Diffstat (limited to 'src/plist.c')
| -rw-r--r-- | src/plist.c | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/src/plist.c b/src/plist.c index 4fc2780..7949bce 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -53,9 +53,6 @@ static void plist_free_node(GNode * node, gpointer none) | |||
| 53 | case PLIST_STRING: | 53 | case PLIST_STRING: |
| 54 | free(data->strval); | 54 | free(data->strval); |
| 55 | break; | 55 | break; |
| 56 | case PLIST_UNICODE: | ||
| 57 | free(data->unicodeval); | ||
| 58 | break; | ||
| 59 | case PLIST_DATA: | 56 | case PLIST_DATA: |
| 60 | free(data->buff); | 57 | free(data->buff); |
| 61 | break; | 58 | break; |
| @@ -90,10 +87,6 @@ static plist_t plist_add_sub_element(plist_t node, plist_type type, const void * | |||
| 90 | //only structured types are allowed to have nulll value | 87 | //only structured types are allowed to have nulll value |
| 91 | if (value || (!value && (type == PLIST_DICT || type == PLIST_ARRAY))) { | 88 | if (value || (!value && (type == PLIST_DICT || type == PLIST_ARRAY))) { |
| 92 | 89 | ||
| 93 | glong len = 0; | ||
| 94 | glong items_read = 0; | ||
| 95 | glong items_written = 0; | ||
| 96 | GError *error = NULL; | ||
| 97 | plist_t subnode = NULL; | 90 | plist_t subnode = NULL; |
| 98 | 91 | ||
| 99 | //now handle value | 92 | //now handle value |
| @@ -115,11 +108,6 @@ static plist_t plist_add_sub_element(plist_t node, plist_type type, const void * | |||
| 115 | case PLIST_STRING: | 108 | case PLIST_STRING: |
| 116 | data->strval = strdup((char *) value); | 109 | data->strval = strdup((char *) value); |
| 117 | break; | 110 | break; |
| 118 | case PLIST_UNICODE: | ||
| 119 | len = strlen((char *) value); | ||
| 120 | data->unicodeval = g_utf8_to_utf16((char *) value, len, &items_read, &items_written, &error); | ||
| 121 | data->length = items_written; | ||
| 122 | break; | ||
| 123 | case PLIST_DATA: | 111 | case PLIST_DATA: |
| 124 | data->buff = (uint8_t*)malloc(length); | 112 | data->buff = (uint8_t*)malloc(length); |
| 125 | memcpy(data->buff, value, length); | 113 | memcpy(data->buff, value, length); |
| @@ -210,9 +198,6 @@ static char compare_node_value(plist_type type, plist_data_t data, const void *v | |||
| 210 | case PLIST_STRING: | 198 | case PLIST_STRING: |
| 211 | res = !strcmp(data->strval, ((char *) value)); | 199 | res = !strcmp(data->strval, ((char *) value)); |
| 212 | break; | 200 | break; |
| 213 | case PLIST_UNICODE: | ||
| 214 | res = !memcpy(data->unicodeval, value, length); | ||
| 215 | break; | ||
| 216 | case PLIST_DATA: | 201 | case PLIST_DATA: |
| 217 | res = !memcmp(data->buff, (char *) value, length); | 202 | res = !memcmp(data->buff, (char *) value, length); |
| 218 | break; | 203 | break; |
| @@ -262,11 +247,6 @@ plist_t plist_find_node_by_string(plist_t plist, const char *value) | |||
| 262 | 247 | ||
| 263 | static void plist_get_type_and_value(plist_t node, plist_type * type, void *value, uint64_t * length) | 248 | static void plist_get_type_and_value(plist_t node, plist_type * type, void *value, uint64_t * length) |
| 264 | { | 249 | { |
| 265 | //for unicode | ||
| 266 | glong len = 0; | ||
| 267 | glong items_read = 0; | ||
| 268 | glong items_written = 0; | ||
| 269 | GError *error = NULL; | ||
| 270 | plist_data_t data = NULL; | 250 | plist_data_t data = NULL; |
| 271 | 251 | ||
| 272 | if (!node) | 252 | if (!node) |
| @@ -291,10 +271,6 @@ static void plist_get_type_and_value(plist_t node, plist_type * type, void *valu | |||
| 291 | case PLIST_STRING: | 271 | case PLIST_STRING: |
| 292 | *((char **) value) = strdup(data->strval); | 272 | *((char **) value) = strdup(data->strval); |
| 293 | break; | 273 | break; |
| 294 | case PLIST_UNICODE: | ||
| 295 | len = data->length; | ||
| 296 | *((char **) value) = g_utf16_to_utf8(data->unicodeval, len, &items_read, &items_written, &error); | ||
| 297 | break; | ||
| 298 | case PLIST_DATA: | 274 | case PLIST_DATA: |
| 299 | *((uint8_t **) value) = (uint8_t *) malloc(*length * sizeof(uint8_t)); | 275 | *((uint8_t **) value) = (uint8_t *) malloc(*length * sizeof(uint8_t)); |
| 300 | memcpy(*((uint8_t **) value), data->buff, *length * sizeof(uint8_t)); | 276 | memcpy(*((uint8_t **) value), data->buff, *length * sizeof(uint8_t)); |
| @@ -360,11 +336,6 @@ void plist_add_sub_data_el(plist_t node, const char *val, uint64_t length) | |||
| 360 | plist_add_sub_element(node, PLIST_DATA, val, length); | 336 | plist_add_sub_element(node, PLIST_DATA, val, length); |
| 361 | } | 337 | } |
| 362 | 338 | ||
| 363 | void plist_add_sub_unicode_el(plist_t node, const char *val) | ||
| 364 | { | ||
| 365 | plist_add_sub_element(node, PLIST_UNICODE, val, strlen(val)); | ||
| 366 | } | ||
| 367 | |||
| 368 | void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec) | 339 | void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec) |
| 369 | { | 340 | { |
| 370 | GTimeVal val = { sec, usec }; | 341 | GTimeVal val = { sec, usec }; |
| @@ -423,15 +394,6 @@ void plist_get_data_val(plist_t node, char **val, uint64_t * length) | |||
| 423 | plist_get_type_and_value(node, &type, (void *) val, length); | 394 | plist_get_type_and_value(node, &type, (void *) val, length); |
| 424 | } | 395 | } |
| 425 | 396 | ||
| 426 | void plist_get_unicode_val(plist_t node, char **val) | ||
| 427 | { | ||
| 428 | plist_type type = plist_get_node_type(node); | ||
| 429 | uint64_t length = 0; | ||
| 430 | if (PLIST_UNICODE == type) | ||
| 431 | plist_get_type_and_value(node, &type, (void *) val, &length); | ||
| 432 | assert(length == strlen(*val)); | ||
| 433 | } | ||
| 434 | |||
| 435 | void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec) | 397 | void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec) |
| 436 | { | 398 | { |
| 437 | plist_type type = plist_get_node_type(node); | 399 | plist_type type = plist_get_node_type(node); |
| @@ -476,11 +438,6 @@ gboolean plist_data_compare(gconstpointer a, gconstpointer b) | |||
| 476 | return TRUE; | 438 | return TRUE; |
| 477 | else | 439 | else |
| 478 | return FALSE; | 440 | return FALSE; |
| 479 | case PLIST_UNICODE: | ||
| 480 | if (!memcmp(val_a->unicodeval, val_b->unicodeval, val_a->length)) | ||
| 481 | return TRUE; | ||
| 482 | else | ||
| 483 | return FALSE; | ||
| 484 | 441 | ||
| 485 | case PLIST_DATA: | 442 | case PLIST_DATA: |
| 486 | if (!memcmp(val_a->buff, val_b->buff, val_a->length)) | 443 | if (!memcmp(val_a->buff, val_b->buff, val_a->length)) |
