1 #include <string.h>
2 #include <glib.h>
4 // FIXME: kill this ugliness when we have a proper CSS parser
6 // Functions as per 4.3.4 of CSS 2.1
7 // http://www.w3.org/TR/CSS21/syndata.html#uri
8 gchar *extract_uri(gchar const *s)
9 {
10 gchar* result = 0;
11 gchar const *sb = s;
12 g_assert( strncmp(sb, "url", 3) == 0 );
13 sb += 3;
15 // This first whitespace technically is not allowed.
16 // Just left in for now for legacy behavior.
17 while ( ( *sb == ' ' ) ||
18 ( *sb == '\t' ) )
19 {
20 sb++;
21 }
23 if ( *sb == '(' ) {
24 sb++;
25 while ( ( *sb == ' ' ) ||
26 ( *sb == '\t' ) )
27 {
28 sb++;
29 }
31 gchar delim = ')';
32 if ( (*sb == '\'' || *sb == '"') ) {
33 delim = *sb;
34 sb++;
35 }
36 gchar const* se = sb + 1;
37 while ( *se && (*se != delim) ) {
38 se++;
39 }
41 // we found the delimiter
42 if ( *se ) {
43 if ( delim == ')' ) {
44 // back up for any trailing whitespace
45 se--;
46 while ( ( se[-1] == ' ' ) ||
47 ( se[-1] == '\t' ) )
48 {
49 se--;
50 }
51 result = g_strndup(sb, se - sb + 1);
52 } else {
53 gchar const* tail = se + 1;
54 while ( ( *tail == ' ' ) ||
55 ( *tail == '\t' ) )
56 {
57 tail++;
58 }
59 if ( *tail == ')' ) {
60 result = g_strndup(sb, se - sb);
61 }
62 }
63 }
64 }
66 return result;
67 }
69 /*
70 Local Variables:
71 mode:c++
72 c-file-style:"stroustrup"
73 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74 indent-tabs-mode:nil
75 fill-column:99
76 End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :