logo

const class

sys::Charset

sys::Obj
  sys::Charset
  1  //
  2  // Copyright (c) 2006, Brian Frank and Andy Frank
  3  // Licensed under the Academic Free License version 3.0
  4  //
  5  // History:
  6  //   16 Mar 06  Brian Frank  Creation
  7  //
  8  
  9  **
 10  ** Charset represents a specific character encoding used to decode
 11  ** bytes to Unicode characters, and encode Unicode characters to bytes.
 12  **
 13  const class Charset
 14  {
 15  
 16  //////////////////////////////////////////////////////////////////////////
 17  // Construction
 18  //////////////////////////////////////////////////////////////////////////
 19  
 20    **
 21    ** Attempt to lookup a Charset by name.  Use one of the predefined
 22    ** methods such as utf8() to get a standard encoding.  Throw Err
 23    ** if a charset is not available for the specified name.
 24    **
 25    static Charset make(Str name)
 26  
 27    **
 28    ** Private constructor
 29    **
 30    private new privateMake()
 31  
 32  //////////////////////////////////////////////////////////////////////////
 33  // Standard Encodings
 34  //////////////////////////////////////////////////////////////////////////
 35  
 36    **
 37    ** An charset for "UTF-8" format (Eight-bit UCS Transformation Format).
 38    **
 39    static Charset utf8()
 40  
 41    **
 42    ** An charset for "UTF-16BE" format (Sixteen-bit UCS Transformation
 43    ** Format, big-endian byte order).
 44    **
 45    static Charset utf16BE()
 46  
 47    **
 48    ** An charset for "UTF-16LE" format (Sixteen-bit UCS Transformation
 49    ** Format, little-endian byte order).
 50    **
 51    static Charset utf16LE()
 52  
 53  //////////////////////////////////////////////////////////////////////////
 54  // Methods
 55  //////////////////////////////////////////////////////////////////////////
 56  
 57    **
 58    ** Get the name of this character encoding.
 59    **
 60    Str name()
 61  
 62    **
 63    ** Compute hash code based on case-insensitive name.
 64    **
 65    override Int hash()
 66  
 67    **
 68    ** Charset equality is based on the character set name
 69    ** ignoring case (names are not case-sensitive).
 70    **
 71    override Bool equals(Obj obj)
 72  
 73    **
 74    ** Return name().
 75    **
 76    override Str toStr()
 77  
 78  }