diff options
Diffstat (limited to 'libraries/eina/src/lib/eina_ustringshare.c')
-rw-r--r-- | libraries/eina/src/lib/eina_ustringshare.c | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/libraries/eina/src/lib/eina_ustringshare.c b/libraries/eina/src/lib/eina_ustringshare.c new file mode 100644 index 0000000..3992dc6 --- /dev/null +++ b/libraries/eina/src/lib/eina_ustringshare.c | |||
@@ -0,0 +1,132 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2002-2008 Carsten Haitzler, | ||
3 | * Jorge Luis Zapata Muga, | ||
4 | * Cedric Bail, | ||
5 | * Gustavo Sverzut Barbieri | ||
6 | * Tom Hacohen | ||
7 | * | ||
8 | * This library is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * This library is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with this library; | ||
20 | * if not, see <http://www.gnu.org/licenses/>. | ||
21 | |||
22 | */ | ||
23 | /** | ||
24 | * @page tutorial_ustringshare_page UStringshare Tutorial | ||
25 | * | ||
26 | * to be written... | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #include "eina_share_common.h" | ||
31 | #include "eina_unicode.h" | ||
32 | #include "eina_private.h" | ||
33 | #include "eina_ustringshare.h" | ||
34 | |||
35 | /* The actual share */ | ||
36 | static Eina_Share *ustringshare_share; | ||
37 | static const char EINA_MAGIC_USTRINGSHARE_NODE_STR[] = "Eina UStringshare Node"; | ||
38 | |||
39 | /*============================================================================* | ||
40 | * Global * | ||
41 | *============================================================================*/ | ||
42 | |||
43 | /** | ||
44 | * @internal | ||
45 | * @brief Initialize the share_common module. | ||
46 | * | ||
47 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
48 | * | ||
49 | * This function sets up the share_common module of Eina. It is called by | ||
50 | * eina_init(). | ||
51 | * | ||
52 | * @see eina_init() | ||
53 | */ | ||
54 | Eina_Bool | ||
55 | eina_ustringshare_init(void) | ||
56 | { | ||
57 | return eina_share_common_init(&ustringshare_share, | ||
58 | EINA_MAGIC_USTRINGSHARE_NODE, | ||
59 | EINA_MAGIC_USTRINGSHARE_NODE_STR); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * @internal | ||
64 | * @brief Shut down the share_common module. | ||
65 | * | ||
66 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
67 | * | ||
68 | * This function shuts down the share_common module set up by | ||
69 | * eina_share_common_init(). It is called by eina_shutdown(). | ||
70 | * | ||
71 | * @see eina_shutdown() | ||
72 | */ | ||
73 | Eina_Bool | ||
74 | eina_ustringshare_shutdown(void) | ||
75 | { | ||
76 | Eina_Bool ret; | ||
77 | ret = eina_share_common_shutdown(&ustringshare_share); | ||
78 | return ret; | ||
79 | } | ||
80 | |||
81 | /*============================================================================* | ||
82 | * API * | ||
83 | *============================================================================*/ | ||
84 | |||
85 | EAPI void | ||
86 | eina_ustringshare_del(const Eina_Unicode *str) | ||
87 | { | ||
88 | if (!str) | ||
89 | return; | ||
90 | |||
91 | eina_share_common_del(ustringshare_share,(const char *)str); | ||
92 | } | ||
93 | |||
94 | EAPI const Eina_Unicode * | ||
95 | eina_ustringshare_add_length(const Eina_Unicode *str, unsigned int slen) | ||
96 | { | ||
97 | return (const Eina_Unicode *)eina_share_common_add_length(ustringshare_share, | ||
98 | (const char *)str, | ||
99 | slen * | ||
100 | sizeof( | ||
101 | Eina_Unicode), | ||
102 | sizeof( | ||
103 | Eina_Unicode)); | ||
104 | } | ||
105 | |||
106 | EAPI const Eina_Unicode * | ||
107 | eina_ustringshare_add(const Eina_Unicode *str) | ||
108 | { | ||
109 | int slen = (str) ? (int)eina_unicode_strlen(str) : -1; | ||
110 | return eina_ustringshare_add_length(str, slen); | ||
111 | } | ||
112 | |||
113 | EAPI const Eina_Unicode * | ||
114 | eina_ustringshare_ref(const Eina_Unicode *str) | ||
115 | { | ||
116 | return (const Eina_Unicode *)eina_share_common_ref(ustringshare_share, | ||
117 | (const char *)str); | ||
118 | } | ||
119 | |||
120 | EAPI int | ||
121 | eina_ustringshare_strlen(const Eina_Unicode *str) | ||
122 | { | ||
123 | int len = eina_share_common_length(ustringshare_share, (const char *)str); | ||
124 | len = (len > 0) ? len / (int)sizeof(Eina_Unicode) : -1; | ||
125 | return len; | ||
126 | } | ||
127 | |||
128 | EAPI void | ||
129 | eina_ustringshare_dump(void) | ||
130 | { | ||
131 | eina_share_common_dump(ustringshare_share, NULL, 0); | ||
132 | } | ||