src/Pure/General/url.scala
changeset 69901 20b32ade0024
parent 69394 f3240f3aa698
child 71163 b5822f4c3fde
equal deleted inserted replaced
69900:18a61caf5e68 69901:20b32ade0024
     8 
     8 
     9 
     9 
    10 import java.io.{File => JFile}
    10 import java.io.{File => JFile}
    11 import java.nio.file.{Paths, FileSystemNotFoundException}
    11 import java.nio.file.{Paths, FileSystemNotFoundException}
    12 import java.net.{URI, URISyntaxException, URL, MalformedURLException, URLDecoder, URLEncoder}
    12 import java.net.{URI, URISyntaxException, URL, MalformedURLException, URLDecoder, URLEncoder}
       
    13 import java.util.Locale
    13 import java.util.zip.GZIPInputStream
    14 import java.util.zip.GZIPInputStream
    14 
    15 
    15 
    16 
    16 object Url
    17 object Url
    17 {
    18 {
    18   def escape(name: String): String =
    19   /* special characters */
    19     (for (c <- name.iterator) yield if (c == '\'') "%27" else new String(Array(c))).mkString
    20 
       
    21   def escape_special(c: Char): String =
       
    22     if ("!#$&'()*+,/:;=?@[]".contains(c)) String.format(Locale.ROOT, "%%%02X", new Integer(c.toInt))
       
    23     else c.toString
       
    24 
       
    25   def escape_special(s: String): String = s.iterator.map(escape_special(_)).mkString
       
    26 
       
    27   def escape_name(name: String): String =
       
    28     name.iterator.map({ case '\'' => "%27" case c => c.toString }).mkString
       
    29 
       
    30 
       
    31   /* make and check URLs */
    20 
    32 
    21   def apply(name: String): URL =
    33   def apply(name: String): URL =
    22   {
    34   {
    23     try { new URL(name) }
    35     try { new URL(name) }
    24     catch { case _: MalformedURLException => error("Malformed URL " + quote(name)) }
    36     catch { case _: MalformedURLException => error("Malformed URL " + quote(name)) }