The R Project SVN R

Rev

Rev 68948 | Rev 83003 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/utils/man/URLencode.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
67896 ripley 3
% Copyright 1995-2015 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
34323 ripley 6
\name{URLencode}
56186 murdoch 7
\alias{URLencode}
34323 ripley 8
\alias{URLdecode}
9
\title{Encode or Decode a (partial) URL}
10
\description{
69207 ripley 11
  Functions to percent-encode or decode characters in URLs.
34323 ripley 12
}
13
\usage{
67899 ripley 14
URLencode(URL, reserved = FALSE, repeated = FALSE)
34323 ripley 15
URLdecode(URL)
16
}
17
\arguments{
67899 ripley 18
  \item{URL}{a character string.}
19
  \item{reserved}{logical: should \sQuote{reserved} characters be
20
    encoded? See \sQuote{Details}.}
21
  \item{repeated}{logical: should apparently already-encoded URLs be
22
    encoded again?}
34323 ripley 23
}
24
\details{
34324 ripley 25
  Characters in a URL other than the English alphanumeric characters and
66302 hornik 26
  \samp{- _ . ~} should be encoded as \code{\%}
34324 ripley 27
  plus a two-digit hexadecimal representation, and any single-byte
67896 ripley 28
  character can be so encoded. (Multi-byte characters are encoded
69207 ripley 29
  byte-by-byte.)  The standard refers to this as \sQuote{percent-encoding}.
34354 maechler 30
 
66302 hornik 31
  In addition, \samp{! $ & ' ( ) * + , ; = : / ? @ # [ ]} are reserved
32
  characters, and should be encoded unless used in their reserved sense,
33
  which is scheme specific.  The default in \code{URLencode} is to leave
34
  them alone, which is appropriate for \samp{file://} URLs, but probably
35
  not for \samp{http://} ones.
67898 ripley 36
 
67899 ripley 37
  An \sQuote{apparently already-encoded URL} is one containing
38
  \code{\%xx} for two hexadecimal digits.
34323 ripley 39
}
40
\value{
41
  A character string.
42
}
43
\references{
68447 ripley 44
  Internet STD 66 (formerly RFC 3986),
45
  \url{https://tools.ietf.org/html/std66}
34323 ripley 46
}
47
\examples{
34324 ripley 48
(y <- URLencode("a url with spaces and / and @"))
49
URLdecode(y)
61160 ripley 50
(y <- URLencode("a url with spaces and / and @", reserved = TRUE))
34324 ripley 51
URLdecode(y)
67899 ripley 52
 
53
URLdecode(z <- "ab\%20cd")
54
c(URLencode(z), URLencode(z, repeated = TRUE)) # first is usually wanted
34323 ripley 55
}
56
\keyword{utilities}