Class CVMChar

All Implemented Interfaces:
IValidated, IWriteable

public final class CVMChar extends APrimitive
Class for CVM Character values. Characters are Unicode code point, and can be used to construct Strings on the CVM. Limited to range 0 .. 0x10ffff as per Unicode standard
  • Field Details

    • MAX_VALUE

      public static int MAX_VALUE
    • ZERO

      public static final CVMChar ZERO
      Singleton instance representing the NULL character (code point zero)
    • MAX_UTF_BYTES

      public static final int MAX_UTF_BYTES
      Maximum number of UTF-8 bytes required to represent a CVMChar
      See Also:
  • Method Details

    • getType

      public AType getType()
      Description copied from class: ACell
      Gets the most specific known runtime Type for this Cell.
      Overrides:
      getType in class ACell
      Returns:
      The Type of this Call
    • create

      public static CVMChar create(long value)
      Gets a CVMChar for the given Unicode code point, or null if not valid
      Parameters:
      value - Unicode code point for the character
      Returns:
      CVMChar instance, or null if not valid
    • longValue

      public long longValue()
      Gets the Long value of this char, equal to the Unicode code point
      Specified by:
      longValue in class APrimitive
      Returns:
      long value representing primitive
    • estimatedEncodingSize

      public int estimatedEncodingSize()
      Description copied from interface: IWriteable
      Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.
      Returns:
      The estimated size for the binary representation of this object.
    • validateCell

      public void validateCell() throws InvalidDataException
      Description copied from class: ACell
      Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.
      Specified by:
      validateCell in class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • codepointFromUTFInt

      public static int codepointFromUTFInt(int utf)
      Gets a code point value from bytes encoded in a Java integer (starting from high byte
    • utfLength

      public static int utfLength(long c)
      Gets the UTF-8 length in bytes for this CVMChar
      Parameters:
      c - Code point value
      Returns:
      UTF lenth or -1 if not a valid Unicode value
    • read

      public static CVMChar read(int len, ByteBuffer bb) throws BadFormatException
      Throws:
      BadFormatException
    • encode

      public int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • encodeRaw

      public int encodeRaw(int len, byte[] bs, int pos)
    • encodeRaw

      public int encodeRaw(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, excluding the tag byte.
      Specified by:
      encodeRaw in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • print

      public boolean print(BlobBuilder bb, long limit)
      Description copied from class: AObject
      Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time if limit of printing is exceeded otherwise DoS attacks may be possible.
      Specified by:
      print in class AObject
      Parameters:
      bb - BlobBuilder to append to
      limit - Limit of printing in string bytes
      Returns:
      True if fully printed within limit, false otherwise
    • toString

      public String toString()
      Returns the Java String representation of this CVMChar. Returns a bad character representation in the case that the UTF code point of this Character is invalid Different from print() which returns a readable representation. For instance, on CVMChar \a, this methods returns "a" while print() returns "\a".
      Overrides:
      toString in class ACell
    • doubleValue

      public double doubleValue()
      Specified by:
      doubleValue in class APrimitive
      Returns:
      double value representing primitive
    • parse

      public static CVMChar parse(String s)
      Parses a Character from a Java String, as interpreted by the Reader e.g. "\newline" or "\c"
      Parameters:
      s - String to parse
      Returns:
      CVMChar instance, or null if not valid
    • getTag

      public byte getTag()
      Description copied from class: ACell
      Gets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding
      Specified by:
      getTag in class ACell
      Returns:
      Tag byte for this Cell
    • charValue

      public char charValue()
      Gets the Java char value of this CVM Character. Not all Unicode code points fit in a JVM char, a "bad character" value is used as replacement if this is not possible.
    • toUTFBytes

      public byte[] toUTFBytes()
      Converts this Character to a Blob with its UTF-8 byte representation
      Returns:
      byte[] array containing UTF-8 bytes
    • toUTFBlob

      public Blob toUTFBlob()
      Gets the Blob representation of this Character in UTF-8
      Returns:
      1-4 Bytes Blob containing UTF-8 representation of this Character
    • toCVMString

      public AString toCVMString(long limit)
      Description copied from class: ACell
      Returns the CVM String representation of this Cell. Normally, this is as printed, but may be different for some types. MUST return null in O(1) time if the length of the CVM String would exceed limit. The String representation is intended to be a easy-to-read textual representation of the Cell's data content.
      Overrides:
      toCVMString in class ACell
      Parameters:
      limit - Limit of CVM String length in UTF-8 bytes
      Returns:
      CVM String, or null if limit exceeded
    • getCodePoint

      public int getCodePoint()
      Gets the Unicode code point for this Character
      Returns:
      Code point as an int value