Class ATextOutputStream

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ATextOutputStream = class(AStreamWrapper)

Description

This class serves as the basis for a class which wraps around other instances of AStream and provides the ability to treat the data to be written to the stream as text. In particular, this class supports printing ASCII- or UTF-8-encoded streams, as well as Unicode strings and WideStrings.

Hierarchy

Overview

Methods

Public function write(const count: TStreamIOSize; const source): TStreamIOSize; override;
Public function print(const str: AnsiString): TStreamIOSize; virtual;
Public function printEach(const vals: array of const): TStreamIOSize; virtual;
Public function printWrapped(const str: AnsiString; const breakCharacters: array of string; thisLineLength: longword = 0; const firstLineStartColumn: longword = 0; const remainingLinesStartColumn: longword = 0; padCharacter: string = ''; const lineBreakCharacter: string = System.lineEnding): TStreamIOSize;
Public function lineLength: longword; virtual;

Description

Methods

Public function write(const count: TStreamIOSize; const source): TStreamIOSize; override;

Write count bytes from source to the stream.

This method simply passes the read call through to AStreamWrapper.Target. It does not attempt to interpret the data written. To print one or more strings, call ATextOutputStream.print or ATextOutputStream.printEach.

Returns

The total number of bytes written to the stream. This value may be less than count if the end of the stream was encountered while writing.

Public function print(const str: AnsiString): TStreamIOSize; virtual;

Print the specificed string to the stream.

This method will print the contents of str to the stream. It is primarily designed to be used with text-based output streams, such as AStandardOutputStream, since it does not record the length of the string so that it can be read later. To write a string, including its length, to the stream, use AStream.writeString instead.

Returns

The total number of bytes printed to the stream. This value will be zero if str is an empty string.

Public function printEach(const vals: array of const): TStreamIOSize; virtual;

Print each value in vals to the stream.

This method is defined and implemented as a convenience function; it writes a string representation of each variable provided in vals to the stream.

It is possible to pass instances of objects to this routine, but they must be members of a class that implements CanPrint. This routine will call the printTo method for all such instances passed. All other object instances passed to this routine are ignored.

If a class reference is passed to this routine, it will output a string containing the name of the class.

Returns

The total number of bytes printed to the stream. This value may be less than expected if certain items in vals were skipped.

Public function printWrapped(const str: AnsiString; const breakCharacters: array of string; thisLineLength: longword = 0; const firstLineStartColumn: longword = 0; const remainingLinesStartColumn: longword = 0; padCharacter: string = ''; const lineBreakCharacter: string = System.lineEnding): TStreamIOSize;

Print the selected string to the stream, breaking into lines and then wrapping and justifying those lines as necessary.

str is broken into one or more lines that are no more than thisLineLength characters in length. If thisLineLength is zero (0), then this method uses the value of ATextOutputStream.lineLength instead.

str is broken into lines only where the characters specified by breakCharacters are encountered within the string. The default characters in tosWrapDefaultBreakCharacters can be used if the caller does not wish to specify other characters. In any case, breakCharacters should contain ASCII or UTF-8 encoded characters. Only the first such character from each element in breakCharacters is used; if the strings in breakCharacters contain more than one character, the extraneous characters are ignored.

The first line that is printed is padded on the left by a repeating sequence of the characters specified by padCharacter, which should contain an ASCII or UTF-8 encoded character. Only the first such character from padCharacter is used; if it contains others, they are ignored. The number of times padCharacter is used for the first line is determined by firstLineStartColumn; if that value is zero, then the first line is not padded.

The remaining lines that are printed are padded on the left by the same repeating sequence of characters specified by padCharacter. The number of times padCharacter is used for each remaining line is determined by remainingLinesStartColumn; if that value is zero, the remaining lines are not padded.

If padCharacter is an empty string, the value specified by tosWrapDefaultPadCharacter is used.

For more information on the various parameters accepted by this routine, see AStringList.wrapString.

Returns

The total number of bytes printed to the stream. If str is an empty string, this method does nothing and returns zero (0).

Public function lineLength: longword; virtual;

Determine the maximum length of a printed line, in characters.

The value returned by this method indicates the maximum number of characters that may be printed on a single line before the line is forcibly wrapped by the underlying device.

The base implementation of this method simply returns the value of tosDefaultLineLength, but descendant classes may override this behavior to return a different value.

This value is used by ATextOutputStream.printWrapped to wrap text so that it fits within the boundaries of the target stream.


Generated by PasDoc 0.13.0 on 2015-06-23 19:40:11