From: Toni Gundogdu Date: Mon, 14 Oct 2013 13:09:15 +0000 (+0300) Subject: Add misc/url.* with m_url_(un)escaped_form X-Git-Tag: v0.9.4~4^2~9 X-Git-Url: https://repo.or.cz/w/libquvi.git/commitdiff_plain/4a626abb7253bbb350f5f5ae0e5f507243e88471 Add misc/url.* with m_url_(un)escaped_form Signed-off-by: Toni Gundogdu --- diff --git a/src/misc/Makefile.am b/src/misc/Makefile.am index 89b123f..5fa82f5 100644 --- a/src/misc/Makefile.am +++ b/src/misc/Makefile.am @@ -15,7 +15,8 @@ src=\ subtitle.c\ subtitle_export.c\ to_utf8.c\ - trim.c + trim.c\ + url.c hdr=\ match_media_script.h\ @@ -30,7 +31,8 @@ hdr=\ script_free.h\ slst.h\ subtitle_export.h\ - subtitle.h + subtitle.h\ + url.h noinst_LTLIBRARIES=libconvenience_misc.la libconvenience_misc_la_SOURCES=$(src) $(hdr) diff --git a/src/misc/url.c b/src/misc/url.c new file mode 100644 index 0000000..ed8562a --- /dev/null +++ b/src/misc/url.c @@ -0,0 +1,60 @@ +/* libquvi + * Copyright (C) 2013 Toni Gundogdu + * + * This file is part of libquvi . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see + * . + */ + +#include "config.h" + +#include +/* -- */ +#include "misc/url.h" + +static gboolean _is_unescaped(const gchar *s) +{ + gboolean r; + gchar *u; + u = g_uri_unescape_string(s, NULL); + r = g_strcmp0(u,s) == 0 ? TRUE:FALSE; + g_free(u); + return (r); +} + +gchar *m_url_unescaped_form(const gchar *s) +{ + gchar *r = g_strdup(s); + do + { + gchar *u = g_uri_unescape_string(r, NULL); + g_free(r); + r = u; + } + while (_is_unescaped(r) == FALSE); + return (r); +} + +gchar *m_url_escaped_form(const gchar *s) +{ + static const gchar *reserved_chars = "!*'();:@&=+$,/?#[]"; + gchar *u, *r; + u = m_url_unescaped_form(s); + r = g_uri_escape_string(u, reserved_chars, FALSE); + g_free(u); + return (r); +} + +/* vim: set ts=2 sw=2 tw=72 expandtab: */ diff --git a/src/misc/url.h b/src/misc/url.h new file mode 100644 index 0000000..621ac1c --- /dev/null +++ b/src/misc/url.h @@ -0,0 +1,29 @@ +/* libquvi + * Copyright (C) 2013 Toni Gundogdu + * + * This file is part of libquvi . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see + * . + */ + +#ifndef m_url_h +#define m_url_h + +gchar *m_url_unescaped_form(const gchar*); +gchar *m_url_escaped_form(const gchar*); + +#endif /* m_url_h */ + +/* vim: set ts=2 sw=2 tw=72 expandtab: */