src/Pure/System/isabelle_charset.scala
author wenzelm
Sun, 25 Nov 2012 20:17:04 +0100
changeset 50203 00d8ad713e32
parent 44778 18b1ba7cfcfe
child 55618 995162143ef4
permissions -rw-r--r--
explicit module UTF8;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43517
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/System/isabelle_charset.scala
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     3
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     4
Charset for Isabelle symbols.
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     5
*/
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     6
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     7
package isabelle
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     8
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
     9
import java.nio.Buffer
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    10
import java.nio.{ByteBuffer, CharBuffer}
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    11
import java.nio.charset.{Charset, CharsetDecoder, CharsetEncoder, CoderResult}
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    12
import java.nio.charset.spi.CharsetProvider
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    13
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    14
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    15
object Isabelle_Charset
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    16
{
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    17
  val name: String = "UTF-8-Isabelle-test"  // FIXME
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    18
  lazy val charset: Charset = new Isabelle_Charset
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    19
}
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    20
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    21
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    22
class Isabelle_Charset extends Charset(Isabelle_Charset.name, null)
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    23
{
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    24
  override def contains(cs: Charset): Boolean =
50203
00d8ad713e32 explicit module UTF8;
wenzelm
parents: 44778
diff changeset
    25
    cs.name.equalsIgnoreCase(UTF8.charset_name) || UTF8.charset.contains(cs)
43517
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    26
50203
00d8ad713e32 explicit module UTF8;
wenzelm
parents: 44778
diff changeset
    27
  override def newDecoder(): CharsetDecoder = UTF8.charset.newDecoder
43517
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    28
50203
00d8ad713e32 explicit module UTF8;
wenzelm
parents: 44778
diff changeset
    29
  override def newEncoder(): CharsetEncoder = UTF8.charset.newEncoder
43517
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    30
}
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    31
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    32
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    33
class Isabelle_Charset_Provider extends CharsetProvider
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    34
{
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    35
  override def charsetForName(name: String): Charset =
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    36
  {
44778
18b1ba7cfcfe deactivate unfinished charset provider for now, to avoid user confusion;
wenzelm
parents: 43517
diff changeset
    37
    // FIXME inactive
18b1ba7cfcfe deactivate unfinished charset provider for now, to avoid user confusion;
wenzelm
parents: 43517
diff changeset
    38
    // if (name.equalsIgnoreCase(Isabelle_Charset.name)) Isabelle_Charset.charset
18b1ba7cfcfe deactivate unfinished charset provider for now, to avoid user confusion;
wenzelm
parents: 43517
diff changeset
    39
    // else null
18b1ba7cfcfe deactivate unfinished charset provider for now, to avoid user confusion;
wenzelm
parents: 43517
diff changeset
    40
    null
43517
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    41
  }
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    42
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    43
  override def charsets(): java.util.Iterator[Charset] =
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    44
  {
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    45
    import scala.collection.JavaConversions._
44778
18b1ba7cfcfe deactivate unfinished charset provider for now, to avoid user confusion;
wenzelm
parents: 43517
diff changeset
    46
    // FIXME inactive
18b1ba7cfcfe deactivate unfinished charset provider for now, to avoid user confusion;
wenzelm
parents: 43517
diff changeset
    47
    // Iterator(Isabelle_Charset.charset)
18b1ba7cfcfe deactivate unfinished charset provider for now, to avoid user confusion;
wenzelm
parents: 43517
diff changeset
    48
    Iterator()
43517
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    49
  }
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    50
}
87ec9a1c0f98 basic setup for Isabelle charset;
wenzelm
parents:
diff changeset
    51