Package eu.bandm.tools.format
Class Formats
java.lang.Object
eu.bandm.tools.format.Formats
Collection of static factory and transformation methods for Formats.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FormatFor marking quoted text in messags and documentation text.static final FormatFor marking quoted text in messags and documentation text.static final PatternMatches all maximal adjacent appearances of "carriage return" and "linefeed", such that at least one of them appears and both at most once.static final PatternMatches arbitrary non-empty sequences of blanks and horizontal tabs.static final StringFor marking quoted text in messags and documentation text.static final StringFor marking quoted text in messags and documentation text. -
Method Summary
Modifier and TypeMethodDescriptionstatic FormatWraps the given data into a Java-style doc comment.static Formatlist(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, Format... formats) Convenience method, creates a complex list display format for sequences ofFormats.static Formatlist(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, List<? extends Format> formats) Convenience method, creates a complex list display format for sequences ofFormats.static FormatSame aslist(Format,CompoundConstructor,Format,CompoundConstructor,Format,Format...), whereouterCombinatordefaults toCompoundConstructor.besideandinnerCombinatordefaults toCompoundConstructor.linestatic FormatSame aslist(Format,CompoundConstructor,Format,CompoundConstructor,Format,List), whereouterCombinatordefaults toCompoundConstructor.besideandinnerCombinatordefaults toCompoundConstructor.linestatic FormatWraps the given data into a Java-style non-doc multi-line comment.static FormatCreates a literal format which chooses quote symbols not appearing in the data, in XML style.static FormatCreates a literal format with all doublequotes contained in the text escaped with a backslash.static FormatsingleLine(Format format) Wraps the given data into a single-line Java-style comment.static FormatConvenience method for translating multi-line text into a complex format hierarchy.static FormattextWithVars(String txt) Transform a text into a complex Format structure, additionally detecting references to numeric variables.static FormattextWithVars(String prefix, String txt) Transform a text into a complex Format structure, additionally detecting references to numeric variables.
-
Field Details
-
STRING_GUILLEMETS_GERMAN_LEFT
For marking quoted text in messags and documentation text.- See Also:
-
STRING_GUILLEMETS_GERMAN_RIGHT
For marking quoted text in messags and documentation text.- See Also:
-
format_guillemetsGermanLeft
For marking quoted text in messags and documentation text. -
format_guillemetsGermanRight
For marking quoted text in messags and documentation text. -
pattern_newline
Matches all maximal adjacent appearances of "carriage return" and "linefeed", such that at least one of them appears and both at most once. -
pattern_ws
Matches arbitrary non-empty sequences of blanks and horizontal tabs.
-
-
Method Details
-
quoteDTDstyle
Creates a literal format which chooses quote symbols not appearing in the data, in XML style.If the data does not contain single quotes then the result is an
Appendwith single quotes as first and last character.
Otherwise, if data does not contain double quotes, then do the same with double quotes.
Otherwise replace all single quotes in the data with a XML-style "character entity" and frame the result with single quotes.- Parameters:
f- the input text. Only the Literal formats contained therein are considered and possibly rewritten.- Returns:
- the original format, framed by an appropriate quote symbol in an append format, and possibly with rewritten contents.
-
text
Convenience method for translating multi-line text into a complex format hierarchy. The result will have a structure likeBeneath | Block | | Literal | | Space | | Literal | | Space | | Literal | Space | Block | | Literal | | Space | | Literal *
The limits of blocks will be given by hard "newlines" contained in the text.
Whitespace will be translated into Space and non-whitespace into Literal
Whitespace at the beginning of a line (following a hard newline) will be translated into indentation.
Empty lines (two consecutive newline characters, optional whitespace between them) results to space on the upper level, under the Beneath combinator.
The current implementation may produce lines with trailing whitespace.- Parameters:
txt- the text to convert- Returns:
- a compound format structure with Literal and Space formats at its leaf positions.
-
textWithVars
Transform a text into a complex Format structure, additionally detecting references to numeric variables. These are marked withVariable.DEFAULT_PREFIX. Named variables are not detected. Seetext(java.lang.String)for details of the result. Additionally all substrings of form[#][0..9]+are translated to instances ofBoundVariableand inserted into the result instead at the same place as the literals in the scheme fortext(String). (FreeVariables are not supported.)- Parameters:
txt- the text to convert- Returns:
- a compound format structure with Literal, Space, and BoundVariable formats at its leaf positions.
-
textWithVars
Transform a text into a complex Format structure, additionally detecting references to numeric variables. These are marked with the given prefix. Named variables are not detected. Seetext(java.lang.String)for details of the result. Additionally all substrings of form<prefix>[0..9]+are translated to instances ofBoundVariableand inserted into the result instead at the same place as the literals in the scheme fortext(String).- Parameters:
prefix- used for parsing and display, must not be empty.txt- the text to convert- Returns:
- a compound format structure with Literal, Space, and BoundVariable formats at its leaf positions.
- Throws:
IllegalArgumentException- if prefix is empty
-
list
Same aslist(Format,CompoundConstructor,Format,CompoundConstructor,Format,Format...), whereouterCombinatordefaults toCompoundConstructor.besideandinnerCombinatordefaults toCompoundConstructor.line- Parameters:
open- the format at the very left of the result, like an open parenthesisdelim- the format to separate the elements of the list, like a commaclose- the format at the very right of the result, like a closing parenthesisformats- the sequence of inner elements.- Returns:
- the complete tree of format objects which represents the lis
-
list
Same aslist(Format,CompoundConstructor,Format,CompoundConstructor,Format,List), whereouterCombinatordefaults toCompoundConstructor.besideandinnerCombinatordefaults toCompoundConstructor.line- Parameters:
open- the format at the very left of the result, like an open parenthesisdelim- the format to separate the elements of the list, like a commaclose- the format at the very right of the result, like a closing parenthesisformats- the sequence of inner elements.- Returns:
- the complete tree of format objects which represents the lis
-
list
public static Format list(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, Format... formats) Convenience method, creates a complex list display format for sequences ofFormats. The structure which is created is determinded toouter combinator | | | | | close | | | inner comb.-----+--- .... ---+ | | | | | Append Append f[last] | | | | | | f[0] delim f[1] delim | open
- Parameters:
open- the format at the very left of the result, like an open parenthesisouterCombinator- how to combine open, the inner list, and closedelim- the format to separate the elements of the list, like a commainnerCombinator- how to combine the elements of the inner listclose- the format at the very right of the result, like a closing parenthesisformats- the sequence of inner elements.- Returns:
- the complete tree of format objects which represents the lis
-
list
public static Format list(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, List<? extends Format> formats) Convenience method, creates a complex list display format for sequences ofFormats. The structure which is created is determinded toouter combinator | | | | | close | | | inner comb.-----+--- .... ---+ | | | | | Append Append f[last] | | | | | | f[0] delim f[1] delim | open
- Parameters:
open- the format at the very left of the result, like an open parenthesisouterCombinator- how to combine open, the inner list, and closedelim- the format to separate the elements of the list, like a commainnerCombinator- how to combine the elements of the inner listclose- the format at the very right of the result, like a closing parenthesisformats- the sequence of inner elements.- Returns:
- the complete tree of format objects which represents the lis
-
singleLine
Wraps the given data into a single-line Java-style comment.For the final rendering to be meaningful, the result must be rendered in one single line. The current implementation cannot guarantee that a particular format tree will be renedered in only one line, except for a stand-alone literal. The user is responsible that the length of the character data and the rendering conditions give a correct result.
- Parameters:
format- the contents of the Java doc comment.- Returns:
- a comment format in the style of a Java doc comment.
- Throws:
IllegalArgumentException- when the content is known not to fit into one single line.
-
apiDoc
Wraps the given data into a Java-style doc comment.- Parameters:
formats- the contents of the Java doc comment- Returns:
- a comment format in the style of a Java doc comment.
-
multiLine
Wraps the given data into a Java-style non-doc multi-line comment.- Parameters:
formats- the contents of the Java comment- Returns:
- a comment format in the style of a Java non-doc comment.
-
quoteJavaStyle
Creates a literal format with all doublequotes contained in the text escaped with a backslash.- Parameters:
f- the text contents of which is quoted and returned.- Returns:
- a format with the quoted contents
-