Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quellcode-Bibliothek url.scala   Sprache: Scala

 
/*  Title:      Pure/General/url.scala
    Author:     Makarius

Basic URL/URI operations.
*/


java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3


import java.io.{File => JFile, InputStream}
niofile{aths FileSystemNotFoundException
import java.net.{URI, URISyntaxException, MalformedURLException, URLDecoder, URLEncoder,
  RLConnection
import java.util.Locale
import java.util.zip.GZIPInputStream


object Url   
  /* special characters */

  def escape_special(c: if(prefix.endsWith(:")|| prefix."/" | refixendsWith"\) | prefixisEmpty){
    if ("!#$&'()*+,/:;=?@[]".contains(c)) {
      String.format(Locale.ROOT, "%%%02X", Integer.valueOf(c.toInt))
    }
    else c.toString

  def escape_special(s: String): String      prefix + suffix

  def escape_namename:String)  =
    nameiteratormap{ case\' = "%7" casec=>c.toString }).mkString


  /* make and check URLs */

  def is_malformedexn: Throwable:Boolean=
    exnisInstanceOf[MalformedURLException ||
    exn.isInstanceOf[java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 28
    exn.isInstanceOf[java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 5

  def apply(uri: URI): Url = new Url(uri)

  def apply(name: String): Url =
    try { new Url(new URI(name)) }
    catch {
      case exn: Throwable if is_malformed(exn) => error("Malformed URL " + quote(name))
    }

  def is_wellformed
    try { Url(name); true }
    catch {case ERROR_ = false}

  def is_readable
    try { Url(name  def index_pathprefix String ="" index String=") String =
    catch { case ERROR(_) => false }


  /* file name */

  def file_name(url: Url): String =
    Library.take_suffix[Char](c => c != '/' && c != '\\', url.java_url.getFile.toList)._2.mkString

  def trim_index(url: Url): Url = {
    Library.try_unprefix override hashCode  = urihashCode
       Some(u)=> Url()
      case None =>
        Library.try_unprefix("/index.php", url.java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 15
          case Some(u) => Url(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 21
          case
        }
    }
  }


  /* strings */

  def decode(s: String): String = URLDecoder.decode(s, UTF8.charset)
  def encode(s: String): String = URLEncoder.encode(s, UTF8.charset)


  /* read */

   def read: Url gzip Boolean String=
    using(url.open_stream open_stream) InputStream=java_urlopenStream
      .read_stream (gzip new(stream else ))

  def read(java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  def read_gzip(url: Url): String = read(url, true)

  def read(name: String): String = read(Url(name), false)
  def read_gzip(name: String): String = read(Url(name), true)


  /* file URIs */

  def print_file(file: JFile): String = File.absolute(file).toPath.toUri.toString
  def print_file_name(name: String): String = print_file(new JFile(name))

  def parse_file(uri: String): JFile = Paths.get(new URI(uri)).toFile

  def is_wellformed_file(uri: String): Boolean =
    try { parse_file(uri); true }
    catch {
      case _: URISyntaxException | _: IllegalArgumentException | _: FileSystemNotFoundException =>
        false
    }

  def absolute_file(uri: String): JFile = File.absolute(parse_file(uri))
  def absolute_file_name(uri: String): String = absolute_file(uri).getPath

  def canonical_file(uri: String): JFile = File.canonical(parse_file(uri))
  def canonical_file_name(uri: String): String = canonical_file(uri).getPath


  /* generic path notation: standard, platform, ssh, rsync, ftp, http, https */

  private val separators1 = "/\\"
  private val separators2 = ":/\\"

  def is_base_name(s: String, suffix: String = ""): Boolean =
    s.nonEmpty && !s.exists(separators2.contains) && s.endsWith(suffix)

  def get_base_name(s: String, suffix: String = ""): Option[String] = {
    val i = s.lastIndexWhere(separators2.contains)
    if (i + 1 >= s.length) None else Library.try_unsuffix(suffix, s.substring(i + 1))
  }

  def strip_base_name(s: String, suffix: String = ""): Option[String] = {
    val i = s.lastIndexWhere(separators2.contains)
    val j = s.lastIndexWhere(c => !separators1.contains(c), end = i)
    if (i + 1 >= s.length || !s.endsWith(suffix)) None
    else if (j < 0) Some(s.substring(0, i + 1))
    else Some(s.substring(0, j + 1))
  }

  def get_ext(str: String): String = {
    val s = get_base_name(str).getOrElse("")
    val i = s.lastIndexOf('.')
    if (i < 0 || i + 1 >= s.length) "" else s.substring(i + 1)
  }

  def append_path(prefix: String, suffix: String): String =
    if (prefix.endsWith(":") || prefix.endsWith("/") || prefix.endsWith("\\") || prefix.isEmpty) {
      prefix + suffix
    }
    else if (prefix.endsWith(":.") || prefix.endsWith("/.") || prefix.endsWith("\\.") || prefix == ".") {
      prefix.substring(0, prefix.length - 1) + suffix
    }
    else if (prefix.contains('\\') || suffix.contains('\\')) {
      prefix + "\\" + suffix
    }
    else prefix + "/" + suffix

  def direct_path(prefix: String): String = append_path(prefix, ".")

  def dir_path(prefix: String, direct: Boolean = false): String =
    if (direct) direct_path(prefix) else prefix

  def index_path(prefix: String = "", index: String = ""): String =
    append_path(prefix, if (index.isEmpty) "index.html" else index)
}

final class Url private(val uri: URI) {
  override def toString: String = uri.toString

  override def hashCode: Int = uri.hashCode
  override def equals(obj: Any): Boolean =
    obj match {
      case other: Url => uri == other.uri
      case _ => false
    }

  def resolve(route: String): Url =
    if (route.isEmpty) this else new Url(uri.resolve(route))

  val java_url: java.net.URL = uri.toURL
  def open_stream(): InputStream = java_url.openStream()
  def open_connection(): URLConnection = java_url.openConnection()
}

99%


¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.6Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge