Sharkysoft home

lava.string
Class StringDecoder

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

public class StringDecoder
extends java.lang.Object

Decodes strings.

Details: StringEncoder contains functions for transforming encoded strings into regular strings.

Since:
2000.05.31
Version:
2000.12.21
Author:
Sharky

Constructor Summary
StringDecoder()
           
 
Method Summary
static java.lang.String decodeCString(java.lang.String s)
          Details: decodeCString decodes a C-style string that may contain backslash-escaped sequences.
static java.lang.String decodeHtmlText(java.lang.String encoded)
          Decodes HTML-encoded string.
static java.lang.String decodeQuotedCString(java.lang.String s)
          Decodes quoted C string.
static int digitForChar(char c)
          Converts digit character to value.
static byte[] hexStringToBytes(java.lang.String s)
          Coverts hex string to bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringDecoder

public StringDecoder()
Method Detail

decodeCString

public static final java.lang.String decodeCString(java.lang.String s)

Details: decodeCString decodes a C-style string that may contain backslash-escaped sequences. It is assumed that the surrounding quotes have already been stripped off. Any unescaped illegal characters (such as quotes) will be included verbatim in the decoded string.

The following characters have special interpretations when preceded by a backslash:

'a', 'b', 'f', 'n', 'r', 't', 'v', 'x'

Other characters preceded by a backslash are taken to be themselves. (Hence, "\?" converts to just "?".) Consult your favorite C text for more information on C string literals.

Parameters:
s - the C-style string to decode
Returns:
the decoded string

decodeQuotedCString

public static java.lang.String decodeQuotedCString(java.lang.String s)
Decodes quoted C string.

Details: decodeQuotedCString decodes a quoted C string literal using the common rules of C. If the string does not begin and end with single or double quotes, or if it begins and ends with mismatching quote types, null is returned. Otherwise, the quotes are trimmed and what's left is passed to decodeCString.

Parameters:
s - the quoted string
Returns:
the decoded string
Since:
unknown

digitForChar

public static int digitForChar(char c)
Converts digit character to value.

Details: digitForChar returns the value that would represented by the given character if the radix allowed it. For '0'-'9', digitForChar returns 0-9; for 'A(a)'-'Z(z)', digitForChar returns 10-35. All other characters are illegal.

Parameters:
c - the character digit
Returns:
the digit value
Since:
2000.02.21

hexStringToBytes

public static byte[] hexStringToBytes(java.lang.String s)
Coverts hex string to bytes.

Details: hexStringToBytes converts an even-length string of hexadecimal digits into an array of bytes. This operation fails if the string is null, the length of the string is odd, or the string contains non-hexadecimal digits. null is returned on failure.

Parameters:
s - the string
Returns:
the array of bytes, or null if the conversion failed

decodeHtmlText

public static java.lang.String decodeHtmlText(java.lang.String encoded)
Decodes HTML-encoded string.

Details: decodeHtmlText converts an HTML-encoded string (encode) into a natural string by decoding all of the HTML entities contained within the string.

Parameters:
the - encoded string
Returns:
the decoded result
Since:
2000.12.21

Sharkysoft home