Sharkysoft home

lava.string
Class StringEncoder

java.lang.Object
  |
  +--lava.string.StringEncoder

public class StringEncoder
extends java.lang.Object

Encodes strings.

Details: StringEncoder contains functions for transforming regular strings into strings that satisfy various encoding rules.

Since:
2000.05.31
Version:
2000.12.21
Author:
Sharky

Constructor Summary
StringEncoder()
           
 
Method Summary
static java.lang.String bytesToHexString(byte[] bytes)
          Converts byte array to hex string.
static char charForDigit(int n)
          Converts digit value to character.
static java.lang.String encodeAsciiJavaString(java.lang.String input)
          Encodes string into Java string literal.
static java.lang.String encodeHtmlText(java.lang.String encoded)
          Encodes HTML text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringEncoder

public StringEncoder()
Method Detail

encodeAsciiJavaString

public static java.lang.String encodeAsciiJavaString(java.lang.String input)
Encodes string into Java string literal.

Details: This method transforms a "binary" string into a Java string literal, such as might appear in Java source code, but using only 7-bit ASCII characters. The result is contained in quotes, and all non-printable characters or characters outside the 7-bit ASCII range are encoded using appropriate Java escape sequences. If null is supplied, null is returned.

Parameters:
input - the string to encode
Returns:
the encoded string
Since:
1988.10.13

encodeHtmlText

public static java.lang.String encodeHtmlText(java.lang.String encoded)
Encodes HTML text.

Details: encodeHtmlText prepares a string for output into an HTML document by escaping the reserved characters '<', '>', and '&'.

Parameters:
s - the input string
Returns:
the escaped string
Since:
1999.01.29

charForDigit

public static char charForDigit(int n)
Converts digit value to character.

Details: charForDigit converts the given integer (n) into its character equivalent. For 0 <= n <= 9, this is simply the character corresponding to the number. For 10 <= n < 36, this is 'A' + (n - 10). All other values for n are illegal.

Parameters:
n - the integer
Returns:
the character

bytesToHexString

public static java.lang.String bytesToHexString(byte[] bytes)
Converts byte array to hex string.

Details: bytesToHexString converts the given byte array (bytes) into an upper case hexadecimal string.

Parameters:
bytes - the array
Returns:
the string
Since:
2000.01.29

Sharkysoft home