src/Pure/General/url.scala
changeset 75393 87ebf5a50283
parent 73417 1dcc2b228b8b
child 76354 908433a347d1
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
    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.Locale
    14 import java.util.zip.GZIPInputStream
    14 import java.util.zip.GZIPInputStream
    15 
    15 
    16 
    16 
    17 object Url
    17 object Url {
    18 {
       
    19   /* special characters */
    18   /* special characters */
    20 
    19 
    21   def escape_special(c: Char): String =
    20   def escape_special(c: Char): String =
    22     if ("!#$&'()*+,/:;=?@[]".contains(c)) {
    21     if ("!#$&'()*+,/:;=?@[]".contains(c)) {
    23       String.format(Locale.ROOT, "%%%02X", Integer.valueOf(c.toInt))
    22       String.format(Locale.ROOT, "%%%02X", Integer.valueOf(c.toInt))
    30     name.iterator.map({ case '\'' => "%27" case c => c.toString }).mkString
    29     name.iterator.map({ case '\'' => "%27" case c => c.toString }).mkString
    31 
    30 
    32 
    31 
    33   /* make and check URLs */
    32   /* make and check URLs */
    34 
    33 
    35   def apply(name: String): URL =
    34   def apply(name: String): URL = {
    36   {
       
    37     try { new URL(name) }
    35     try { new URL(name) }
    38     catch { case _: MalformedURLException => error("Malformed URL " + quote(name)) }
    36     catch { case _: MalformedURLException => error("Malformed URL " + quote(name)) }
    39   }
    37   }
    40 
    38 
    41   def is_wellformed(name: String): Boolean =
    39   def is_wellformed(name: String): Boolean =
    50   /* file name */
    48   /* file name */
    51 
    49 
    52   def file_name(url: URL): String =
    50   def file_name(url: URL): String =
    53     Library.take_suffix[Char](c => c != '/' && c != '\\', url.getFile.toString.toList)._2.mkString
    51     Library.take_suffix[Char](c => c != '/' && c != '\\', url.getFile.toString.toList)._2.mkString
    54 
    52 
    55   def trim_index(url: URL): URL =
    53   def trim_index(url: URL): URL = {
    56   {
       
    57     Library.try_unprefix("/index.html", url.toString) match {
    54     Library.try_unprefix("/index.html", url.toString) match {
    58       case Some(u) => Url(u)
    55       case Some(u) => Url(u)
    59       case None =>
    56       case None =>
    60         Library.try_unprefix("/index.php", url.toString) match {
    57         Library.try_unprefix("/index.php", url.toString) match {
    61           case Some(u) => Url(u)
    58           case Some(u) => Url(u)