8.13. File tom/ByteString

class tom.ByteString

A ByteString is a String and a ByteArray, which can do all kinds of nice string-like things.

Requesting a substring of a ByteString results in a ByteSubstring to be returned. This will mimic a ByteString as much as possible, including hashing, equality, uniquing, printing, copying, etc, but they do not share a common superclass between String and ByteString.

In the future, the ByteString instance actual functionality could be put into a ByteFullstring, enabling the ByteSubstring to actually become a subclass of ByteString...

inherits

State supers: ByteArray, String, C, Constants

variables

static CharacterEncoding default_encoding;

The default character encoding for ByteString instances.

Never refer this variable directly; always ask the string (even if it is self) for its encoding. A normal ByteString will then return this default_encoding.

methods


OutputStream
  help OutputStream s
  done MutableKeyed done;

Output information on the ByteString unit arguments.


void
  load MutableArray arguments;

Set the default byte encoding. If it is not specified on the command line, iso-8859-1 will be used.

Before this method is invoked by the runtime library, the default_encoding will be a USASCIIEncoding.


void
  switchToEncoding String name;

Switch to the encoding with the name, moaning if it fails (without changing the current encoding).

instance tom.ByteString

methods


char
  at int index;

Return the Unicode character for the byte at index.


(pointer, int)
  byteStringContents;

Undocumented.


boolean
  equal String other;

Undocumented.


int
  hashRange (int, int) (start, len);

Undocumented.


boolean
  equalByteString ByteString other;

Undocumented.


boolean
  equalCharString CharString other;

Undocumented.


boolean
  equalUniqueString UniqueString other;

Undocumented.


protected id (self)
  init (pointer, int) (p, num);

Initialize the newly allocated instance with the num bytes at p. The receiving instance will `own' the memory at p.


id (self)
  initCopy (pointer, int) (p, num);

Initialize the newly allocated instance with a copy of the num bytes at p.


MutableByteString
  mutableSubstring (int, int) (start, len);

Return a new instance of the receiver's mutableCopyClass, initialized with a substring from the receiver's range (start, len).


String
  substring (int, int) (start, len);

Undocumented.


UniqueByteString
  uniqueString;

Undocumented.


OutputStream
  write OutputStream s;

Undocumented.


class (State)
  mutableCopyClass;

Return the MutableByteString class.


CharacterEncoding
  encoding;

Return the encoding of the receiving ByteString. The default implementation returns the default_encoding.


String
  stringByDecoding String encoding_name;

Undocumented.


String
  stringByDemapping CharArray demap;

Undocumented.


boolean
  isAlpha byte b;

Return TRUE the character denoted by the byte b in the encoding of the receiving string is a letter.


boolean
  isDigit byte b;

Return TRUE the character denoted by the byte b in the encoding of the receiving string is a digit.


boolean
  isLower byte b;

Return TRUE the character denoted by the byte b in the encoding of the receiving string is a lowercase letter.


boolean
  isPunct byte b;

Return TRUE the character denoted by the byte b in the encoding of the receiving string is a punctuation character.


boolean
  isSpace byte b;

Return TRUE the character denoted by the byte b in the encoding of the receiving string is a space character.


boolean
  isUpper byte b;

Return TRUE the character denoted by the byte b in the encoding of the receiving string is a uppercase letter.


byte
  toLower byte b;

Return the lower-case version of the byte b, according to the encoding of the receiving string. If the character is not in upper-case, it is returned unharmed.


byte
  toUpper byte b;

Return the upper-case equivalent of the byte b, according to the encoding of the receiving string. If the character is not in lower-case, it is returned unharmed.


int
  digitValue byte b;

Return the value equivalent of the byte b, for which this string should return TRUE when asked isDigit.


int
  alphaValue byte b;

Return the index of the letter b relative to the start of its letter range. Thus, 'a' returns 0, 'f' returns 5, etc.


id
  downcase;

This version of downcase overrides the implementation by String, since this one is faster due to avoiding the unnecessary conversion to/from Unicode.


id
  upcase;

Like downcase, this just is a faster implementation than the one provided by String.