tcl.lang.cmd
Class EncodingCmd

java.lang.Object
  extended by tcl.lang.cmd.EncodingCmd
All Implemented Interfaces:
Command

public class EncodingCmd
extends Object
implements Command

This class implements the built-in "encoding" command in Tcl. It's also the home for the global systemEncoding property, and translates between TCL encoding names and Java Encoding names.


Field Summary
static String systemJavaEncoding
          The java equivalent name (either java.nio or java.io/java.lang) of the value returned for 'encoding system'
static String systemTclEncoding
          The encoding value set and returned by 'encoding system'
 
Constructor Summary
EncodingCmd()
           
 
Method Summary
 void cmdProc(Interp interp, TclObject[] objv)
          This procedure is invoked to process the "encoding" Tcl command.
static void decodeSymbol(byte[] bbuf, char[] cbuf, int off, int len)
          Decode bytes encoded in Tcl's symbol encoding into a character array.
static byte[] encodeSymbol(char[] cbuf, int off, int len)
          Encode chars into Tcl's symbol encoding into a byte array.
static int getBytesPerChar(String name)
          Given a Java encoding name return the average bytes per char
static String getJavaName(String name)
          Given a Tcl encoding name, return the Java encoding name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

systemTclEncoding

public static String systemTclEncoding
The encoding value set and returned by 'encoding system'


systemJavaEncoding

public static String systemJavaEncoding
The java equivalent name (either java.nio or java.io/java.lang) of the value returned for 'encoding system'

Constructor Detail

EncodingCmd

public EncodingCmd()
Method Detail

cmdProc

public void cmdProc(Interp interp,
                    TclObject[] objv)
             throws TclException
This procedure is invoked to process the "encoding" Tcl command. See the user documentation for details on what it does.

Specified by:
cmdProc in interface Command
Parameters:
interp - the current interpreter.
objv - command arguments.
Throws:
TclException - on any errors

getBytesPerChar

public static int getBytesPerChar(String name)
Given a Java encoding name return the average bytes per char

Parameters:
name - Java name of encoding as returned from getJavaName(
Returns:
the average bytes per character

getJavaName

public static String getJavaName(String name)
Given a Tcl encoding name, return the Java encoding name

Parameters:
name - Tcl name for encoding
Returns:
java name for encoding, which may be either the new-style java.nio name, or the old style java.io/java.lang name

decodeSymbol

public static void decodeSymbol(byte[] bbuf,
                                char[] cbuf,
                                int off,
                                int len)
Decode bytes encoded in Tcl's symbol encoding into a character array. We probably should have done this by registering a Java CharSet, but that's a lot of code for this not-often-used encoding.

Parameters:
bbuf - binary data that contains a symbol encodes string
cbuf - character buffer to fill with data s
off - offset to filling cbuf
len - number of characters to add to cbuf

encodeSymbol

public static byte[] encodeSymbol(char[] cbuf,
                                  int off,
                                  int len)
Encode chars into Tcl's symbol encoding into a byte array. We probably should have done this by registering a Java CharSet, but that's a lot of code for this not-often-used encoding.

Parameters:
cbuf - character data to encode in 'symbol' encoding
off - offset to start encoding
len - number of characters to encode
Returns:
a byte array of lenght len containing encoded data


Copyright © 2015. All rights reserved.