bff22cd6de22d8fe1803ae36dbff588e8328a9bd
[gedcom-parse.git] / gom / gom_modify.c
1 /* Source code for modifying the gedcom object model.
2    Copyright (C) 2002 The Genes Development Team
3    This file is part of the Gedcom parser library.
4    Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2002.
5
6    The Gedcom parser library is free software; you can redistribute it
7    and/or modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The Gedcom parser library is distributed in the hope that it will be
12    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the Gedcom parser library; if not, write to the
18    Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
20
21 /* $Id$ */
22 /* $Name$ */
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include "utf8.h"
27 #include "gom.h"
28 #include "gom_internal.h"
29
30 void gom_set_unknown(const char* unknown)
31 {
32   convert_set_unknown(unknown);
33 }
34
35 char* gom_get_string(char* data)
36 {
37   return data;
38 }
39
40 char* gom_get_string_for_locale(char* data, int* conversion_failures)
41 {
42   return convert_utf8_to_locale(gom_get_string(data), conversion_failures);
43 }
44
45 char* gom_set_string(char** data, const char* utf8_str)
46 {
47   char* result = NULL;
48   char* newptr;
49
50   if (!is_utf8_string(utf8_str)) {
51     gedcom_error(_("The input '%s' is not a valid UTF-8 string"), utf8_str);
52   }
53   else {
54     newptr = strdup(utf8_str);
55     if (!newptr)
56       MEMORY_ERROR;
57     else {
58       if (*data) free(*data);
59       *data = newptr;
60       result = *data;
61     }
62   }
63   
64   return result;
65 }
66
67 char* gom_set_string_for_locale(char** data, const char* locale_str)
68 {
69   char* result = NULL;
70   char* utf8_str = convert_locale_to_utf8(locale_str);
71   
72   if (!utf8_str)
73     gedcom_error(_("The input '%s' is not a valid string for the locale"),
74                  locale_str);
75   else
76     result = gom_set_string(data, utf8_str);
77
78   return result;
79 }