Code

remove memory boundries on bitmap renderer, optimize memory usage
[inkscape.git] / src / extract-uri.cpp
index b3923ed1e4dd64df75961b57e8c6b6affff7b627..76778bacb93748ff655a9fb0840fdaed1b9a8904 100644 (file)
@@ -5,7 +5,7 @@
 
 // Functions as per 4.3.4 of CSS 2.1
 // http://www.w3.org/TR/CSS21/syndata.html#uri
-gchar *extract_uri(gchar const *s)
+gchar *extract_uri( gchar const *s, gchar const** endptr )
 {
     if (!s)
         return NULL;
@@ -18,6 +18,10 @@ gchar *extract_uri(gchar const *s)
 
     sb += 3;
 
+    if ( endptr ) {
+        *endptr = 0;
+    }
+
     // This first whitespace technically is not allowed.
     // Just left in for now for legacy behavior.
     while ( ( *sb == ' ' ) ||
@@ -47,6 +51,10 @@ gchar *extract_uri(gchar const *s)
         // we found the delimiter
         if ( *se ) {
             if ( delim == ')' ) {
+                if ( endptr ) {
+                    *endptr = se + 1;
+                }
+
                 // back up for any trailing whitespace
                 se--;
                 while ( ( se[-1] == ' ' ) ||
@@ -54,6 +62,7 @@ gchar *extract_uri(gchar const *s)
                 {
                     se--;
                 }
+
                 result = g_strndup(sb, se - sb + 1);
             } else {
                 gchar const* tail = se + 1;
@@ -63,6 +72,9 @@ gchar *extract_uri(gchar const *s)
                     tail++;
                 }
                 if ( *tail == ')' ) {
+                    if ( endptr ) {
+                        *endptr = tail + 1;
+                    }
                     result = g_strndup(sb, se - sb);
                 }
             }
@@ -81,4 +93,4 @@ gchar *extract_uri(gchar const *s)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :