/*
7 * Authors: see git history
9 * Copyright (C) 2006-2024 Authors
10 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
27 if ( strlen(sb) < 4 || strncmp(sb,
"url", 3) != 0 ) {
39 while ( ( *sb ==
' ' ) ||
47 while ( ( *sb ==
' ' ) ||
54 if ( (*sb ==
'\'' || *sb ==
'"') ) {
64 while ( *se && (*se != delim) ) {
76 while (se > sb && g_ascii_isspace(se[-1]))
81 result = std::string(sb, se);
83 gchar
const* tail = se + 1;
84 while ( ( *tail ==
' ' ) ||
93 result = std::string(sb, se);
104 return link.empty() ? std::nullopt : std::make_optional(link);
109 if (!ret->empty() && (*ret)[0] ==
'#') {
119 bool data_is_base64 =
false;
120 bool data_is_image =
false;
121 bool data_is_svg =
false;
122 bool data_has_mime =
false;
124 gchar
const *
data = uri_data;
126 if ((*
data) && strncmp(
data,
"data:", 5) == 0) {
131 if (strncmp(
data,
"base64", 6) == 0) {
133 data_is_base64 =
true;
135 data_is_image = !data_has_mime;
138 else if (strncmp(
data,
"image/png", 9) == 0
139 || strncmp(
data,
"image/jpg", 9) == 0
140 || strncmp(
data,
"image/jp2", 9) == 0
141 || strncmp(
data,
"image/bmp", 9) == 0) {
143 data_is_image =
true;
146 else if (strncmp(
data,
"image/jpeg", 10) == 0
147 || strncmp(
data,
"image/tiff", 10) == 0) {
149 data_is_image =
true;
152 else if (strncmp(
data,
"image/svg+xml", 13) == 0) {
155 data_is_image =
true;
160 if (((*
data) ==
';') || ((*
data) ==
',')) {
163 if ((*
data) ==
'/') {
164 data_has_mime =
true;
169 if ((*
data) ==
';') {
173 if ((*
data) ==
',') {
178 if (data_is_base64 && data_is_image) {
std::tuple< char const *, Base64Data > extract_uri_data(char const *uri_data)
Attempt to extract the data in a data uri, but does not decode the base64.
std::string extract_uri(char const *s, char const **endptr)
Parse functional URI notation, as per 4.3.4 of CSS 2.1.
std::optional< std::string > try_extract_uri_id(const char *url)
Try extracting the object id from "url(#obj_id)" string using extract_uri.
std::optional< std::string > try_extract_uri(const char *url)
Try extracting URI from "url(xyz)" string using extract_uri.