Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/6f09b64c5931ae3615f38...
...commit
http://git.netsurf-browser.org/netsurf.git/commit/6f09b64c5931ae3615f3814...
...tree
http://git.netsurf-browser.org/netsurf.git/tree/6f09b64c5931ae3615f381436...
The branch, master has been updated
via 6f09b64c5931ae3615f381436558e82d01862ed3 (commit)
via 13832a453a6a4433b4dc62fb0092810671e8751e (commit)
via 3ff7557c34618d8e5d0dceccbbfafa2361712f69 (commit)
from 612100bd1a1690fb0884b1e6904c4ab2671ad023 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=6f09b64c5931ae3615f...
commit 6f09b64c5931ae3615f381436558e82d01862ed3
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add some nsurl_nice tests.
diff --git a/test/nsurl.c b/test/nsurl.c
index bd7dc80..49ccdba 100644
--- a/test/nsurl.c
+++ b/test/nsurl.c
@@ -165,6 +165,32 @@ static const struct test_pairs join_tests[] = {
{ NULL, NULL }
};
+static const struct test_pairs nice_tests[] = {
+ { "www.foo.org", "www_foo_org" },
+ { "www.foo.org/index.html", "www_foo_org" },
+ { "www.foo.org/default.en", "www_foo_org" },
+ { "www.foo.org/about", "about" },
+ { "www.foo.org/about.jpg", "about.jpg" },
+ { "www.foo.org/moose/index.en", "moose" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "http://www.f.org//index.en", "www_f_org" },
+ { NULL, NULL }
+};
+
+static const struct test_pairs nice_strip_tests[] = {
+ { "www.foo.org", "www_foo_org" },
+ { "www.foo.org/index.html", "www_foo_org" },
+ { "www.foo.org/default.en", "www_foo_org" },
+ { "www.foo.org/about", "about" },
+ { "www.foo.org/about.jpg", "about" },
+ { "www.foo.org/moose/index.en", "moose" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "http://www.f.org//index.en", "www_f_org" },
+ { NULL, NULL }
+};
+
static const struct test_triplets replace_query_tests[] = {
{ "http://netsurf-browser.org/?magical=true",
"?magical=true&result=win",
@@ -284,6 +310,74 @@ int main(void)
count++;
}
+ /* nice filename tests */
+ LOG(("Testing nsurl_nice (no strip)"));
+ for (test = nice_tests; test->test != NULL; test++) {
+ err = nsurl_create(test->test, &base);
+ if (err != NSERROR_OK) {
+ LOG(("Failed to create URL:\n\t\t%s.", test->test));
+ } else {
+ char *res;
+ err = nsurl_nice(base, &res, false);
+ if (err == NSERROR_OK && test->res != NULL) {
+ if (strcmp(res, test->res) == 0) {
+ LOG(("\tPASS: \"%s\"\t--> %s",
+ test->test, res));
+ passed++;
+ } else {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting %s", test->res));
+ }
+ free(res);
+ } else {
+ if (test->res == NULL && err == NSERROR_OK) {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting BAD_INPUT"));
+ free(res);
+ } else {
+ LOG(("\tFAIL: \"%s\"", test->test));
+ }
+ }
+ nsurl_unref(base);
+ }
+ count++;
+ }
+ LOG(("Testing nsurl_nice (strip)"));
+ for (test = nice_strip_tests; test->test != NULL; test++) {
+ err = nsurl_create(test->test, &base);
+ if (err != NSERROR_OK) {
+ LOG(("Failed to create URL:\n\t\t%s.", test->test));
+ } else {
+ char *res;
+ err = nsurl_nice(base, &res, true);
+ if (err == NSERROR_OK && test->res != NULL) {
+ if (strcmp(res, test->res) == 0) {
+ LOG(("\tPASS: \"%s\"\t--> %s",
+ test->test, res));
+ passed++;
+ } else {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting %s", test->res));
+ }
+ free(res);
+ } else {
+ if (test->res == NULL && err == NSERROR_OK) {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting BAD_INPUT"));
+ free(res);
+ } else {
+ LOG(("\tFAIL: \"%s\"", test->test));
+ }
+ }
+ nsurl_unref(base);
+ }
+ count++;
+ }
+
/* Replace query tests */
LOG(("Testing nsurl_replace_query"));
for (ttest = replace_query_tests; ttest->test1 != NULL; ttest++) {
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=13832a453a6a4433b4d...
commit 13832a453a6a4433b4dc62fb0092810671e8751e
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add a nsurl_nice, which can replace url_nice.
diff --git a/utils/nsurl.c b/utils/nsurl.c
index f5bb06f..7479e72 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -2209,6 +2209,110 @@ nserror nsurl_replace_query(const nsurl *url, const char *query,
}
+/* exported interface documented in utils/nsurl.h */
+nserror nsurl_nice(const nsurl *url, char **result, bool remove_extensions)
+{
+ char *dot;
+ const char *data;
+ size_t len;
+ size_t pos;
+ bool match;
+ char *name;
+
+ *result = 0;
+
+ /* extract the last component of the path, if possible */
+ if ((url->components.path != NULL) &&
+ lwc_string_length(url->components.path) != 0 &&
+ lwc_string_isequal(url->components.path,
+ corestring_lwc_slash_, &match) == lwc_error_ok &&
+ match != true) {
+ bool first = true;
+ bool keep_looking;
+
+ /* Get hold of the string data we're examining */
+ data = lwc_string_data(url->components.path);
+ len = lwc_string_length(url->components.path);
+ pos = len;
+
+ do {
+ keep_looking = false;
+ pos--;
+
+ /* Find last '/' with stuff after it */
+ while (pos != 0) {
+ if (data[pos] == '/' && pos < len - 1) {
+ break;
+ }
+ pos--;
+ }
+
+ if (pos == 0) {
+ break;
+ }
+
+ if (first) {
+ if (strncasecmp("/default.", data + pos,
+ SLEN("/default.")) == 0) {
+ keep_looking = true;
+
+ } else if (strncasecmp("/index.",
+ data + pos,
+ 6) == 0) {
+ keep_looking = true;
+
+ }
+ first = false;
+ }
+
+ } while (keep_looking);
+
+ if (data[pos] == '/')
+ pos++;
+
+ if (strncasecmp("default.", data + pos, 8) != 0 &&
+ strncasecmp("index.", data + pos, 6) != 0) {
+ size_t end = pos;
+ while (data[end] != '\0' && data[end] != '/') {
+ end++;
+ }
+ if (end - pos != 0) {
+ name = malloc(end - pos + 1);
+ if (name == NULL) {
+ return NSERROR_NOMEM;
+ }
+ memcpy(name, data + pos, end - pos);
+ name[end - pos] = '\0';
+ if (remove_extensions) {
+ /* strip any extenstion */
+ char *dot = strchr(name, '.');
+ if (dot && dot != name) {
+ *dot = '\0';
+ }
+ }
+ *result = name;
+ return NSERROR_OK;
+ }
+ }
+ }
+
+ if (url->components.host != NULL) {
+ name = strdup(lwc_string_data(url->components.host));
+
+ for (pos = 0; name[pos] != '\0'; pos++) {
+ if (name[pos] == '.') {
+ name[pos] = '_';
+ }
+ }
+
+ *result = name;
+ return NSERROR_OK;
+ }
+
+ return NSERROR_NOT_FOUND;
+}
+
+
/* exported interface, documented in nsurl.h */
nserror nsurl_parent(const nsurl *url, nsurl **new_url)
{
diff --git a/utils/nsurl.h b/utils/nsurl.h
index 435df73..ec00ded 100644
--- a/utils/nsurl.h
+++ b/utils/nsurl.h
@@ -285,6 +285,19 @@ nserror nsurl_replace_query(const nsurl *url, const char *query,
/**
+ * Attempt to find a nice filename for a URL.
+ *
+ * \param url A NetSurf URL object to create a filename from
+ * \param result Updated to caller-owned string with filename
+ * \param remove_extensions remove any extensions from the filename
+ * \return NSERROR_OK on success, appropriate error otherwise
+ *
+ * Caller must ensure string result string is freed, if NSERROR_OK returned.
+ */
+nserror nsurl_nice(const nsurl *url, char **result, bool remove_extensions);
+
+
+/**
* Create a NetSurf URL object for URL with parent location of an existing URL.
*
* \param url NetSurf URL to create new NetSurf URL from
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=3ff7557c34618d8e5d0...
commit 3ff7557c34618d8e5d0dceccbbfafa2361712f69
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add a lwc corestring for "/".
diff --git a/utils/corestrings.c b/utils/corestrings.c
index cb340e9..0f9c4d6 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -121,6 +121,7 @@ lwc_string *corestring_lwc__blank;
lwc_string *corestring_lwc__parent;
lwc_string *corestring_lwc__self;
lwc_string *corestring_lwc__top;
+lwc_string *corestring_lwc_slash_;
/* dom_string strings */
dom_string *corestring_dom_a;
@@ -380,6 +381,7 @@ void corestrings_fini(void)
CSS_LWC_STRING_UNREF(_parent);
CSS_LWC_STRING_UNREF(_self);
CSS_LWC_STRING_UNREF(_top);
+ CSS_LWC_STRING_UNREF(slash_);
#undef CSS_LWC_STRING_UNREF
@@ -687,6 +689,13 @@ nserror corestrings_init(void)
goto error;
}
+ lerror = lwc_intern_string("/", SLEN("/"),
+ &corestring_lwc_slash_);
+ if ((lerror != lwc_error_ok) || (corestring_lwc_slash_ == NULL)) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
#define CSS_DOM_STRING_INTERN(NAME) \
do { \
diff --git a/utils/corestrings.h b/utils/corestrings.h
index b41d1f8..9fcc224 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -126,6 +126,7 @@ extern lwc_string *corestring_lwc__blank;
extern lwc_string *corestring_lwc__parent;
extern lwc_string *corestring_lwc__self;
extern lwc_string *corestring_lwc__top;
+extern lwc_string *corestring_lwc_slash_; /* / */
struct dom_string;
-----------------------------------------------------------------------
Summary of changes:
test/nsurl.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++
utils/corestrings.c | 9 +++++
utils/corestrings.h | 1 +
utils/nsurl.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++
utils/nsurl.h | 13 +++++++
5 files changed, 221 insertions(+)
diff --git a/test/nsurl.c b/test/nsurl.c
index bd7dc80..49ccdba 100644
--- a/test/nsurl.c
+++ b/test/nsurl.c
@@ -165,6 +165,32 @@ static const struct test_pairs join_tests[] = {
{ NULL, NULL }
};
+static const struct test_pairs nice_tests[] = {
+ { "www.foo.org", "www_foo_org" },
+ { "www.foo.org/index.html", "www_foo_org" },
+ { "www.foo.org/default.en", "www_foo_org" },
+ { "www.foo.org/about", "about" },
+ { "www.foo.org/about.jpg", "about.jpg" },
+ { "www.foo.org/moose/index.en", "moose" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "http://www.f.org//index.en", "www_f_org" },
+ { NULL, NULL }
+};
+
+static const struct test_pairs nice_strip_tests[] = {
+ { "www.foo.org", "www_foo_org" },
+ { "www.foo.org/index.html", "www_foo_org" },
+ { "www.foo.org/default.en", "www_foo_org" },
+ { "www.foo.org/about", "about" },
+ { "www.foo.org/about.jpg", "about" },
+ { "www.foo.org/moose/index.en", "moose" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "http://www.f.org//index.en", "www_f_org" },
+ { NULL, NULL }
+};
+
static const struct test_triplets replace_query_tests[] = {
{ "http://netsurf-browser.org/?magical=true",
"?magical=true&result=win",
@@ -284,6 +310,74 @@ int main(void)
count++;
}
+ /* nice filename tests */
+ LOG(("Testing nsurl_nice (no strip)"));
+ for (test = nice_tests; test->test != NULL; test++) {
+ err = nsurl_create(test->test, &base);
+ if (err != NSERROR_OK) {
+ LOG(("Failed to create URL:\n\t\t%s.", test->test));
+ } else {
+ char *res;
+ err = nsurl_nice(base, &res, false);
+ if (err == NSERROR_OK && test->res != NULL) {
+ if (strcmp(res, test->res) == 0) {
+ LOG(("\tPASS: \"%s\"\t--> %s",
+ test->test, res));
+ passed++;
+ } else {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting %s", test->res));
+ }
+ free(res);
+ } else {
+ if (test->res == NULL && err == NSERROR_OK) {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting BAD_INPUT"));
+ free(res);
+ } else {
+ LOG(("\tFAIL: \"%s\"", test->test));
+ }
+ }
+ nsurl_unref(base);
+ }
+ count++;
+ }
+ LOG(("Testing nsurl_nice (strip)"));
+ for (test = nice_strip_tests; test->test != NULL; test++) {
+ err = nsurl_create(test->test, &base);
+ if (err != NSERROR_OK) {
+ LOG(("Failed to create URL:\n\t\t%s.", test->test));
+ } else {
+ char *res;
+ err = nsurl_nice(base, &res, true);
+ if (err == NSERROR_OK && test->res != NULL) {
+ if (strcmp(res, test->res) == 0) {
+ LOG(("\tPASS: \"%s\"\t--> %s",
+ test->test, res));
+ passed++;
+ } else {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting %s", test->res));
+ }
+ free(res);
+ } else {
+ if (test->res == NULL && err == NSERROR_OK) {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting BAD_INPUT"));
+ free(res);
+ } else {
+ LOG(("\tFAIL: \"%s\"", test->test));
+ }
+ }
+ nsurl_unref(base);
+ }
+ count++;
+ }
+
/* Replace query tests */
LOG(("Testing nsurl_replace_query"));
for (ttest = replace_query_tests; ttest->test1 != NULL; ttest++) {
diff --git a/utils/corestrings.c b/utils/corestrings.c
index cb340e9..0f9c4d6 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -121,6 +121,7 @@ lwc_string *corestring_lwc__blank;
lwc_string *corestring_lwc__parent;
lwc_string *corestring_lwc__self;
lwc_string *corestring_lwc__top;
+lwc_string *corestring_lwc_slash_;
/* dom_string strings */
dom_string *corestring_dom_a;
@@ -380,6 +381,7 @@ void corestrings_fini(void)
CSS_LWC_STRING_UNREF(_parent);
CSS_LWC_STRING_UNREF(_self);
CSS_LWC_STRING_UNREF(_top);
+ CSS_LWC_STRING_UNREF(slash_);
#undef CSS_LWC_STRING_UNREF
@@ -687,6 +689,13 @@ nserror corestrings_init(void)
goto error;
}
+ lerror = lwc_intern_string("/", SLEN("/"),
+ &corestring_lwc_slash_);
+ if ((lerror != lwc_error_ok) || (corestring_lwc_slash_ == NULL)) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
#define CSS_DOM_STRING_INTERN(NAME) \
do { \
diff --git a/utils/corestrings.h b/utils/corestrings.h
index b41d1f8..9fcc224 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -126,6 +126,7 @@ extern lwc_string *corestring_lwc__blank;
extern lwc_string *corestring_lwc__parent;
extern lwc_string *corestring_lwc__self;
extern lwc_string *corestring_lwc__top;
+extern lwc_string *corestring_lwc_slash_; /* / */
struct dom_string;
diff --git a/utils/nsurl.c b/utils/nsurl.c
index f5bb06f..7479e72 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -2209,6 +2209,110 @@ nserror nsurl_replace_query(const nsurl *url, const char *query,
}
+/* exported interface documented in utils/nsurl.h */
+nserror nsurl_nice(const nsurl *url, char **result, bool remove_extensions)
+{
+ char *dot;
+ const char *data;
+ size_t len;
+ size_t pos;
+ bool match;
+ char *name;
+
+ *result = 0;
+
+ /* extract the last component of the path, if possible */
+ if ((url->components.path != NULL) &&
+ lwc_string_length(url->components.path) != 0 &&
+ lwc_string_isequal(url->components.path,
+ corestring_lwc_slash_, &match) == lwc_error_ok &&
+ match != true) {
+ bool first = true;
+ bool keep_looking;
+
+ /* Get hold of the string data we're examining */
+ data = lwc_string_data(url->components.path);
+ len = lwc_string_length(url->components.path);
+ pos = len;
+
+ do {
+ keep_looking = false;
+ pos--;
+
+ /* Find last '/' with stuff after it */
+ while (pos != 0) {
+ if (data[pos] == '/' && pos < len - 1) {
+ break;
+ }
+ pos--;
+ }
+
+ if (pos == 0) {
+ break;
+ }
+
+ if (first) {
+ if (strncasecmp("/default.", data + pos,
+ SLEN("/default.")) == 0) {
+ keep_looking = true;
+
+ } else if (strncasecmp("/index.",
+ data + pos,
+ 6) == 0) {
+ keep_looking = true;
+
+ }
+ first = false;
+ }
+
+ } while (keep_looking);
+
+ if (data[pos] == '/')
+ pos++;
+
+ if (strncasecmp("default.", data + pos, 8) != 0 &&
+ strncasecmp("index.", data + pos, 6) != 0) {
+ size_t end = pos;
+ while (data[end] != '\0' && data[end] != '/') {
+ end++;
+ }
+ if (end - pos != 0) {
+ name = malloc(end - pos + 1);
+ if (name == NULL) {
+ return NSERROR_NOMEM;
+ }
+ memcpy(name, data + pos, end - pos);
+ name[end - pos] = '\0';
+ if (remove_extensions) {
+ /* strip any extenstion */
+ char *dot = strchr(name, '.');
+ if (dot && dot != name) {
+ *dot = '\0';
+ }
+ }
+ *result = name;
+ return NSERROR_OK;
+ }
+ }
+ }
+
+ if (url->components.host != NULL) {
+ name = strdup(lwc_string_data(url->components.host));
+
+ for (pos = 0; name[pos] != '\0'; pos++) {
+ if (name[pos] == '.') {
+ name[pos] = '_';
+ }
+ }
+
+ *result = name;
+ return NSERROR_OK;
+ }
+
+ return NSERROR_NOT_FOUND;
+}
+
+
/* exported interface, documented in nsurl.h */
nserror nsurl_parent(const nsurl *url, nsurl **new_url)
{
diff --git a/utils/nsurl.h b/utils/nsurl.h
index 435df73..ec00ded 100644
--- a/utils/nsurl.h
+++ b/utils/nsurl.h
@@ -285,6 +285,19 @@ nserror nsurl_replace_query(const nsurl *url, const char *query,
/**
+ * Attempt to find a nice filename for a URL.
+ *
+ * \param url A NetSurf URL object to create a filename from
+ * \param result Updated to caller-owned string with filename
+ * \param remove_extensions remove any extensions from the filename
+ * \return NSERROR_OK on success, appropriate error otherwise
+ *
+ * Caller must ensure string result string is freed, if NSERROR_OK returned.
+ */
+nserror nsurl_nice(const nsurl *url, char **result, bool remove_extensions);
+
+
+/**
* Create a NetSurf URL object for URL with parent location of an existing URL.
*
* \param url NetSurf URL to create new NetSurf URL from
--
NetSurf Browser