BRL.TextStream
The Text Stream module allows you to load and save text in a number of formats: LATIN1, UTF8 and UTF16.
The LATIN1 format uses a single byte to represent each character, and is therefore only capable of manipulating 256 distinct character values.
The UTF8 and UTF16 formats are capable of manipulating up to 1114112 character values, but will generally use greater storage space. In addition, many text processing applications are unable to handle UTF8 and UTF16 files.
Functions
Function LoadText$( url:Object, checkForUTF8:Int = True )
Load text from a stream
LoadText loads LATIN1, UTF8 or UTF16 text from url.
The first bytes read from the stream control the format of the text:
&$fe $ff | Text is big endian UTF16 |
&$ff $fe | Text is little endian UTF16 |
&$ef $bb $bf | Text is UTF8 |
If the first bytes don't match any of the above values, the stream is assumed to contain LATIN1 text. Additionally, when checkForUTF8 is enabled, the stream will be tested for UTF8 compatibility, and loaded as such as appropriate.
A TStreamReadException is thrown if not all bytes could be read.
Returns
A string containing the text
Function SaveText:Int( str$,url:Object, format:ETextStreamFormat = ETextStreamFormat.LATIN1, withBOM:Int = True )
Save text to a stream
SaveText saves the characters in str to url.
If str contains any characters with a character code greater than 255, then str is saved in UTF16 format. Otherwise, str is saved in LATIN1 format.
A TStreamWriteException is thrown if not all bytes could be written.