summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ccf19a7)
raw | patch | inline | side by side (parent: ccf19a7)
author | Max Kellermann <max@duempel.org> | |
Thu, 18 Sep 2008 10:53:35 +0000 (12:53 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 18 Sep 2008 10:53:35 +0000 (12:53 +0200) |
Follow the same code style als MPD itself.
src/support.c | patch | blob | history |
diff --git a/src/support.c b/src/support.c
index ae3381ef294e60f3996287c3d08e55ad18aa3cbb..949c8dc52c568a6743bffecb77642304e15a08b5 100644 (file)
--- a/src/support.c
+++ b/src/support.c
size_t
my_strlen(const char *str)
{
- if( g_utf8_validate(str,-1,NULL) )
- return g_utf8_strlen(str,-1);
- else
- return strlen(str);
+ if (g_utf8_validate(str, -1, NULL))
+ return g_utf8_strlen(str, -1);
+ else
+ return strlen(str);
}
char *
remove_trailing_slash(char *path)
{
- int len;
+ int len;
- if( path==NULL )
- return NULL;
+ if (path == NULL)
+ return NULL;
- len=strlen(path);
- if( len>1 && path[len-1] == '/' )
- path[len-1] = '\0';
+ len = strlen(path);
+ if (len > 1 && path[len - 1] == '/')
+ path[len - 1] = '\0';
- return path;
+ return path;
}
char *
lowerstr(char *str)
{
- gsize i;
- gsize len = strlen(str);
-
- if( str==NULL )
- return NULL;
-
- i=0;
- while(i<len && str[i])
- {
- str[i] = tolower(str[i]);
- i++;
- }
- return str;
+ gsize i;
+ gsize len = strlen(str);
+
+ if (str == NULL)
+ return NULL;
+
+ i = 0;
+ while (i < len && str[i]) {
+ str[i] = tolower(str[i]);
+ i++;
+ }
+ return str;
}
char *
basename(char *path)
{
- char *end;
+ char *end;
- path = remove_trailing_slash(path);
- end = path + strlen(path);
+ path = remove_trailing_slash(path);
+ end = path + strlen(path);
- while( end>path && *end!='/' )
- end--;
+ while (end > path && *end != '/')
+ end--;
- if( *end=='/' && end!=path )
- return end+1;
+ if (*end == '/' && end != path)
+ return end+1;
- return path;
+ return path;
}
#endif /* HAVE_BASENAME */
char *
strcasestr(const char *haystack, const char *needle)
{
- return strstr(lowerstr(haystack), lowerstr(needle));
+ return strstr(lowerstr(haystack), lowerstr(needle));
}
#endif /* HAVE_STRCASESTR */
g_strlcat(tmp, separator, size);
len = my_strlen(tmp);
- if( st->offset >= len )
+ if (st->offset >= len)
st->offset = 0;
/* create the new scrolled string */
char *
utf8_to_locale(const char *utf8str)
{
- gchar *str;
- gsize rb, wb;
- GError *error;
-
- if( noconvert )
- return g_strdup(utf8str);
-
- rb = 0; /* bytes read */
- wb = 0; /* bytes written */
- error = NULL;
- str=g_locale_from_utf8(utf8str,
- strlen(utf8str),
- &wb, &rb,
- &error);
- if( error )
- {
- const char *charset;
-
- g_get_charset(&charset);
- screen_status_printf(_("Error: Unable to convert characters to %s"),
- charset);
- D("utf8_to_locale(): %s\n", error->message);
- g_error_free(error);
- return g_strdup(utf8str);
- }
-
- return str;
+ gchar *str;
+ gsize rb, wb;
+ GError *error;
+
+ if (noconvert)
+ return g_strdup(utf8str);
+
+ rb = 0; /* bytes read */
+ wb = 0; /* bytes written */
+ error = NULL;
+ str = g_locale_from_utf8(utf8str,
+ strlen(utf8str),
+ &wb, &rb,
+ &error);
+ if (error) {
+ const char *charset;
+
+ g_get_charset(&charset);
+ screen_status_printf(_("Error: Unable to convert characters to %s"),
+ charset);
+ D("utf8_to_locale(): %s\n", error->message);
+ g_error_free(error);
+ return g_strdup(utf8str);
+ }
+
+ return str;
}
char *
locale_to_utf8(const char *localestr)
{
- gchar *str;
- gsize rb, wb;
- GError *error;
-
- if( noconvert )
- return g_strdup(localestr);
-
- rb = 0; /* bytes read */
- wb = 0; /* bytes written */
- error = NULL;
- str=g_locale_to_utf8(localestr,
- strlen(localestr),
- &wb, &rb,
- &error);
- if( error )
- {
- screen_status_printf(_("Error: Unable to convert characters to UTF-8"));
- D("locale_to_utf8: %s\n", error->message);
- g_error_free(error);
- return g_strdup(localestr);
- }
-
- return str;
-}
-
-
+ gchar *str;
+ gsize rb, wb;
+ GError *error;
+
+ if (noconvert)
+ return g_strdup(localestr);
+
+ rb = 0; /* bytes read */
+ wb = 0; /* bytes written */
+ error = NULL;
+ str = g_locale_to_utf8(localestr,
+ strlen(localestr),
+ &wb, &rb,
+ &error);
+ if (error) {
+ screen_status_printf(_("Error: Unable to convert characters to UTF-8"));
+ D("locale_to_utf8: %s\n", error->message);
+ g_error_free(error);
+ return g_strdup(localestr);
+ }
+ return str;
+}