basic setup for Isabelle charset;
authorwenzelm
Thu Jun 23 10:58:29 2011 +0200 (2011-06-23)
changeset 4351787ec9a1c0f98
parent 43516 1c4736b9396a
child 43518 7cad71ca9bcc
basic setup for Isabelle charset;
src/Pure/System/isabelle_charset.scala
src/Pure/build-jars
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/System/isabelle_charset.scala	Thu Jun 23 10:58:29 2011 +0200
     1.3 @@ -0,0 +1,50 @@
     1.4 +/*  Title:      Pure/System/isabelle_charset.scala
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Charset for Isabelle symbols.
     1.8 +*/
     1.9 +
    1.10 +package isabelle
    1.11 +
    1.12 +import java.nio.Buffer
    1.13 +import java.nio.{ByteBuffer, CharBuffer}
    1.14 +import java.nio.charset.{Charset, CharsetDecoder, CharsetEncoder, CoderResult}
    1.15 +import java.nio.charset.spi.CharsetProvider
    1.16 +
    1.17 +
    1.18 +object Isabelle_Charset
    1.19 +{
    1.20 +  val name: String = "UTF-8-Isabelle-test"  // FIXME
    1.21 +  lazy val charset: Charset = new Isabelle_Charset
    1.22 +}
    1.23 +
    1.24 +
    1.25 +class Isabelle_Charset extends Charset(Isabelle_Charset.name, null)
    1.26 +{
    1.27 +  override def contains(cs: Charset): Boolean =
    1.28 +    cs.name.equalsIgnoreCase(Standard_System.charset_name) ||
    1.29 +    Standard_System.charset.contains(cs)
    1.30 +
    1.31 +  override def newDecoder(): CharsetDecoder =
    1.32 +    Standard_System.charset.newDecoder
    1.33 +
    1.34 +  override def newEncoder(): CharsetEncoder =
    1.35 +    Standard_System.charset.newEncoder
    1.36 +}
    1.37 +
    1.38 +
    1.39 +class Isabelle_Charset_Provider extends CharsetProvider
    1.40 +{
    1.41 +  override def charsetForName(name: String): Charset =
    1.42 +  {
    1.43 +    if (name.equalsIgnoreCase(Isabelle_Charset.name)) Isabelle_Charset.charset
    1.44 +    else null
    1.45 +  }
    1.46 +
    1.47 +  override def charsets(): java.util.Iterator[Charset] =
    1.48 +  {
    1.49 +    import scala.collection.JavaConversions._
    1.50 +    Iterator(Isabelle_Charset.charset)
    1.51 +  }
    1.52 +}
    1.53 +
     2.1 --- a/src/Pure/build-jars	Wed Jun 22 23:56:44 2011 +0200
     2.2 +++ b/src/Pure/build-jars	Thu Jun 23 10:58:29 2011 +0200
     2.3 @@ -37,6 +37,7 @@
     2.4    System/download.scala
     2.5    System/event_bus.scala
     2.6    System/gui_setup.scala
     2.7 +  System/isabelle_charset.scala
     2.8    System/isabelle_process.scala
     2.9    System/isabelle_syntax.scala
    2.10    System/isabelle_system.scala
    2.11 @@ -165,7 +166,11 @@
    2.12  
    2.13    pushd classes >/dev/null
    2.14  
    2.15 -  jar cfe "$(jvmpath "$PURE_JAR")" isabelle.GUI_Setup isabelle || \
    2.16 +  CHARSET_SERVICE="META-INF/services/java.nio.charset.spi.CharsetProvider"
    2.17 +  mkdir -p "$(dirname "$CHARSET_SERVICE")"
    2.18 +  echo isabelle.Isabelle_Charset_Provider > "$CHARSET_SERVICE"
    2.19 +
    2.20 +  jar cfe "$(jvmpath "$PURE_JAR")" isabelle.GUI_Setup META-INF isabelle || \
    2.21      fail "Failed to produce $PURE_JAR"
    2.22  
    2.23    cp "$SCALA_HOME/lib/scala-swing.jar" .