Location:
txtetext.h
Link against: etext.lib
CPlainText
Supported from 5.0
Stores and manipulates plain text.
Plain text cannot be displayed, so this class provides no support for formatting. It is purely an in-memory buffer for text, and provides services that act upon it. These services include the following: import from and export to streams, optionally translating between Unicode and other encodings; reading and writing of field data; extraction of text; finding word and paragraph boundaries.
The type and size of in-memory buffer can be specified upon object
construction. However, if no specification is provided a buffer is provided
with default settings. There are two types of storage buffer:
segmented buffers and flat buffers. The default buffer for plain text is
segmented (CBufSeg
). This is most efficient when a large quantity
of text is to be stored, or will have a large dynamic range. A flat buffer
(CBufFlat
) is most appropriate for storing small quantities of
text of bounded length. For most uses, however, a segmented buffer is
sufficient.
|
Defined in CPlainText
:
Anonymous
, CharPosOfParagraph()
, ComponentInfo()
, ConvertAllFieldsToText()
, ConvertFieldToText()
, CopyToStoreL()
, DeleteL()
, DocumentLength()
, EOrganiseByLine
, EOrganiseByParagraph
, EScanBackwards
, EScanEndOfData
, EScanJoinDelimiters
, EScanPictureIsDelimiter
, EScanPunctuationIsDelimiter
, EScanStayIfBoundary
, EScanToUnitEnd
, EScanToUnitStart
, ExportAsTextL()
, ExportTextL()
, ExternalizeFieldDataL()
, ExternalizeL()
, ExternalizePlainTextL()
, ExternalizePlainTextNoLengthCountL()
, Extract()
, FieldCount()
, FieldFactory()
, FindFields()
, GetWordInfo()
, ImportTextFileL()
, ImportTextL()
, InsertFieldL()
, InsertL()
, InternalizeFieldDataL()
, InternalizeL()
, InternalizePlainTextL()
, NewL()
, NewTextFieldL()
, PageContainingPos()
, ParagraphCount()
, ParagraphNumberForPos()
, PasteFromStoreL()
, Read()
, RemoveField()
, Reset()
, RestoreComponentsL()
, RestoreFieldComponentsL()
, ScanParas()
, ScanWords()
, SetFieldFactory()
, SetPageTable()
, StoreComponentsL()
, StoreFieldComponentsL()
, TImportExportParam
, TImportExportResult
, TScanDataEnd
, TTextOrganisation
, TextField()
, ToParagraphStart()
, UpdateAllFieldsL()
, UpdateFieldL()
, WordCount()
, ~CPlainText()
Inherited from CBase
:
operator new()
Inherited from CEditableText
:
EDefaultTextGranularity
,
EFlatStorage
,
ELineBreak
,
ENonBreakingHyphen
,
ENonBreakingSpace
,
ENonBreakingTab
,
EPageBreak
,
EParagraphDelimiter
,
EPictureCharacter
,
EPotentialHyphen
,
ESegmentedStorage
,
ETabCharacter
,
EVisibleSpaceCharacter
,
HasChanged()
,
RestoreL()
,
SetHasChanged()
,
StoreL()
,
TDocumentStorage
static CPlainText* NewL(TDocumentStorage aStorage=ESegmentedStorage,TInt aDefaultTextGranularity=EDefaultTextGranularity);
static CPlainText* NewL(const CStreamStore& aStore,TStreamId aStreamId,
MTextFieldFactory* aFieldFactory=NULL,TDocumentStorage aStorage=ESegmentedStorage);
Allocates and constructs a plain text object — overloaded function. The text object's contents may be restored from a stream store. If the text object supports fields, a field factory should be specified.
|
|
virtual ~CPlainText();
The destructor frees the object's text storage and field set, prior to its destruction.
virtual void InternalizeL(RReadStream& aStream);
Internalises the text object's text content and field set from a
read stream. The presence of this function means that the standard templated
operator>>()
(defined in s32strm.h)
is available to internalise objects of this class. InternalizeL()
has construct rather than assignment semantics. You should not use it for fully
initialised objects.
|
virtual void ExternalizeL(RWriteStream& aStream)const;
Externalises a plain text object to a write stream. The presence of
this function means that the standard templated operator<<()
(defined in s32strm.h) is available to
externalise objects of this class.
|
virtual void StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap)const;
Stores the plain text object's components to the stream store specified.
|
virtual void RestoreComponentsL(const CStreamStore& aStore);
Restores the plain text object's field set from a stream store.
|
void InternalizePlainTextL(RReadStream& aStream);
void InternalizePlainTextL(RReadStream& aStream,TInt aLength);
Internalises an empty text object's text content from a read stream — overloaded function.
This function has construct rather than assignment semantics. You should not use it for fully initialised objects.
Note
The overload which takes a length argument is not intended for general use and its use is deprecated.
|
void ExternalizePlainTextL(RWriteStream& aStream)const;
Externalises the plain text object's text content (preceded by a length count) to a write stream.
|
void ExternalizePlainTextNoLengthCountL(RWriteStream& aStream)const;
Externalises the plain text object's text content to a write stream. This
function differs from ExternalizePlainTextL()
in that it does not
precede the text content with a length count.
This function is not intended for general use and is deprecated.
virtual TInt ImportTextFileL(TInt aPos,const TDes& aFileName,TTextOrganisation aTextOrganisation);
Imports a plain text file into this text object.
Translates non-printing characters in the source text file into EPOC special characters,
for instance tabs are converted into
CEditableText::ETabCharacter
s, and form feeds into
CEditableText::EPageBreak
s. Line feeds in the source text file are
translated according to the aTextOrganisation
argument.
The function leaves if there is any problem in opening the file.
|
|
void ImportTextL(TInt aPos,RReadStream& aInput,TTextOrganisation aTextOrganisation,TInt aMaxOutputChars = KMaxTInt,TInt aMaxInputChars = KMaxTInt, TInt* aOutputChars = NULL,TInt* aInputChars = NULL);
Imports plain text from a stream into this text object.
Translates line feeds in the source text according to the aTextOrganisation
argument.
|
void ImportTextL(TInt aPos,RReadStream& aInput,const TImportExportParam& aParam,TImportExportResult& aResult);
Supported from 6.1
Imports plain text from a stream into this text object, optionally converting it from a foreign encoding into Unicode.
|
virtual void ExportAsTextL(const TDes& aFileName,TTextOrganisation aTextOrganisation,TInt aMaxLineLength)const;
Writes the contents of the plain text object to a text file.
The filename is given by aFileName
. Any existing file with that name is replaced. A wrap width can be specified. This is only used when exporting by line (aTextOrganisation
is
EOrganiseByLine
).
The function leaves if there is any problem in creating or replacing the file.
|
void ExportTextL(TInt aPos,RWriteStream& aOutput,TTextOrganisation aTextOrganisation, TInt aMaxOutputChars = KMaxTInt,TInt aMaxInputChars = KMaxTInt, TInt aMaxLineLength = KMaxTInt, TInt* aOutputChars = NULL,TInt* aInputChars = NULL) const;
Writes plain text to a stream.
A wrap width can be specified. This is only relevant when exporting by line, (aTextOrganisation
is CPlainText::EOrganiseByLine
). When the line length reaches the wrap width, a
carriage return/line feed is inserted. When exporting text by paragraph, the
wrap width is disregarded.
|
void ExportTextL(TInt aPos,RWriteStream& aOutput,const TImportExportParam& aParam,TImportExportResult& aResult) const;
Supported from 6.1
Writes plain text to a stream, optionally converting it from Unicode into a foreign encoding.
|
void StoreFieldComponentsL(CStreamStore& aStore,CStoreMap& aMap)const;
Stores the plain text object's field components to a stream store.
|
void RestoreFieldComponentsL(const CStreamStore& aStore);
Restores the plain text object's field set.
|
void ExternalizeFieldDataL(RWriteStream& aStream)const;
Externalises the plain text object's field set.
|
void InternalizeFieldDataL(RReadStream& aStream);
Internalizes the field set.
|
virtual void CopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength)const;
Copies plain text including fields, if present, to the clipboard.
A panic occurs in any of the following circumstances:
aPos
is invalid
aLength
is invalid (zero or less)
the sum of aPos
and aLength
is greater than or
equal to the number of characters in the document
|
virtual TInt PasteFromStoreL(const CStreamStore& aStore,const CStreamDictionary& aDictionary,TInt aPos);
Pastes plain text and fields, if present, from the clipboard into the current text object at the specified document position. The entire contents of the store are pasted.
|
|
virtual TInt DocumentLength()const;
Gets the the number of characters in the text object.
Note: the count includes all non-printing characters but excludes the end of text paragraph delimiter, so that the smallest possible return value is zero.
|
virtual TInt WordCount()const;
Gets a count of the number of words in the text object.
|
virtual TInt ParagraphCount()const;
Gets a count of the number of paragraphs in the text object.
Note: the paragraph delimiter which terminates every text object means this function always returns a count of at least one.
|
virtual TInt ScanWords(TInt& aPos,TUint& aScanMask)const;
Scans from a document position to the beginning or end of a word. The destination is determined by a scan mask. The scan can either be forwards (the default) or backwards, and the destination may be the first or last character in the word containing the position, or the first character in the next word.
Note:
If an attempt is made to scan beyond the end of text delimiter, on return, aPos
is set to
EScanEndOfData
(= – 1) and the function’s return value
indicates the number of characters skipped in passing the end of text
delimiter.
|
|
virtual TInt ScanParas(TInt& aPos,TUint& aScanMask)const;
Scans from a document position to the beginning or end of a paragraph. The destination is determined by a scan mask. The scan can either be forwards (the default) or backwards, and the destination may be the first or last character in the paragraph containing the position, or the first character in the next paragraph.
Note: if an attempt is made to scan beyond the end of text delimiter, on return, aPos
is set to
EScanEndOfData
(= – 1) and the function’s return value
indicates the number of characters skipped in passing the end of text
delimiter.
|
|
virtual TInt ToParagraphStart(TInt& aPos)const;
Gets the document position of the start of the paragraph containing the specified document position.
|
|
virtual void GetWordInfo(TInt aCurrentPos,TInt& aStartPos,TInt& aLength,TBool aPictureIsDelimiter,TBool aPunctuationIsDelimiter)const;
Gets the start position and length of the word that contains the document position specified.
|
virtual TEtextComponentInfo ComponentInfo()const;
Gets information about the number of components contained in the text object. For plain text, only the field count has relevance.
|
void SetPageTable(TPageTable* aPageTable);
Links the text object to a page table. A page table is an array of integers; each integer represents the number of characters on a page. It is required for pagination. The page table is updated when changes are made to the document, e.g. after pasting from the clipboard, inserting, importing or deleting text.
The text object does not take ownership of the page table specified.
|
TInt PageContainingPos(TInt aPos)const;
Gets the number of the page which contains the specified document
position. If no page table has been set up, the function returns a value of
zero. Use SetPageTable()
to set up the page table.
|
|
virtual TInt CharPosOfParagraph(TInt& aLength,TInt aParaOffset)const;
Finds the length and the start position of a paragraph identified by its paragraph number — the first paragraph is numbered zero.
Notes:
if aParaOffset
is invalid, (equal to or greater than the
total number of paragraphs), the function’s return value is
EScanEndOfData
(= – 1)
|
|
virtual TInt ParagraphNumberForPos(TInt& aPos)const;
Gets the number of the paragraph which contains a document position. Paragraph numbering begins at zero.
|
|
void ConvertAllFieldsToText();
Removes all fields from the text object's field set, leaving their current text value in the text object. Does not update the fields beforehand.
TBool ConvertFieldToText(TInt aPos);
Converts the field containing the specified document position into text, leaving its current value in the text object. Does not update the field beforehand.
|
|
TInt FieldCount() const;
Gets a count of the number of fields in the text object's field set.
|
const MTextFieldFactory* FieldFactory()const;
Gets a pointer to the field factory used by the text object. The field
factory may be set up using SetFieldFactory()
, or may be specified
in the NewL()
.
|
void SetFieldFactory(MTextFieldFactory* aFactory);
Sets up a field factory. A field factory is an instance of a class
deriving from MTextFieldFactory
. It must implement a
NewFieldL()
function to create and return fields of the desired
type. The field factory's NewFieldL()
function is called by
CPlainText::NewTextFieldL()
. A field factory must be set up if you
intend to add any fields to the text object.
|
TBool FindFields(TInt aPos) const;
TBool FindFields(TFindFieldInfo& aInfo,TInt aPos,TInt aRange=0) const;
Tests whether a document position is located within a field — overloaded function.
The second overload extracts information about all fields located within a range of characters.
|
|
void InsertFieldL(TInt aPos,CTextField* aField,TUid aFieldType);
Inserts a field into the text object at a specified document position.
Note:
After insertion, the field should be evaluated in order to make its
contents visible; use UpdateFieldL()
.
|
TBool RemoveField(TInt aPos);
Removes the field covering the document position specified from the field set, and deletes all text content associated with the field from the text object.
|
|
CTextField* NewTextFieldL(TUid aFieldType)const;
Creates and returns a new field. Before calling this function, a field
factory should have been set up, either by calling
SetFieldFactory()
, or by specifying one in the
NewL()
. The field factory's NewFieldL()
function is
called to create a field of the type specified in the argument. A NULL field is
returned if no field factory has been set up.
|
|
const CTextField* TextField(TInt aPos)const;
Returns a pointer to the field located at the specified document position.
|
|
void UpdateAllFieldsL();
Re-evaluates all of the fields in the text object. Re-evaluating a field means calculating the field's new value, then inserting that value into the text object, replacing the previous value.
Note:
Fields have a maximum length of 20 characters.
virtual void UpdateFieldL(TInt aPos);
Re-evaluates the field which covers the document position specified. Re-evaluating a field means calculating the field's new value, then inserting that value into the text object, replacing the previous value.
Notes:
fields have a maximum length of 20 characters
the first time a field is updated, the position specified should be the position at which the field was inserted
|
virtual void Reset();
Deletes all text content, formatting and fields from the document, leaving the single paragraph delimiter which terminates the text object.
virtual void InsertL(TInt aPos,const TChar& aChar);
virtual void InsertL(TInt aPos,const TDesC& aBuf);
Inserts either a single character or a descriptor into the text object at a specified document position. Updates the page table.
|
virtual TBool DeleteL(TInt aPos,TInt aLength);
Deletes one or more characters beginning at, and including, the character at a specified document position. Updates the page table. Any fields wholly contained in the range of characters to delete are removed from the field set.
|
|
virtual TPtrC Read(TInt aStartPos)const;
virtual TPtrC Read(TInt aStartPos,TInt aLength)const;
Gets a read-only view of a portion of the text object.
The extent of the view is the range of characters starting at
aStartPos
and ending at whichever of the following document
positions is reached first:
the end of the document
the end of the segment if using segmented storage (the storage type is
specified in the NewL()
)
if aLength
is specified, the sum of aStartPos
and (aLength
–1)
Therefore, when using a segmented buffer to store the document, the
length of the resultant view may be less than the requested length. In this
case multiple calls to Read()
may be necessary.
|
|
virtual void Extract(TDes& aBuf,TInt aPos=0)const;
virtual void Extract(TDes& aBuf,TInt aPos,TInt aLength)const;
Copies the contents of the text object into a descriptor — overloaded function. The function copies all characters from and including the document position specified, to the end of the document or the end of the range of characters, if specified.
Notes:
For the two parameter overload, the buffer's maximum length must be greater than or equal to the number of characters to extract, or a panic occurs.
For the three parameter variant, the buffer's maximum length must be
greater than or equal to aLength
, or a panic ocurs.
|
TImportExportParam
Supported from 6.1
Parameters for importing or exporting text using CPlainText::ImportTextL()
or CPlainText::ExportTextL()
.
Defined in CPlainText::TImportExportParam
:
TImportExportParam()
, iFileSession
, iForeignEncoding
, iGuessForeignEncoding
, iInputInternal
, iMaxInputChars
, iMaxLineLength
, iMaxOutputChars
, iOrganisation
, iOutputInternal
TImportExportParam()
TImportExportParam();
Default constructor. All member data is assigned default values. For details, see the member data.
iOrganisation
TTextOrganisation iOrganisation
Controls how line delimiters are translated. By default, EOrganiseByParagraph
.
iMaxOutputChars
TInt iMaxOutputChars
The maximum number of characters to write to the stream (when exporting) or to write to the text object (when importing). By default, KMaxTInt
.
iMaxInputChars
TInt iMaxInputChars
The maximum number of characters to read from the stream (when importing) or to read from the text object (when exporting). By default, KMaxTInt
.
iMaxLineLength
TInt iMaxLineLength
The wrap width as a number of characters.
Only relevant when exporting by line, (iOrganisation
is CPlainText::EOrganiseByLine
). Not used in CPlainText::ImportTextL()
. By default, KMaxTInt
.
iOutputInternal
TBool iOutputInternal
If true, output is in internal format, so is written according to native endianness. Used in CPlainText::ExportTextL()
. By default, false.
iInputInternal
TBool iInputInternal
If true, input is in internal format, so is read according to native endianness. Used in CPlainText::ImportTextL()
. By default, false.
iForeignEncoding
TUint iForeignEncoding
The identifier of the foreign character set encoding to be used to convert from or to.
Not used if iGuessForeignEncoding
is true. If conversion to/from iForeignEncoding
is not available on the device, the function leaves with KErrNotSupported
. By default, zero.
iGuessForeignEncoding
TBool iGuessForeignEncoding
If true, an attempt is made to guess the encoding of the foreign text being imported before converting it into Unicode. Used in CPlainText::ImportTextL()
. If false, the value specified in iForeignEncoding
(if any) is used. If none of the available character conversion plug-ins on the device return a confidence level greater than 50%, CPlainText::ImportTextL()
leaves with KErrNotSupported
. By default, false.
iFileSession
RFs* iFileSession
If non-null, a connected file server session used to load character conversion data. Only relevant if the text needs to be converted to or from Unicode. By default, null.
TImportExportResult
Supported from 6.1
Results of importing or exporting text using CPlainText::ImportTextL()
or CPlainText::ExportTextL()
.
Defined in CPlainText::TImportExportResult
:
TImportExportResult()
, iForeignEncoding
, iInputChars
, iOutputChars
TImportExportResult()
TImportExportResult()
Default constructor. All member data is initialised to zero.
iOutputChars
TInt iOutputChars
The number of characters written to the stream (when exporting) or written to this text object (when importing).
iInputChars
TInt iInputChars
The number of characters read from the stream (when importing) or read from this text object (when exporting).
iForeignEncoding
TUint iForeignEncoding
The identifier for the character set encoding selected when importing text whose encoding is guessed (iGuessForeignEncoding
was true).
TScanDataEnd
Used in text scanning functions to indicate the end of the document has been passed.
|
TTextOrganisation
Line delimiter translation.
|
N/A
Scan mask values.
|