~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/extract-uri.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <glib.h>
3
3
 
4
4
// FIXME: kill this ugliness when we have a proper CSS parser
5
 
gchar *extract_uri(gchar const *s)
 
5
 
 
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, gchar const** endptr )
6
9
{
 
10
    if (!s)
 
11
        return NULL;
 
12
 
 
13
    gchar* result = NULL;
7
14
    gchar const *sb = s;
8
 
    g_assert( strncmp(sb, "url", 3) == 0 );
 
15
    if ( strlen(sb) < 4 || strncmp(sb, "url", 3) != 0 ) {
 
16
        return NULL;
 
17
    }
 
18
 
9
19
    sb += 3;
10
20
 
 
21
    if ( endptr ) {
 
22
        *endptr = 0;
 
23
    }
 
24
 
 
25
    // This first whitespace technically is not allowed.
 
26
    // Just left in for now for legacy behavior.
11
27
    while ( ( *sb == ' ' ) ||
12
 
            ( *sb == '(' ) )
13
 
    {
14
 
        sb++;
15
 
    }
16
 
 
17
 
    gchar const *se = sb + strlen(sb);
18
 
    while ( ( se[-1] == ' ' ) ||
19
 
            ( se[-1] == ')' ) )
20
 
    {
21
 
        se--;
22
 
    }
23
 
 
24
 
    if ( sb < se ) {
25
 
        return g_strndup(sb, se - sb);
26
 
    } else {
27
 
        return NULL;
28
 
    }
 
28
            ( *sb == '\t' ) )
 
29
    {
 
30
        sb++;
 
31
    }
 
32
 
 
33
    if ( *sb == '(' ) {
 
34
        sb++;
 
35
        while ( ( *sb == ' ' ) ||
 
36
                ( *sb == '\t' ) )
 
37
        {
 
38
            sb++;
 
39
        }
 
40
 
 
41
        gchar delim = ')';
 
42
        if ( (*sb == '\'' || *sb == '"') ) {
 
43
            delim = *sb;
 
44
            sb++;
 
45
        }
 
46
        gchar const* se = sb + 1;
 
47
        while ( *se && (*se != delim) ) {
 
48
            se++;
 
49
        }
 
50
 
 
51
        // we found the delimiter
 
52
        if ( *se ) {
 
53
            if ( delim == ')' ) {
 
54
                if ( endptr ) {
 
55
                    *endptr = se + 1;
 
56
                }
 
57
 
 
58
                // back up for any trailing whitespace
 
59
                se--;
 
60
                while ( ( se[-1] == ' ' ) ||
 
61
                        ( se[-1] == '\t' ) )
 
62
                {
 
63
                    se--;
 
64
                }
 
65
 
 
66
                result = g_strndup(sb, se - sb + 1);
 
67
            } else {
 
68
                gchar const* tail = se + 1;
 
69
                while ( ( *tail == ' ' ) ||
 
70
                        ( *tail == '\t' ) )
 
71
                {
 
72
                    tail++;
 
73
                }
 
74
                if ( *tail == ')' ) {
 
75
                    if ( endptr ) {
 
76
                        *endptr = tail + 1;
 
77
                    }
 
78
                    result = g_strndup(sb, se - sb);
 
79
                }
 
80
            }
 
81
        }
 
82
    }
 
83
 
 
84
    return result;
29
85
}
30
86
 
31
87
/*