00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #include <config.h>
00025 #include "dbus-gutils.h"
00026 #include "dbus-gtest.h"
00027 #include <string.h>
00028 
00029 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00030 
00031 char**
00032 _dbus_gutils_split_path (const char *path)
00033 {
00034   int len;
00035   char **split;
00036   int n_components;
00037   int i, j, comp;
00038 
00039   len = strlen (path);
00040 
00041   n_components = 0;
00042   if (path[1] != '\0') 
00043     {
00044       i = 0;
00045       while (i < len)
00046         {
00047           if (path[i] == '/')
00048             n_components += 1;
00049           ++i;
00050         }
00051     }
00052 
00053   split = g_new0 (char*, n_components + 1);
00054 
00055   comp = 0;
00056   if (n_components == 0)
00057     i = 1;
00058   else
00059     i = 0;
00060   while (comp < n_components)
00061     {
00062       if (path[i] == '/')
00063         ++i;
00064       j = i;
00065 
00066       while (j < len && path[j] != '/')
00067         ++j;
00068 
00069       
00070       g_assert (i < j);
00071       g_assert (path[i] != '/');
00072       g_assert (j == len || path[j] == '/');
00073 
00074       split[comp] = g_strndup (&path[i], j - i + 1);
00075 
00076       split[comp][j-i] = '\0';
00077 
00078       ++comp;
00079       i = j;
00080     }
00081   g_assert (i == len);
00082 
00083   return split;
00084 }
00085 
00086 char*
00087 _dbus_gutils_wincaps_to_uscore (const char *caps)
00088 {
00089   const char *p;
00090   GString *str;
00091 
00092   str = g_string_new (NULL);
00093   p = caps;
00094   while (*p)
00095     {
00096       if (g_ascii_isupper (*p))
00097         {
00098           if (str->len > 0 &&
00099               (str->len < 2 || str->str[str->len-2] != '_'))
00100             g_string_append_c (str, '_');
00101           g_string_append_c (str, g_ascii_tolower (*p));
00102         }
00103       else
00104         {
00105           g_string_append_c (str, *p);
00106         }
00107       ++p;
00108     }
00109 
00110   return g_string_free (str, FALSE);
00111 }
00112 
00113 
00114 #ifdef DBUS_BUILD_TESTS
00115 
00121 gboolean
00122 _dbus_gutils_test (const char *test_data_dir)
00123 {
00124 
00125   return TRUE;
00126 }
00127 
00128 #endif 
00129 
00130 #endif