summaryrefslogtreecommitdiffstats
path: root/src/extract-uri.cpp
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2018-12-13 20:43:49 +0000
committerThomas Holder <thomas@thomas-holder.de>2018-12-13 20:43:49 +0000
commitd4312f7cac4f6947719cda047645024a34c8795e (patch)
tree180cea4ed59fbca47eb3740f8b8a940e18a97e25 /src/extract-uri.cpp
parentremove most of Inkscape::URI::Impl (diff)
downloadinkscape-d4312f7cac4f6947719cda047645024a34c8795e.tar.gz
inkscape-d4312f7cac4f6947719cda047645024a34c8795e.zip
extract_uri: fix, test, document
Diffstat (limited to 'src/extract-uri.cpp')
-rw-r--r--src/extract-uri.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/extract-uri.cpp b/src/extract-uri.cpp
index 228e0c1c9..65401df6e 100644
--- a/src/extract-uri.cpp
+++ b/src/extract-uri.cpp
@@ -16,15 +16,16 @@
// 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 const** endptr )
+std::string extract_uri(char const *s, char const **endptr)
{
+ std::string result;
+
if (!s)
- return nullptr;
+ return result;
- gchar* result = nullptr;
gchar const *sb = s;
if ( strlen(sb) < 4 || strncmp(sb, "url", 3) != 0 ) {
- return nullptr;
+ return result;
}
sb += 3;
@@ -54,7 +55,12 @@ gchar *extract_uri( gchar const *s, gchar const** endptr )
delim = *sb;
sb++;
}
- gchar const* se = sb + 1;
+
+ if (!*sb) {
+ return result;
+ }
+
+ gchar const* se = sb;
while ( *se && (*se != delim) ) {
se++;
}
@@ -67,14 +73,12 @@ gchar *extract_uri( gchar const *s, gchar const** endptr )
}
// back up for any trailing whitespace
- se--;
- while ( ( se[-1] == ' ' ) ||
- ( se[-1] == '\t' ) )
+ while (se > sb && g_ascii_isspace(se[-1]))
{
se--;
}
- result = g_strndup(sb, se - sb + 1);
+ result = std::string(sb, se);
} else {
gchar const* tail = se + 1;
while ( ( *tail == ' ' ) ||
@@ -86,7 +90,7 @@ gchar *extract_uri( gchar const *s, gchar const** endptr )
if ( endptr ) {
*endptr = tail + 1;
}
- result = g_strndup(sb, se - sb);
+ result = std::string(sb, se);
}
}
}