~jbicha/ubuntu/oneiric/gjs/1.29.18

« back to all changes in this revision

Viewing changes to util/glib.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-02-06 13:01:02 UTC
  • mfrom: (1.3.10 experimental)
  • Revision ID: james.westby@ubuntu.com-20110206130102-69xpqq0gql9fob01
Tags: 0.7.10-1
* New upstream release.
* debian/control.in:
  - Drop build-depend on libmozjs-dev
  - Make libgjs-dev depend on xulrunner-dev and libdbus-1-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * IN THE SOFTWARE.
22
22
 */
23
23
 
 
24
#include <string.h>
 
25
 
 
26
#include "glib.h"
 
27
 
24
28
#include <config.h>
25
29
 
26
 
#include "glib.h"
27
 
 
28
30
typedef struct {
29
31
    void *key;
30
32
    void *value;
125
127
    return (char**)g_ptr_array_free(array, FALSE);
126
128
}
127
129
 
 
130
gchar *
 
131
_gjs_g_utf8_make_valid (const gchar *name)
 
132
{
 
133
  GString *string;
 
134
  const gchar *remainder, *invalid;
 
135
  gint remaining_bytes, valid_bytes;
 
136
 
 
137
  g_return_val_if_fail (name != NULL, NULL);
 
138
 
 
139
  string = NULL;
 
140
  remainder = name;
 
141
  remaining_bytes = strlen (name);
 
142
 
 
143
  while (remaining_bytes != 0)
 
144
    {
 
145
      if (g_utf8_validate (remainder, remaining_bytes, &invalid))
 
146
        break;
 
147
      valid_bytes = invalid - remainder;
 
148
 
 
149
      if (string == NULL)
 
150
        string = g_string_sized_new (remaining_bytes);
 
151
 
 
152
      g_string_append_len (string, remainder, valid_bytes);
 
153
      /* append U+FFFD REPLACEMENT CHARACTER */
 
154
      g_string_append (string, "\357\277\275");
 
155
 
 
156
      remaining_bytes -= valid_bytes + 1;
 
157
      remainder = invalid + 1;
 
158
    }
 
159
 
 
160
  if (string == NULL)
 
161
    return g_strdup (name);
 
162
 
 
163
  g_string_append (string, remainder);
 
164
 
 
165
  g_assert (g_utf8_validate (string->str, -1, NULL));
 
166
 
 
167
  return g_string_free (string, FALSE);
 
168
}
 
169
 
128
170
#if GJS_BUILD_TESTS
129
171
 
130
172
void