|
1 /* -*- mode: C; c-file-style: "gnu" -*- */ |
|
2 /* dbus-gutils.c Utils shared between convenience lib and installed lib |
|
3 * |
|
4 * Copyright (C) 2003 Red Hat, Inc. |
|
5 * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
6 * Licensed under the Academic Free License version 2.1 |
|
7 * |
|
8 * This program is free software; you can redistribute it and/or modify |
|
9 * it under the terms of the GNU General Public License as published by |
|
10 * the Free Software Foundation; either version 2 of the License, or |
|
11 * (at your option) any later version. |
|
12 * |
|
13 * This program 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 |
|
16 * GNU General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with this program; if not, write to the Free Software |
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 * |
|
22 */ |
|
23 |
|
24 #ifndef __SYMBIAN32__ |
|
25 #include <config.h> |
|
26 #else |
|
27 #include "config.h" |
|
28 #endif //__SYMBIAN32__ |
|
29 #include "dbus-gutils.h" |
|
30 #include "dbus-gtest.h" |
|
31 #include <string.h> |
|
32 |
|
33 #ifdef __SYMBIAN32__ |
|
34 #include<glib_global.h> |
|
35 #endif |
|
36 |
|
37 #ifndef DOXYGEN_SHOULD_SKIP_THIS |
|
38 |
|
39 char** |
|
40 _dbus_gutils_split_path (const char *path) |
|
41 { |
|
42 int len; |
|
43 char **split; |
|
44 int n_components; |
|
45 int i, j, comp; |
|
46 |
|
47 len = strlen (path); |
|
48 |
|
49 n_components = 0; |
|
50 if (path[1] != '\0') /* if not "/" */ |
|
51 { |
|
52 i = 0; |
|
53 while (i < len) |
|
54 { |
|
55 if (path[i] == '/') |
|
56 n_components += 1; |
|
57 ++i; |
|
58 } |
|
59 } |
|
60 |
|
61 split = g_new0 (char*, n_components + 1); |
|
62 |
|
63 comp = 0; |
|
64 if (n_components == 0) |
|
65 i = 1; |
|
66 else |
|
67 i = 0; |
|
68 while (comp < n_components) |
|
69 { |
|
70 if (path[i] == '/') |
|
71 ++i; |
|
72 j = i; |
|
73 |
|
74 while (j < len && path[j] != '/') |
|
75 ++j; |
|
76 |
|
77 /* Now [i, j) is the path component */ |
|
78 g_assert (i < j); |
|
79 g_assert (path[i] != '/'); |
|
80 g_assert (j == len || path[j] == '/'); |
|
81 |
|
82 split[comp] = g_strndup (&path[i], j - i + 1); |
|
83 |
|
84 split[comp][j-i] = '\0'; |
|
85 |
|
86 ++comp; |
|
87 i = j; |
|
88 } |
|
89 g_assert (i == len); |
|
90 |
|
91 return split; |
|
92 } |
|
93 |
|
94 char* |
|
95 _dbus_gutils_wincaps_to_uscore (const char *caps) |
|
96 { |
|
97 const char *p; |
|
98 GString *str; |
|
99 |
|
100 str = g_string_new (NULL); |
|
101 p = caps; |
|
102 while (*p) |
|
103 { |
|
104 if (g_ascii_isupper (*p)) |
|
105 { |
|
106 if (str->len > 0 && |
|
107 (str->len < 2 || str->str[str->len-2] != '_')) |
|
108 g_string_append_c (str, '_'); |
|
109 g_string_append_c (str, g_ascii_tolower (*p)); |
|
110 } |
|
111 else |
|
112 { |
|
113 g_string_append_c (str, *p); |
|
114 } |
|
115 ++p; |
|
116 } |
|
117 |
|
118 return g_string_free (str, FALSE); |
|
119 } |
|
120 |
|
121 |
|
122 #ifdef DBUS_BUILD_TESTS |
|
123 |
|
124 /** |
|
125 * @ingroup DBusGLibInternals |
|
126 * Unit test for GLib utils internals |
|
127 * Returns: #TRUE on success. |
|
128 */ |
|
129 #ifdef __SYMBIAN32__ |
|
130 EXPORT_C |
|
131 #endif |
|
132 gboolean |
|
133 _dbus_gutils_test (const char *test_data_dir) |
|
134 { |
|
135 |
|
136 return TRUE; |
|
137 } |
|
138 |
|
139 #endif /* DBUS_BUILD_TESTS */ |
|
140 |
|
141 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |