diff options
| author | 2009-01-22 22:18:43 +0100 | |
|---|---|---|
| committer | 2009-01-22 22:18:43 +0100 | |
| commit | bfd57eb1cf738ed62e17941e855347772ce48ef2 (patch) | |
| tree | 45eda77468ff586bdd64fd6afcb5452cb0407bad /src/xplist.c | |
| parent | 8da4dac2e65778d1f562f4502c09b16590cfd8e1 (diff) | |
| download | libplist-bfd57eb1cf738ed62e17941e855347772ce48ef2.tar.gz libplist-bfd57eb1cf738ed62e17941e855347772ce48ef2.tar.bz2 | |
Add Unicode support.
Diffstat (limited to 'src/xplist.c')
| -rw-r--r-- | src/xplist.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/xplist.c b/src/xplist.c index 0b803cf..e61797c 100644 --- a/src/xplist.c +++ b/src/xplist.c | |||
| @@ -24,7 +24,6 @@ | |||
| 24 | #include <assert.h> | 24 | #include <assert.h> |
| 25 | #include "utils.h" | 25 | #include "utils.h" |
| 26 | #include "plist.h" | 26 | #include "plist.h" |
| 27 | #include <wchar.h> | ||
| 28 | #include <stdlib.h> | 27 | #include <stdlib.h> |
| 29 | #include <stdio.h> | 28 | #include <stdio.h> |
| 30 | 29 | ||
| @@ -139,6 +138,12 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 139 | const xmlChar *tag = NULL; | 138 | const xmlChar *tag = NULL; |
| 140 | gchar *val = NULL; | 139 | gchar *val = NULL; |
| 141 | 140 | ||
| 141 | //for unicode | ||
| 142 | glong len = 0; | ||
| 143 | glong items_read = 0; | ||
| 144 | glong items_written = 0; | ||
| 145 | GError *error = NULL; | ||
| 146 | |||
| 142 | switch (node_data->type) { | 147 | switch (node_data->type) { |
| 143 | case PLIST_BOOLEAN: | 148 | case PLIST_BOOLEAN: |
| 144 | { | 149 | { |
| @@ -166,7 +171,8 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 166 | 171 | ||
| 167 | case PLIST_UNICODE: | 172 | case PLIST_UNICODE: |
| 168 | tag = XPLIST_STRING; | 173 | tag = XPLIST_STRING; |
| 169 | val = g_strdup((gchar *) node_data->unicodeval); | 174 | len = node_data->length; |
| 175 | val = g_utf16_to_utf8(node_data->unicodeval, len, &items_read, &items_written, &error); | ||
| 170 | break; | 176 | break; |
| 171 | 177 | ||
| 172 | case PLIST_KEY: | 178 | case PLIST_KEY: |
| @@ -278,13 +284,28 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | |||
| 278 | g_time_val_from_iso8601((char *) xmlNodeGetContent(node), &data->timeval); | 284 | g_time_val_from_iso8601((char *) xmlNodeGetContent(node), &data->timeval); |
| 279 | data->type = PLIST_DATE; | 285 | data->type = PLIST_DATE; |
| 280 | data->length = sizeof(GTimeVal); | 286 | data->length = sizeof(GTimeVal); |
| 281 | continue; //TODO : handle date tag | 287 | continue; |
| 282 | } | 288 | } |
| 283 | 289 | ||
| 284 | if (!xmlStrcmp(node->name, XPLIST_STRING)) { | 290 | if (!xmlStrcmp(node->name, XPLIST_STRING)) { |
| 285 | data->strval = strdup((char *) xmlNodeGetContent(node)); | 291 | |
| 286 | data->type = PLIST_STRING; | 292 | unsigned char *tmp = xmlNodeGetContent(node); |
| 287 | data->length = strlen(data->strval); | 293 | glong len = strlen((char*)tmp); |
| 294 | glong items_read = 0; | ||
| 295 | glong items_written = 0; | ||
| 296 | GError *error = NULL; | ||
| 297 | int type = xmlDetectCharEncoding(tmp, len); | ||
| 298 | |||
| 299 | if (XML_CHAR_ENCODING_UTF8 == type) { | ||
| 300 | data->unicodeval = g_utf8_to_utf16((char*) tmp, len, &items_read, &items_written, &error); | ||
| 301 | data->type = PLIST_UNICODE; | ||
| 302 | data->length = items_written; | ||
| 303 | } | ||
| 304 | else if (XML_CHAR_ENCODING_ASCII == type || XML_CHAR_ENCODING_NONE == type) { | ||
| 305 | data->strval = strdup((char *) xmlNodeGetContent(node)); | ||
| 306 | data->type = PLIST_STRING; | ||
| 307 | data->length = strlen(data->strval); | ||
| 308 | } | ||
| 288 | continue; | 309 | continue; |
| 289 | } | 310 | } |
| 290 | 311 | ||
