Skip to content

Commit

Permalink
1.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ironholds committed Jun 19, 2015
1 parent 78df7cd commit a3f9ddb
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 49 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: urltools
Type: Package
Title: Vectorised Tools for URL Handling and Parsing
Version: 1.1.1
Date: 2015-04-11
Version: 1.2.0
Date: 2015-06-18
Author: Oliver Keyes [aut, cre], Jay Jacobs [aut, cre], Mark Greenaway [ctb]
Maintainer: Oliver Keyes <ironholds@gmail.com>
Description: A toolkit for handling URLs that so far includes functions for URL
Expand All @@ -13,8 +13,7 @@ Description: A toolkit for handling URLs that so far includes functions for URL
URLs.
License: MIT + file LICENSE
LinkingTo:
Rcpp,
rope
Rcpp
Imports:
Rcpp,
methods
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

export("domain<-")
export("fragment<-")
export("parameters<-")
export("path<-")
export("port<-")
export("query<-")
export("scheme<-")
export(domain)
export(fragment)
export(parameters)
export(path)
export(port)
export(query)
export(scheme)
export(suffix_extract)
export(url_compose)
Expand Down
4 changes: 2 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Version 1.2.0 [WIP]
Version 1.2.0
-------------------------------------------------------------------------

NEW FEATURES
* Jay Jacobs' "tldextract" functionality has been merged with urltools, and can be accessed
with "suffix_extract"

* At Nicolas Coutin's suggestion, url_compose - url_parse in reverse - has been introduced.

BUG FIXES

* To adhere to RfC standards, "query" functions have been renamed "parameter"
* A bug in which fragments could not be retrieved (and were incorrectly identified as parameters)
has been fixed. Thanks to Nicolas Coutin for reporting it and providing a reproducible example.

Expand Down
52 changes: 38 additions & 14 deletions R/accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#'@param x a URL, or vector of URLs
#'
#'@param value a replacement value for x's scheme.
#'
#'@seealso \code{\link{domain}}, \code{\link{port}}, \code{\link{path}},
#'\code{\link{parameters}} and \code{\link{fragment}} for other accessors.
#'
#'@examples
#'#Get a component
#'example_url <- "http://cran.r-project.org/submit.html"
Expand All @@ -20,6 +24,7 @@
scheme <- function(x){
return(get_component_(x,0))
}

