Class Writef

  • All Implemented Interfaces:
    KnowledgeBaseConsumer, PredicateFactory

    public final class Writef
    extends AbstractSingleResultPredicate
    writef(X,Y) - writes formatted text to the output stream.

    The first argument is an atom representing the text to be output. The text can contain special character sequences which specify formatting and substitution rules.

    Supported special character sequences are:

    Sequence Action
    \n Output a 'new line' character (ASCII code 10).
    \l Same as \n.
    \r Output a 'carriage return' character (ASCII code 13).
    \t Output a tab character (ASCII code 9).
    \\ Output the \ character.
    \% Output the % character.
    \\uNNNN Output the unicode character represented by the hex digits NNNN.
    %t Output the next term - in same format as write/1.
    %w Same as \t.
    %q Same as \t.
    %p Same as \t.
    %d Output the next term - in same format as write_canonical/1.
    %f Ignored (only included to support compatibility with other Prologs).
    %s Output the elements contained in the list represented by the next term.
    %n Output the character code of the next term.
    %r Write the next term N times, where N is the value of the second term.
    %Nc Write the next term centered in N columns.
    %Nl Write the next term left-aligned in N columns.
    %Nr Write the next term right-aligned in N columns.

    writef(X) produces the same results as writef(X, []).

    • Constructor Detail

      • Writef

        public Writef()
    • Method Detail

      • format

        private java.lang.StringBuilder format​(java.lang.String text,
                                               java.util.List<Term> args)
      • parsePercentEscapeSequence

        private void parsePercentEscapeSequence​(Writef.Formatter f)
      • repeat

        private java.lang.String repeat​(java.lang.String text,
                                        long timesToRepeat)
      • getWhitespace

        private java.lang.String getWhitespace​(int diff)
      • parseSlashEscapeSequence

        private void parseSlashEscapeSequence​(Writef.Formatter f)
      • isNumber

        private boolean isNumber​(int c)
      • print

        private void print​(java.lang.StringBuilder sb)