34 #define FROM_HEX(c) ((c) < 'A' ? (c) - '0' : (c) < 'a' ? 10 + (c) - 'A' : 10 + (c) - 'a')
35 #define TO_HEX(i) ((i) < 10 ? '0' + (i) : 'A' + (i) - 10)
36 #define IS_LEGAL(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z') \
37 || ((c) >= '0' && (c) <= '9') || (strchr ("-_.~/", (c))))
41 return ! g_ascii_strncasecmp (str, prefix, strlen (prefix));
46 int len1 = strlen (str);
47 int len2 = strlen (suffix);
52 return ! g_ascii_strcasecmp (str + len1 - len2, suffix);
55 static char * (* str_to_utf8_impl) (
const char *) =
NULL;
56 static char * (* str_to_utf8_full_impl) (
const char *,
int,
int *,
int *) =
NULL;
59 char * (* stuf_impl) (
const char *,
int,
int *,
int *))
71 EXPORT
char *
str_to_utf8_full (
const char * str,
int len,
int * bytes_read,
int * bytes_written)
79 while ((
string = strchr (
string, old_c)))
98 if (c ==
'%' && len >= 2 && str[0] && str[1])
131 * out ++ =
TO_HEX ((
unsigned char) c >> 4);
132 * out ++ =
TO_HEX (c & 0xF);
145 char * utf8 = g_locale_to_utf8 (name, -1,
NULL,
NULL,
NULL);
148 fprintf (stderr,
"Cannot convert filename from system locale: %s\n", name);
155 char enc[3 * strlen (utf8) + 1];
161 return g_strdup_printf (
"file:///%s", enc);
163 return g_strdup_printf (
"file://%s", enc);
174 g_return_val_if_fail (! strncmp (uri,
"file:///", 8),
NULL);
175 char buf[strlen (uri + 8) + 1];
178 g_return_val_if_fail (! strncmp (uri,
"file://", 7),
NULL);
179 char buf[strlen (uri + 7) + 1];
188 fprintf (stderr,
"Cannot convert filename to system locale: %s\n", buf);
198 if (! strncmp (uri,
"cdda://?", 8))
199 return g_strdup_printf (
_(
"Audio CD, track %s"), uri + 8);
201 char buf[strlen (uri) + 1];
204 if (! strncmp (uri,
"file:///", 8))
210 if (! strncmp (uri,
"file://", 7))
216 return g_strdup (buf);
219 EXPORT
void uri_parse (
const char * uri,
const char * * base_p,
const char * * ext_p,
220 const char * * sub_p,
int * isub_p)
222 const char * end = uri + strlen (uri);
223 const char * base, * ext, * sub, * c;
227 if ((c = strrchr (uri,
'/')))
232 if ((c = strrchr (base,
'?')) && sscanf (c + 1,
"%d%c", & isub, & junk) == 1)
237 char buf[sub - base + 1];
238 memcpy (buf, base, sub - base);
241 if ((c = strrchr (buf,
'.')))
242 ext = base + (c - buf);
264 g_strlcpy (buf, ext + 1, buflen);
268 if ((qmark = strchr (buf,
'?')))
271 return (buf[0] != 0);
281 return (bp ==
NULL) ? 0 : -1;
285 unsigned char a = * ap ++,
b = * bp ++;
286 for (; a ||
b; a = * ap ++, b = * bp ++)
288 if (a >
'9' || b >
'9' || a <
'0' || b <
'0')
290 if (a <= 'Z' && a >=
'A')
292 if (b <= 'Z' && b >=
'A')
303 for (; (a = * ap) <=
'9' && a >=
'0'; ap ++)
304 x = 10 * x + (a -
'0');
307 for (; (b = * bp) >=
'0' && b <=
'9'; bp ++)
308 y = 10 * y + (b -
'0');
325 return (bp ==
NULL) ? 0 : -1;
329 unsigned char a = * ap ++,
b = * bp ++;
330 for (; a ||
b; a = * ap ++, b = * bp ++)
332 if (a ==
'%' && ap[0] && ap[1])
337 if (b ==
'%' && bp[0] && bp[1])
343 if (a >
'9' || b >
'9' || a <
'0' || b <
'0')
345 if (a <= 'Z' && a >=
'A')
347 if (b <= 'Z' && b >=
'A')
358 for (; (a = * ap) <=
'9' && a >=
'0'; ap ++)
359 x = 10 * x + (a -
'0');
362 for (; (b = * bp) >=
'0' && b <=
'9'; bp ++)
363 y = 10 * y + (b -
'0');
379 int left = strlen(s);
380 int avail = size - (left + 1);
381 int oldlen = strlen(old);
382 int newlen = strlen(
new);
383 int diff = newlen - oldlen;
385 while (left >= oldlen)
387 if (strncmp(ptr, old, oldlen))
398 memmove(ptr + oldlen + diff, ptr + oldlen, left + 1 - oldlen);
400 memcpy(ptr,
new, newlen);
425 bool_t neg = (
string[0] ==
'-');
432 while ((c = *
string ++))
434 if (c < '0' || c >
'9' || val > 100000000)
437 val = val * 10 + (c -
'0');
440 if (val > 1000000000)
443 * addr = neg ? -val : val;
452 bool_t neg = (
string[0] ==
'-');
456 const char * p = strchr (
string,
'.');
468 memcpy (buf,
string, len);
474 len = strlen (p + 1);
478 memcpy (buf, p + 1, len);
479 memset (buf + len,
'0', 6 - len);
493 double val = i + (double) f / 1000000;
494 if (val > 1000000000)
497 * addr = neg ? -val : val;
506 g_return_val_if_fail (val >= -1000000000 && val <= 1000000000,
NULL);
507 return g_strdup_printf (
"%d", val);
512 g_return_val_if_fail (val >= -1000000000 && val <= 1000000000,
NULL);
519 int f = round ((val - i) * 1000000);
527 char *
s = neg ? g_strdup_printf (
"-%d.%06d", i, f) : g_strdup_printf (
"%d.%06d", i, f);
529 char * c = s + strlen (s);
530 while (* (c - 1) ==
'0')
532 if (* (c - 1) ==
'.')
541 char * * split = g_strsplit (
string,
",", -1);
542 if (g_strv_length (split) != count)
545 for (
int i = 0; i < count; i ++)
561 char * * split = g_malloc0 (
sizeof (
char *) * (count + 1));
563 for (
int i = 0; i < count; i ++)
570 char *
string = g_strjoinv (
",", split);