"scheme<-" <- function(x, value) standardGeneric("scheme<-")
#'@rdname scheme
#'@export
Expand All @@ -38,6 +43,9 @@ setGeneric("scheme<-", useAsDefault = function(x, value){
#'
#'@param value a replacement value for x's scheme.
#'
#'@seealso \code{\link{scheme}}, \code{\link{port}}, \code{\link{path}},
#'\code{\link{parameters}} and \code{\link{fragment}} for other accessors.
#'
#'@examples
#'#Get a component
#'example_url <- "http://cran.r-project.org/submit.html"
Expand All @@ -60,12 +68,16 @@ setGeneric("domain<-", useAsDefault = function(x, value){
#'@description as in the lubridate package, individual components of a URL
#'can be both extracted or set using the relevant function call - see the
#'examples.
#'
#'@aliases port
#'@rdname port
#'
#'@param x a URL, or vector of URLs
#'
#'@param value a replacement value for x's scheme.
#'@param value a replacement value for x's port.
#'
#'@seealso \code{\link{scheme}}, \code{\link{domain}}, \code{\link{path}},
#'\code{\link{parameters}} and \code{\link{fragment}} for other accessors.
#'
#'@examples
#'#Get a component
Expand Down Expand Up @@ -94,7 +106,10 @@ setGeneric("port<-", useAsDefault = function(x, value){
#'
#'@param x a URL, or vector of URLs
#'
#'@param value a replacement value for x's scheme.
#'@param value a replacement value for x's path
#'
#'@seealso \code{\link{scheme}}, \code{\link{domain}}, \code{\link{port}},
#'\code{\link{parameters}} and \code{\link{fragment}} for other accessors.
#'
#'@examples
#'#Get a component
Expand All @@ -114,36 +129,41 @@ setGeneric("path<-", useAsDefault = function(x, value){
return(set_component_(x, 3, value))
})

#'@title Get or set a URL's query string
#'@title Get or set a URL's parameters
#'@description as in the lubridate package, individual components of a URL
#'can be both extracted or set using the relevant function call - see the
#'examples.
#'@aliases query
#'@rdname query
#'
#'@aliases parameters
#'@rdname parameters
#'
#'@param x a URL, or vector of URLs
#'
#'@param value a replacement value for x's scheme.
#'@param value a replacement value for x's parameters.
#'
#'@seealso \code{\link{scheme}}, \code{\link{domain}}, \code{\link{port}},
#'\code{\link{path}} and \code{\link{fragment}} for other accessors.
#'
#'@examples
#'#Get a component
#'example_url <- "http://en.wikipedia.org/wiki/Aaron_Halfaker?debug=true"
#'query(example_url)
#'parameters(example_url)
#'#[1] "debug=true"
#'
#'#Set a component
#'query(example_url) <- "debug=false"
#'parameters(example_url) <- "debug=false"
#'@export
query <- function(x){
parameters <- function(x){
return(get_component_(x,4))
}
"query<-" <- function(x, value) standardGeneric("query<-")
#'@rdname query
"parameters<-" <- function(x, value) standardGeneric("parameters<-")
#'@rdname parameters
#'@export
setGeneric("query<-", useAsDefault = function(x, value){
setGeneric("parameters<-", useAsDefault = function(x, value){
return(set_component_(x, 4, value))
})

#'@title Get or set a URL's fragment identifier
#'@title Get or set a URL's fragment
#'@description as in the lubridate package, individual components of a URL
#'can be both extracted or set using the relevant function call - see the
#'examples.
Expand All @@ -152,7 +172,10 @@ setGeneric("query<-", useAsDefault = function(x, value){
#'
#'@param x a URL, or vector of URLs
#'
#'@param value a replacement value for x's scheme.
#'@param value a replacement value for x's fragment.
#'
#'@seealso \code{\link{scheme}}, \code{\link{domain}}, \code{\link{port}},
#'\code{\link{path}} and \code{\link{parameters}} for other accessors.
#'
#'@examples
#'#Get a component
Expand All @@ -167,6 +190,7 @@ setGeneric("query<-", useAsDefault = function(x, value){
fragment <- function(x){
return(get_component_(x,5))
}

"fragment<-" <- function(x, value) standardGeneric("fragment<-")
#'@rdname fragment
#'@export
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ The latest CRAN version can be obtained via:

The latest maintenance version:

devtools::install_github("ironholds/urltools", ref = "1.1.1")
devtools::install_github("ironholds/urltools", ref = "1.2.0")

To get the development version:

devtools::install_github("ironholds/urltools")

Please note that the development version depends on the experimental [rope](https://github.com/Ironholds/rope)
package.

###Dependencies
* R. Doy.
* [Rcpp](http://cran.rstudio.com/web/packages/Rcpp/)
4 changes: 4 additions & 0 deletions man/domain.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ domain(example_url)
#Set a component
domain(example_url) <- "en.wikipedia.org"
}
\seealso{
\code{\link{scheme}}, \code{\link{port}}, \code{\link{path}},
\code{\link{parameters}} and \code{\link{fragment}} for other accessors.
}

8 changes: 6 additions & 2 deletions man/fragment.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
\name{fragment}
\alias{fragment}
\alias{fragment<-}
\title{Get or set a URL's fragment identifier}
\title{Get or set a URL's fragment}
\usage{
fragment(x)
Expand All @@ -12,7 +12,7 @@ fragment(x) <- value
\arguments{
\item{x}{a URL, or vector of URLs}
\item{value}{a replacement value for x's scheme.}
\item{value}{a replacement value for x's fragment.}
}
\description{
as in the lubridate package, individual components of a URL
Expand All @@ -27,4 +27,8 @@ fragment(example_url)
#Set a component
fragment(example_url) <- "production"
}
\seealso{
\code{\link{scheme}}, \code{\link{domain}}, \code{\link{port}},
\code{\link{path}} and \code{\link{parameters}} for other accessors.
}

23 changes: 14 additions & 9 deletions man/query.Rd → man/parameters.Rd
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/accessors.R
\name{query}
\alias{query}
\alias{query<-}
\title{Get or set a URL's query string}
\name{parameters}
\alias{parameters}
\alias{parameters<-}
\title{Get or set a URL's parameters}
\usage{
query(x)
parameters(x)
query(x) <- value
parameters(x) <- value
}
\arguments{
\item{x}{a URL, or vector of URLs}
\item{value}{a replacement value for x's scheme.}
\item{value}{a replacement value for x's parameters.}
}
\description{
as in the lubridate package, individual components of a URL
Expand All @@ -22,9 +22,14 @@ examples.
\examples{
#Get a component
example_url <- "http://en.wikipedia.org/wiki/Aaron_Halfaker?debug=true"
query(example_url)
parameters(example_url)
#[1] "debug=true"

#Set a component
query(example_url) <- "debug=false"
parameters(example_url) <- "debug=false"
}
\seealso{
\code{\link{scheme}}, \code{\link{domain}}, \code{\link{port}},
\code{\link{path}} and \code{\link{fragment}} for other accessors.
}

6 changes: 5 additions & 1 deletion man/path.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ path(x) <- value
\arguments{
\item{x}{a URL, or vector of URLs}
\item{value}{a replacement value for x's scheme.}
\item{value}{a replacement value for x's path}
}
\description{
as in the lubridate package, individual components of a URL
Expand All @@ -27,4 +27,8 @@ path(example_url)
#Set a component
path(example_url) <- "bin/windows/"
}
\seealso{
\code{\link{scheme}}, \code{\link{domain}}, \code{\link{port}},
\code{\link{parameters}} and \code{\link{fragment}} for other accessors.
}

6 changes: 5 additions & 1 deletion man/port.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ port(x) <- value
\arguments{
\item{x}{a URL, or vector of URLs}
\item{value}{a replacement value for x's scheme.}
\item{value}{a replacement value for x's port.}
}
\description{
as in the lubridate package, individual components of a URL
Expand All @@ -27,4 +27,8 @@ port(example_url)
#Set a component
port(example_url) <- "12"
}
\seealso{
\code{\link{scheme}}, \code{\link{domain}}, \code{\link{path}},
\code{\link{parameters}} and \code{\link{fragment}} for other accessors.
}

4 changes: 4 additions & 0 deletions man/scheme.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ scheme(example_url)
#Set a component
scheme(example_url) <- "https"
}
\seealso{
\code{\link{domain}}, \code{\link{port}}, \code{\link{path}},
\code{\link{parameters}} and \code{\link{fragment}} for other accessors.
}

12 changes: 11 additions & 1 deletion src/parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ std::string parsing::scheme(std::string& url){
return output;
}

std::string parsing::string_tolower(std::string str){
unsigned int input_size = str.size();
for(unsigned int i = 0; i < input_size; i++){
str[i] = tolower(str[i]);
}
return str;
}

std::vector < std::string > parsing::domain_and_port(std::string& url){

std::vector < std::string > output(2);
Expand Down Expand Up @@ -128,7 +136,9 @@ std::string parsing::get_component(std::string& url, int component){
std::string parsing::set_component(std::string url, int component, std::string new_value){
std::string url_cp = url;
std::string parsed_url_elem = url_to_vector(url)[component];
url_cp = string_replace(url_cp, parsed_url_elem, new_value);
if(parsed_url_elem.size() != 0){
url_cp.replace(url_cp.find(parsed_url_elem), parsed_url_elem.size(), new_value);
}
return url_cp;
}

Expand Down
4 changes: 1 addition & 3 deletions src/parsing.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#include <Rcpp.h>
//[[Rcpp::depends(rope)]]
#include <rope/case.h>
#include <rope/replace.h>
using namespace Rcpp;

#ifndef __PARSING_INCLUDED__
Expand All @@ -11,6 +8,7 @@ class parsing{

private:

std::string string_tolower(std::string str);
/**
* A function for extracting the scheme of a URL; part of the
* URL parsing framework.
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_get_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("Check elements can be retrieved", {
expect_that(domain(url), equals("www.google.com"))
expect_that(port(url), equals("80"))
expect_that(path(url), equals("foo.php"))
expect_that(query(url), equals("api_params=turnip"))
expect_that(parameters(url), equals("api_params=turnip"))
expect_that(fragment(url), equals("ending"))
})

Expand All @@ -20,8 +20,8 @@ test_that("Check elements can be set", {
expect_that(port(url), equals("23"))
path(url) <- "bar.php"
expect_that(path(url), equals("bar.php"))
query(url) <- "api_params=manic"
expect_that(query(url), equals("api_params=manic"))
parameters(url) <- "api_params=manic"
expect_that(parameters(url), equals("api_params=manic"))
fragment(url) <- "beginning"
expect_that(fragment(url), equals("beginning"))
})
2 changes: 1 addition & 1 deletion urltools.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ LaTeX: pdfLaTeX
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageCheckArgs: --no-manual --as-cran --use-valgrind --check-subdirs=yes --timings --no-clean
PackageCheckArgs: --no-manual --as-cran --check-subdirs=yes --timings --no-clean
PackageRoxygenize: rd,collate,namespace
Loading

0 comments on commit a3f9ddb

Please sign in to comment.