Class Formats
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final int
static final int
static final String
String formatting template for date and time.static final Pattern
static final Pattern
static final int
static final Pattern
Matches all combinations of "carriage return" and "linefeed", where both appear at most once each.static final Pattern
Matches one single "linefeed", "carriage return", or "horizontal tab" character.static final Pattern
Matches arbitrary non-empty sequemces of blanks and horizontal tabs.static final Pattern
Matches arbitrary non-empty sequemces of blanks and horizontal tabs and numbered variables. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
anonymiseLocalFile
(String path) static Format
Wraps the given data into a Java-style doc comment.static String
Returns the given date in the format defined byformat_dateAndTime
.static String
Returns the current state of the calendaric clock in the format defined byformat_dateAndTime
.extractDate
(String generationComment) Extract the date info from a generation comment.static Format
generationComment
(String name_program, @Opt String name_version, int escapemode, boolean html_breaks, String[] args) Generates a Format which can be used to document the command line call.static Format
generationComment
(String main_class, @Opt String descriptive_name, @Opt String name_version, String dateAndTime, int escapemode, boolean html_breaks, String[] args) Generates a Format which can be used to document the command line call, which initiated the generation of a certain Java source file.static Format
generationComment
(String main_class, @Opt String name_version, String dateAndTime, int escapemode, boolean html_breaks, String[] args) Deprecated, for removal: This API element is subject to removal in a future version.for older versions only.static String
generationText
(String prefix, String[] args, int blankEscapeMode, String argSeparator, String lineSeparator, int maxWidth) Generate a primitive string which explains the parameters of a tool application.static Format
list
(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, Format... formats) static Format
list
(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, Iterable<? extends Format> formats) 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 ofFormat
s.static Format
Same aslist(Format,CompoundConstructor,Format,CompoundConstructor,Format,List)
, whereouterCombinator
defaults toCompoundConstructor.beside
andinnerCombinator
defaults toCompoundConstructor.line
static Format
Same aslist(Format,CompoundConstructor,Format,CompoundConstructor,Format,List)
, whereouterCombinator
defaults toCompoundConstructor.beside
andinnerCombinator
defaults toCompoundConstructor.line
static Format
Wraps the given data into a Java-style non-doc multi-line comment.static Format
Creates a literal format which chooses quote symbols not appearing in the data, in XML style.static Format
Creates a literal format which quoted doublequotes by escaping them with a backslash.static String
removeHtml
(String orig) Useful when a comment string shall be used in an HTML body but also in an HTML comment, etc.static String
Replaces all occurences of "linefeed", "carriage return", or "horizontal tab" character by a space character.static Format
singleLine
(Format format) Wraps the given data into a Java-style single-line comment.static String
stringescape
(String data, int mode) Escapes blank characters in the given datum according to the methods selected by the mode parameter:no_escape
, no change,escape_blanks_individually
, escape each blank with an own backslash, orescape_frame_with_doublequotes
, frame whole string with double quotes and escape all internal double quotes with a backslash.static Format
Convenience method for translating multi-line text into a complex format hierarchy.static Format
textWithVars
(String txt) Transform a text into a complex Format structure, addtionally detecting references to numeric variables.
-
Field Details
-
pattern_newline
Matches all combinations of "carriage return" and "linefeed", where both appear at most once each. -
pattern_ws
Matches arbitrary non-empty sequemces of blanks and horizontal tabs. -
pattern_wsWithVars
Matches arbitrary non-empty sequemces of blanks and horizontal tabs and numbered variables. -
no_escape
public static final int no_escape -
escape_frame_with_doublequotes
public static final int escape_frame_with_doublequotes -
escape_blanks_individually
public static final int escape_blanks_individually -
pattern_newlineAndTabs
Matches one single "linefeed", "carriage return", or "horizontal tab" character. -
format_dateAndTime
String formatting template for date and time. This string passed as the format control toString.format(String,Object...)
with someGregorianCalendar
as second argument. Date and Time format is set to the same format as the shell function "makedate" in "etc/calltools.mk", (beside that the latter does currently not include seconds.)
The result looks like
2009-07-21_01h09m07s
Please note that the day-part is defined by the Java string formatting standard code "%tF", which directly corresponds to "%tY-%tm-%td", and thus verbatim to ISO 8601
The time-of-day part closely follows the "extended format" of ISO 8601 cf. ISO 8601/en and ISO 8601/de
BUT the separation character "." is replaced by "h" and "m", to make the string usable as a file name/time stamp! (windoof does not allow colon in file names, and you shouldn't try with unix.)Alternatives would have been ...
- better readable "
%tF %tHh%tMm%tS
" - older version "
%tF %tT
" - completely consistent with "extended" format from
ISO8601 is "
%tFT%tT
"
- See Also:
- better readable "
-
CREATED_ON
- See Also:
-
htmlTag
-
htmlBrTag
-
-
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
Format.Append
with 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 use frame with single quotes. -
quoteJavaStyle
Creates a literal format which quoted doublequotes by escaping them with a backslash. (This is similar toGeneratedLiteral.quote(String)
, which replaces even more special characters.)- Parameters:
f
- the text contents of which is quoted and returned.
-
text
Convenience method for translating multi-line text into a complex format hierarchy. The result will have the structureBeneath | 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) results to space on the upper level, under the Beneath combinator. -
textWithVars
Transform a text into a complex Format structure, addtionally detecting references to numeric variables. Seetext(java.lang.String)
for details. Additionally all substrings from {code #0} to {code #9} are translated to instances ofFormat.BoundVariable
. -
list
public static Format list(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, Iterable<? extends Format> formats) -
list
Same aslist(Format,CompoundConstructor,Format,CompoundConstructor,Format,List)
, whereouterCombinator
defaults toCompoundConstructor.beside
andinnerCombinator
defaults toCompoundConstructor.line
-
list
Same aslist(Format,CompoundConstructor,Format,CompoundConstructor,Format,List)
, whereouterCombinator
defaults toCompoundConstructor.beside
andinnerCombinator
defaults toCompoundConstructor.line
-
list
public static Format list(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, Format... formats) -
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 ofFormat
s. The structure which is created is determinded toouter combinator | | | | | close | | | inner comb.-----+--- .... ---+ | | | | | Append Append f[last] | | | | | | f[0] delim f[1] delim | open
(The argument type "List" instead of "Iterable" has been chosen because addtional length information is convenient for the implementation.)- 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.
-
singleLine
Wraps the given data into a Java-style single-line comment. ASSUMES that argument does not contain line breaks. -
apiDoc
Wraps the given data into a Java-style doc comment. -
multiLine
Wraps the given data into a Java-style non-doc multi-line comment. -
stringescape
Escapes blank characters in the given datum according to the methods selected by the mode parameter:-
no_escape
, no change, -
escape_blanks_individually
, escape each blank with an own backslash, - or
escape_frame_with_doublequotes
, frame whole string with double quotes and escape all internal double quotes with a backslash.
-
-
replaceNewlinesAndTabs
Replaces all occurences of "linefeed", "carriage return", or "horizontal tab" character by a space character. . -
dateNow_standardFormat
Returns the current state of the calendaric clock in the format defined byformat_dateAndTime
. -
date_standardFormat
Returns the given date in the format defined byformat_dateAndTime
. -
anonymiseLocalFile
-
generationText
public static String generationText(String prefix, String[] args, int blankEscapeMode, String argSeparator, String lineSeparator, int maxWidth) Generate a primitive string which explains the parameters of a tool application. Concatenates the prefix and the sequence of args, after blank escaping. It joins the args by argSeparator, or by lineSeparator whenever the line length reaches maxWidth.All strings in the "args[]" array are considered as potential file paths and thus (heuristically) anonymized by calling
anonymiseLocalFile(String)
.- Parameters:
prefix
- first part of comment which will not be altered.args
- arguments to the generation command: blanks will be replacedblankEscapeMode
- seestringescape(String,int)
argSeparator
- to be inserted after every arglineSeparator
- to be inserted when line length is oversteppedmaxWidth
- maximal line length
-
generationComment
public static Format generationComment(String main_class, @Opt @Opt String descriptive_name, @Opt @Opt String name_version, String dateAndTime, int escapemode, boolean html_breaks, String[] args) Generates a Format which can be used to document the command line call, which initiated the generation of a certain Java source file.The format returned by this method can be attached to the generated structure by calling
GeneratedAnnotationTarget.addComment(Format)
orGeneratedAnnotationTarget.addComment(Format)
It can of course also be converted to a string (containing line breaks) by result.toString(70), etc., as documented withFormat
.
The result will look likeCreated on
All strings in the "args" array are considered as potential file paths and thus (heuristically) anonymized by callingby (= ) (version )? command line: anonymiseLocalFile(String)
.- Parameters:
main_class
- must be given,descirptive_name
- is optional and may contain blanks and special charactersname_version
- may be==null
, omitting the "version ..." textdateAndTime
- must be given,escapemode
- how arg-strings which contain whitespace shall be encoded, seestringescape(String,int)
html_breaks
- whether to insert html line break commands and other markup.args
- the arguments which reachedstatic void main()
-
extractDate
Extract the date info from a generation comment. This is sensible to avoid the necessity of passing around two different but functional dependent parameters, when the date is required for a html meta element and the whole generationComment for a comment. -
generationComment
public static Format generationComment(String name_program, @Opt @Opt String name_version, int escapemode, boolean html_breaks, String[] args) Generates a Format which can be used to document the command line call. Acts asgenerationComment(String,String,String,int,boolean,String[])
, but usesdateNow_standardFormat()
for date and time.- Parameters:
name_program
- must be given,name_version
- may be==null
, omitting the "version ..." textescapemode
- how arg-strings which contain whitespace shall be encoded, seestringescape(String,int)
html_breaks
- whether to insert html line break commands and other markup.args
- the arguments which reachedstatic void main()
-
generationComment
@Deprecated(forRemoval=true) public static Format generationComment(String main_class, @Opt @Opt String name_version, String dateAndTime, int escapemode, boolean html_breaks, String[] args) Deprecated, for removal: This API element is subject to removal in a future version.for older versions only.Calls#generationText(String,String,int, boolean, String[])
with no descirptive name. -
removeHtml
Useful when a comment string shall be used in an HTML body but also in an HTML comment, etc.
-