HiRISE

HiRISE.HiPlan.Utilities
Class Escaper

java.lang.Object
  extended by HiRISE.HiPlan.Utilities.Escaper

public class Escaper
extends Object

A class for escaping designated special characters in a string by prefixing them with a designated escape character. The literal escape character will be escaped as well.

Version:
1.4
Author:
Christian Schaller - UA/PIRL

Field Summary
static char DEFAULT_ESCAPE_CHARACTER
          The default escape character.
static char[] DEFAULT_SPECIAL_CHARACTERS
          The default set of special characters to escape.
static String ID
          Class identification name with source code version and date.
 
Constructor Summary
Escaper()
          Creates an Escaper with the default set of special characters and the default escape character.
Escaper(char[] special_characters, char escape_character)
          Creates an Escaper with the indicated set of special characters and the indicated escape character.
 
Method Summary
 char escape_character()
          Gets the escape character.
 void escape_character(char escape_character)
          Sets the escape character.
 String escape(String string)
          Escapes certain characters in a string.
 char[] special_characters()
          Gets the set of special characters.
 void special_characters(char[] special_characters)
          Sets the set of special characters.
 String unescape(String string)
          Unescapes characters in a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
Class identification name with source code version and date.

See Also:
Constant Field Values

DEFAULT_ESCAPE_CHARACTER

public static final char DEFAULT_ESCAPE_CHARACTER
The default escape character. The default character is the backslash ('\').

See Also:
Constant Field Values

DEFAULT_SPECIAL_CHARACTERS

public static final char[] DEFAULT_SPECIAL_CHARACTERS
The default set of special characters to escape. This default set consists of the comma (',') only, although the escape character, whatever it may be, will always be escaped.

Constructor Detail

Escaper

public Escaper(char[] special_characters,
               char escape_character)
Creates an Escaper with the indicated set of special characters and the indicated escape character.

Parameters:
special_characters - the set of special characters. The escape_character will be escaped as well.
escape_character - the character that marks a character as escaped.

Escaper

public Escaper()
Creates an Escaper with the default set of special characters and the default escape character.

See Also:
DEFAULT_SPECIAL_CHARACTERS, DEFAULT_ESCAPE_CHARACTER
Method Detail

special_characters

public char[] special_characters()
Gets the set of special characters. The escape_character will be escaped as well, whether it appears in this list or not.

Returns:
the user's set of special characters.

special_characters

public void special_characters(char[] special_characters)
Sets the set of special characters. The escape_character will be escaped as well, whether it appears in this list or not.

Parameters:
special_characters - the set of special characters, which need not include the escape character.

escape_character

public char escape_character()
Gets the escape character.

Returns:
escape_character the character used to escape other characters.

escape_character

public void escape_character(char escape_character)
Sets the escape character. The literal escape_character will be escaped, whether it appears in the list of special_characters or not.

Parameters:
escape_character - the character used to escape other characters.

escape

public String escape(String string)
Escapes certain characters in a string. Characters in special_characters are escaped by prefacing them with the escape_character.

If string is null, then null is returned.

Parameters:
string - the unescaped string.
Returns:
the escaped string.

unescape

public String unescape(String string)
Unescapes characters in a string. Only characters that are in the special_characters list and that are preceded by the escape_character are unescaped; the escaped escape character is also unescaped. Characters that are not in the list but that are preceded by the escape character are left untouched.

If string is null, then null is returned.

Parameters:
string - the escaped string.
Returns:
the unescaped string.

HiRISE

Copyright (C) Arizona Board of Regents on behalf of the Planetary Image Research Laboratory, Lunar and Planetary Laboratory at the University of Arizona