sl@0: /* -*- mode: C; c-file-style: "gnu" -*- */
sl@0: /* dbus-gutils.c Utils shared between convenience lib and installed lib
sl@0:  *
sl@0:  * Copyright (C) 2003  Red Hat, Inc.
sl@0:  * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0:  * Licensed under the Academic Free License version 2.1
sl@0:  *
sl@0:  * This program is free software; you can redistribute it and/or modify
sl@0:  * it under the terms of the GNU General Public License as published by
sl@0:  * the Free Software Foundation; either version 2 of the License, or
sl@0:  * (at your option) any later version.
sl@0:  *
sl@0:  * This program is distributed in the hope that it will be useful,
sl@0:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
sl@0:  * GNU General Public License for more details.
sl@0:  *
sl@0:  * You should have received a copy of the GNU General Public License
sl@0:  * along with this program; if not, write to the Free Software
sl@0:  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
sl@0:  *
sl@0:  */
sl@0: 
sl@0: #ifndef __SYMBIAN32__
sl@0: #include <config.h>
sl@0: #else
sl@0: #include "config.h"
sl@0: #endif //__SYMBIAN32__
sl@0: #include "dbus-gutils.h"
sl@0: #include "dbus-gtest.h"
sl@0: #include <string.h>
sl@0: 
sl@0: #ifdef __SYMBIAN32__
sl@0: #include<glib_global.h>
sl@0: #endif
sl@0: 
sl@0: #ifndef DOXYGEN_SHOULD_SKIP_THIS
sl@0: 
sl@0: char**
sl@0: _dbus_gutils_split_path (const char *path)
sl@0: {
sl@0:   int len;
sl@0:   char **split;
sl@0:   int n_components;
sl@0:   int i, j, comp;
sl@0: 
sl@0:   len = strlen (path);
sl@0: 
sl@0:   n_components = 0;
sl@0:   if (path[1] != '\0') /* if not "/" */
sl@0:     {
sl@0:       i = 0;
sl@0:       while (i < len)
sl@0:         {
sl@0:           if (path[i] == '/')
sl@0:             n_components += 1;
sl@0:           ++i;
sl@0:         }
sl@0:     }
sl@0: 
sl@0:   split = g_new0 (char*, n_components + 1);
sl@0: 
sl@0:   comp = 0;
sl@0:   if (n_components == 0)
sl@0:     i = 1;
sl@0:   else
sl@0:     i = 0;
sl@0:   while (comp < n_components)
sl@0:     {
sl@0:       if (path[i] == '/')
sl@0:         ++i;
sl@0:       j = i;
sl@0: 
sl@0:       while (j < len && path[j] != '/')
sl@0:         ++j;
sl@0: 
sl@0:       /* Now [i, j) is the path component */
sl@0:       g_assert (i < j);
sl@0:       g_assert (path[i] != '/');
sl@0:       g_assert (j == len || path[j] == '/');
sl@0: 
sl@0:       split[comp] = g_strndup (&path[i], j - i + 1);
sl@0: 
sl@0:       split[comp][j-i] = '\0';
sl@0: 
sl@0:       ++comp;
sl@0:       i = j;
sl@0:     }
sl@0:   g_assert (i == len);
sl@0: 
sl@0:   return split;
sl@0: }
sl@0: 
sl@0: char*
sl@0: _dbus_gutils_wincaps_to_uscore (const char *caps)
sl@0: {
sl@0:   const char *p;
sl@0:   GString *str;
sl@0: 
sl@0:   str = g_string_new (NULL);
sl@0:   p = caps;
sl@0:   while (*p)
sl@0:     {
sl@0:       if (g_ascii_isupper (*p))
sl@0:         {
sl@0:           if (str->len > 0 &&
sl@0:               (str->len < 2 || str->str[str->len-2] != '_'))
sl@0:             g_string_append_c (str, '_');
sl@0:           g_string_append_c (str, g_ascii_tolower (*p));
sl@0:         }
sl@0:       else
sl@0:         {
sl@0:           g_string_append_c (str, *p);
sl@0:         }
sl@0:       ++p;
sl@0:     }
sl@0: 
sl@0:   return g_string_free (str, FALSE);
sl@0: }
sl@0: 
sl@0: 
sl@0: #ifdef DBUS_BUILD_TESTS
sl@0: 
sl@0: /**
sl@0:  * @ingroup DBusGLibInternals
sl@0:  * Unit test for GLib utils internals
sl@0:  * Returns: #TRUE on success.
sl@0:  */
sl@0:   	#ifdef __SYMBIAN32__
sl@0: 	EXPORT_C
sl@0: 	#endif
sl@0: gboolean
sl@0: _dbus_gutils_test (const char *test_data_dir)
sl@0: {
sl@0: 
sl@0:   return TRUE;
sl@0: }
sl@0: 
sl@0: #endif /* DBUS_BUILD_TESTS */
sl@0: 
sl@0: #endif /* DOXYGEN_SHOULD_SKIP_THIS */