cz.cuni.amis.pogamut.shady
Class ArgString

Package class diagram package ArgString
java.lang.Object
  extended by cz.cuni.amis.pogamut.shady.ArgString
All Implemented Interfaces:
IArgument<String>

public class ArgString
extends Object

Store the string value as an argument. We want to allow escaping (e.g. \n, \t ..) and we are using syntax defined by the (java lexical structure).

The constructor won't automatically unescape the passed value. Use ArgString#parseStringLiteral(java.lang.StringBuilder) .

Author:
Honza

Constructor Summary
ArgString(String string)
          Take the string and use it as the value of the argument.
 
Method Summary
 boolean equals(Object obj)
           
 T getValue()
           
protected static Character parseStringCharacter(StringBuilder sb)
          Extract the StringCharacter from the sb and return it.
protected static String parseStringLiteral(String escaped)
          Take the escaped string, parse it and return the unescaped value.
static String unescape(String escapedString)
          Get unescaped version of passed string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgString

public ArgString(String string)
Take the string and use it as the value of the argument. Be careful, in most cases, use of unescape(java.lang.String) is recommended (it parses escaped string into an unescaped form).

Parameters:
string - value of the argument
Method Detail

unescape

public static String unescape(String escapedString)
                       throws ParseException
Get unescaped version of passed string.

Parameters:
escapedString - string escaped according to java lexical structure, without double quotes (e.g. Hello\nWorld)
Returns:
unescaped string
Throws:
ParseException - if there is an error in the escaping

parseStringLiteral

protected static String parseStringLiteral(String escaped)
                                    throws ParseException
Take the escaped string, parse it and return the unescaped value.

Parameters:
string - string to parse, incl. quotes (e.g. "Foo\nBar")

StringLiteral: " [StringCharacters] "

Returns:
parsed string
Throws:
ParseException

parseStringCharacter

protected static Character parseStringCharacter(StringBuilder sb)
                                         throws ParseException
Extract the StringCharacter from the sb and return it.

< pre> StringCharacter: InputCharacter but not " or \ StringCharacter: EscapeSequence InputCharacter: UnicodeInputCharacter but not CR or LF Basically when you expand it all, you will get

  \(u)+ [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]  ~ Unicode char
  \[btnfr"'\]
  \[0-3][0-7][0-7]
  \[0-7][0-7]
  \[0-7]
 

Parameters:
sb - sequence of chars that is used to extract the character. Is modified (characters are removed) during parsing.
Returns:
found character if there is a StringCharacter, null otherwise
Throws:
ParseException

getValue

public T getValue()
Specified by:
getValue in interface IArgument<T>

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.