~ubuntu-branches/ubuntu/trusty/pcmanfm/trusty-proposed

« back to all changes in this revision

Viewing changes to src/ptk/exo-string.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Lee
  • Date: 2008-09-26 10:19:20 UTC
  • mfrom: (4.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080926101920-cfldybkmwgwrtv9u
Tags: 0.5-3
* Correct spellings,  03_correct_spelling.dpatch (Closes:498794) 
* Code in some files are taken from other projects, added these
  informations into copyright file. (Closes:499678)
* Applied 04_defaut_terminal.dpatch to support x-terminal-emulator
  alternative. (Closes:497494) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: exo-string.c 47 2006-01-30 02:32:10Z pcmanx $ */
2
 
/*-
3
 
 * Copyright (c) 2004 os-cillation e.K.
4
 
 *
5
 
 * Written by Benedikt Meurer <benny@xfce.org>.
6
 
 *
7
 
 * This library is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Library General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2 of the License, or (at your option) any later version.
11
 
 *
12
 
 * This library is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Library General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Library General Public
18
 
 * License along with this library; if not, write to the
19
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
 * Boston, MA 02111-1307, USA.
21
 
 */
22
 
 
23
 
#ifdef HAVE_CONFIG_H
24
 
#include <config.h>
25
 
#endif
26
 
 
27
 
#ifdef HAVE_MEMORY_H
28
 
#include <memory.h>
29
 
#endif
30
 
#ifdef HAVE_STRING_H
31
 
#include <string.h>
32
 
#endif
33
 
 
34
 
#include "exo-string.h"
35
 
 
36
 
 
37
 
 
38
 
/**
39
 
 * exo_str_elide_underscores:
40
 
 * @text : A zero terminated string.
41
 
 *
42
 
 * Returns a copy of @text with all mnemonic underscores
43
 
 * stripped off.
44
 
 *
45
 
 * Return value: A copy of @text without underscores. The
46
 
 *               returned string must be freed when no
47
 
 *               longer required.
48
 
 **/
49
 
gchar*
50
 
exo_str_elide_underscores (const gchar *text)
51
 
{
52
 
  const gchar *s;
53
 
  gboolean     last_underscore = FALSE;
54
 
  gchar       *result;
55
 
  gchar       *t;
56
 
 
57
 
  g_return_val_if_fail (text != NULL, NULL);
58
 
 
59
 
  result = g_malloc (strlen (text) + 1);
60
 
 
61
 
  for (s = text, t = result; *s != '\0'; ++s)
62
 
    if (!last_underscore && *s == '_')
63
 
      {
64
 
        last_underscore = TRUE;
65
 
      }
66
 
    else
67
 
      {
68
 
        last_underscore = FALSE;
69
 
        *t++ = *s;
70
 
      }
71
 
 
72
 
  *t = '\0';
73
 
 
74
 
  return result;
75
 
}
76
 
 
77
 
 
78
 
 
79
 
/**
80
 
 * exo_str_is_equal:
81
 
 * @a : A pointer to first string or %NULL.
82
 
 * @b : A pointer to second string or %NULL.
83
 
 *
84
 
 * %NULL-safe string comparison. Returns %TRUE if both @a and @b are
85
 
 * %NULL or if @a and @b refer to valid strings which are equal.
86
 
 *
87
 
 * You should always prefer this function over strcmp().
88
 
 *
89
 
 * Return value: %TRUE if @a equals @b, else %FALSE.
90
 
 **/
91
 
gboolean
92
 
exo_str_is_equal (const gchar *a,
93
 
                  const gchar *b)
94
 
{
95
 
  if (a == NULL && b == NULL)
96
 
    return TRUE;
97
 
  else if (a == NULL || b == NULL)
98
 
    return FALSE;
99
 
 
100
 
  while (*a == *b++)
101
 
    if (*a++ == '\0')
102
 
      return TRUE;
103
 
 
104
 
  return FALSE;
105
 
}
106
 
 
107
 
 
108
 
 
109
 
/**
110
 
 * exo_strndupv:
111
 
 * @strv  : String vector to duplicate.
112
 
 * @num   : Number of strings in @strv to
113
 
 *          duplicate.
114
 
 *
115
 
 * Creates a new string vector containing the
116
 
 * first @n elements of @strv.
117
 
 *
118
 
 * Return value: The new string vector. Should be
119
 
 *               freed using g_strfreev() when no
120
 
 *               longer needed.
121
 
 **/
122
 
gchar**
123
 
exo_strndupv (gchar **strv,
124
 
              gint    num)
125
 
{
126
 
  gchar **result;
127
 
 
128
 
  g_return_val_if_fail (strv != NULL, NULL);
129
 
  g_return_val_if_fail (num >= 0, NULL);
130
 
 
131
 
  result = g_new (gchar *, num + 1);
132
 
  result[num--] = NULL;
133
 
  for (; num >= 0; --num)
134
 
    result[num] = g_strdup (strv[num]);
135
 
 
136
 
  return result;
137
 
}
138