|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.taco.text.StringConverterUtilities
public class StringConverterUtilities
Utility functions for converting interpolated strings.
Field Summary | |
---|---|
protected static java.lang.String |
_ARGUMENT_MAP_REFERENCE_PREFIX_REGEX_STRING
|
protected static java.lang.String |
_BUNDLE_KEY_REFERENCE_REGEX_STRING
|
protected static java.util.regex.Pattern |
_DEFAULT_VALUE_END_PATTERN
|
protected static java.lang.String |
_DOTTED_NAME_REGEX_STRING
|
protected static java.util.regex.Pattern |
_GLOBAL_ASSIGNMENT_PATTERN
The pattern compiled from _GLOBAL_NAME_ASSIGNMENT_REGEX_STRING . |
protected static java.lang.String |
_GLOBAL_ASSIGNMENT_REGEX_STRING
A regex string for the prefix before a literal indicating a property value. |
protected static java.lang.String |
_GLOBAL_REFERENCE_REGEX_STRING
|
protected static java.util.regex.Pattern |
_VARIABLE_REFERENCE_PATTERN
|
protected static java.lang.String |
_VARIABLE_REFERENCE_REGEX_STRING
|
static java.util.regex.Pattern |
END_OF_STRING_PATTERN
A pattern passed to nextValue() that indicates that the
entire sequence should be used for the next value. |
Constructor Summary | |
---|---|
StringConverterUtilities()
|
Method Summary | |
---|---|
protected static int |
_finishSequence(java.lang.CharSequence cs,
int startIndex,
java.util.regex.Pattern endPattern)
Give a character sequence and an index at which a value end pattern should match, return the index into the character sequence at which the end of the value sequence lies. |
protected static int |
_parseArgumentMapSuffix(java.lang.CharSequence cs,
int prefixEndOffset,
InterpolatedValueMatchResult result)
Given a character sequence that begins with a reference to an argument map key, the location of the end of the reference, and an instance of InterpolatedValueMatchResult which has its
startIndex field set to the index in the original
character sequence at which cs starts, set the
fromMapValueConverterString ,
toMapValueConverterString fields of result . |
protected static int |
_parseLiteral(java.lang.CharSequence cs,
java.util.regex.Pattern endPattern,
InterpolatedValueMatchResult result)
Given that cs begins with a string literal, parse it an
fill in the appropriate fields of result . |
static java.lang.CharSequence |
extractPropertiesSubSequence(java.lang.CharSequence cs)
Given a literal string to convert, return the part of the string that is a series of property name / value pairs. |
static int |
intValueForProperty(java.lang.Object propertyValue,
IStringToObjectConverter converter,
int defaultValue)
Given a property value and a converter from strings to instances of Number , return the int value of the property. |
static void |
main(java.lang.String[] args)
Send args[0] to valueForSequence and print
the result. |
static InterpolatedValueMatchResult |
nextValue(java.lang.CharSequence cs,
int startIndex)
Parse the sequence starting at the argument index, looking for the default end pattern to terminate the subsequence used for the value. |
static InterpolatedValueMatchResult |
nextValue(java.lang.CharSequence cs,
int startIndex,
java.util.regex.Pattern endPattern)
Given a character sequence that starting from startIndex , contains a subsequence specifying a (possibly
interpolated) value, return a new instance of
InterpolatedValueMatchResult . |
static java.lang.Object |
test(IInterpolatingStringToObjectConverter converter,
java.lang.String[] args)
Call test(IInterpolatingStringToObjectConverter, String[],
ResourceBundle, INoReturnMap) with a null bundle and a new
observable map. |
static java.lang.Object |
test(IInterpolatingStringToObjectConverter converter,
java.lang.String[] args,
java.util.ResourceBundle bundle,
INoReturnMap map)
A simple test program for an interpolating string to object converter. |
static java.lang.Object |
testOrdinaryConverter(IStringToObjectConverter converter,
java.lang.String[] args)
A simple test program for an ordinary string to object converter. |
static java.lang.String |
unescape(java.lang.String s)
Unescape a leading '%', '$', '&', or '#' character in a string when they are followed by '\'. |
static void |
usage(java.lang.Class c)
|
static InterpolatedValueMatchResult |
valueForSequence(java.lang.CharSequence cs)
Parse the entire sequence to get a single interpolated value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.util.regex.Pattern END_OF_STRING_PATTERN
nextValue()
that indicates that the
entire sequence should be used for the next value.
protected static final java.util.regex.Pattern _DEFAULT_VALUE_END_PATTERN
protected static final java.lang.String _DOTTED_NAME_REGEX_STRING
protected static final java.lang.String _BUNDLE_KEY_REFERENCE_REGEX_STRING
protected static final java.lang.String _GLOBAL_REFERENCE_REGEX_STRING
protected static final java.lang.String _ARGUMENT_MAP_REFERENCE_PREFIX_REGEX_STRING
protected static final java.lang.String _VARIABLE_REFERENCE_REGEX_STRING
protected static final java.util.regex.Pattern _VARIABLE_REFERENCE_PATTERN
protected static final java.lang.String _GLOBAL_ASSIGNMENT_REGEX_STRING
protected static final java.util.regex.Pattern _GLOBAL_ASSIGNMENT_PATTERN
_GLOBAL_NAME_ASSIGNMENT_REGEX_STRING
.
Constructor Detail |
---|
public StringConverterUtilities()
Method Detail |
---|
public static final java.lang.String unescape(java.lang.String s)
public static final InterpolatedValueMatchResult valueForSequence(java.lang.CharSequence cs) throws java.text.ParseException
java.text.ParseException
public static final InterpolatedValueMatchResult nextValue(java.lang.CharSequence cs, int startIndex) throws java.text.ParseException
java.text.ParseException
public static final InterpolatedValueMatchResult nextValue(java.lang.CharSequence cs, int startIndex, java.util.regex.Pattern endPattern) throws java.text.ParseException
startIndex
, contains a subsequence specifying a (possibly
interpolated) value, return a new instance of
InterpolatedValueMatchResult
.
java.text.ParseException
- if the sequence is not a variable and the
opening brace is not found or not matched with a closing brace.protected static int _finishSequence(java.lang.CharSequence cs, int startIndex, java.util.regex.Pattern endPattern) throws java.text.ParseException
endPattern
has a
capturing group and the group captures something, return the index at
which the capturing group starts. Otherwise, return the index after the
entire matched sequence.
java.text.ParseException
protected static int _parseLiteral(java.lang.CharSequence cs, java.util.regex.Pattern endPattern, InterpolatedValueMatchResult result) throws java.text.ParseException
cs
begins with a string literal, parse it an
fill in the appropriate fields of result
.
java.text.ParseException
protected static int _parseArgumentMapSuffix(java.lang.CharSequence cs, int prefixEndOffset, InterpolatedValueMatchResult result) throws java.text.ParseException
InterpolatedValueMatchResult
which has its
startIndex
field set to the index in the original
character sequence at which cs
starts, set the
fromMapValueConverterString
,
toMapValueConverterString
fields of result
.
If no converters are specified, set these fields to the empty string.
Return the index just after the reference, if there are no converters,
or just after the last '#' if there are converters.
java.text.ParseException
public static void main(java.lang.String[] args)
args[0]
to valueForSequence
and print
the result.
public static final void usage(java.lang.Class c)
public static final java.lang.Object test(IInterpolatingStringToObjectConverter converter, java.lang.String[] args)
test(IInterpolatingStringToObjectConverter, String[],
ResourceBundle, INoReturnMap)
with a null bundle and a new
observable map.
public static final java.lang.Object test(IInterpolatingStringToObjectConverter converter, java.lang.String[] args, java.util.ResourceBundle bundle, INoReturnMap map)
converter
- The converter to use to create an object.args
- A list of arguments from the command line.map
- The argument map.
public static final java.lang.Object testOrdinaryConverter(IStringToObjectConverter converter, java.lang.String[] args)
public static final java.lang.CharSequence extractPropertiesSubSequence(java.lang.CharSequence cs) throws java.text.ParseException
java.text.ParseException
public static int intValueForProperty(java.lang.Object propertyValue, IStringToObjectConverter converter, int defaultValue)
Given a property value and a converter from strings to instances of
Number
, return the int value of the property. If the value
cannot be converted, return defaultValue
.
To be more precise, if propertyValue
is
null
, defaultValue
is returned. Otherwise, if
propertyValue
is a string, use the argument converter to
convert it to an instance of Number
. If the conversion
succeeds, return the int value of the Number
. If the
conversion fails, return defaultValue
.
Otherwise, if propertyValue
is an instance of Number,
return its int value. If propertyValue
is not a
String
or Number
, return
defaultValue
.
propertyValue
- the value to be converter, may be
null
converter
- the string to object converter to use to convert
propertyValue
if it's a stringdefaultValue
- the value to return in case of error
propertyValue
, or
defaultValue
in case or conversion error
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |