Seed7 - The extensible programming language
Seed7 FAQ Manual Screenshots Examples Libraries Algorithms Download Links
Libraries AES ARC4 Array ASN.1 Bigfile Bigint Bigrat Bin32 Bin64 Bitdata Bitmapfont Bitset Bitsetof Boolean Browser Bstring Bytedata Cards Category CC config Cgi Cgi dialog Char Charsets Cipher Clib_file Color CLI Commands Complex Console Crc32 Deflate DES Dialog Dir Draw Duration Echo Editline Enable_input Enable_io Enable_output Encoding Environment External_file File File system Float Font Forloop Ftp Getf Gethttp Gethttps Graph Graph_file Gzip Hash Hashsetof Hmac Html_ent Httpserv Idxarray Image Inflate Inflate file Inifile Integer Keybd Line Listener LZW Make Math Msgdigest Null_file Osfiles Picture utility Pixmap_file Pixmapfont PKCS #1 Poll Process Progs Propertyfile Rational Reference Ref_list Scanfile Scanstri Set Shell Smtp Sockbase Socket SQL base Stdio Strifile String Stritext Subrange Tar Text Time TLS/SSL Triple DES Unicode Utf16 Utf8 Vectorfont 3D Vector Wildcard Window Wrinum X.509 Xmldom Xml_ent Zip
Libraries
Utf8 Source Code
 previous   up   next 

Types
utf8_file
File implementation type for UTF-8 files.

utf8_file

const type: utf8_file

File implementation type for UTF-8 files. This type supports UTF-8 encoded sequential files of the operating system. UTF-8 files are seekable, therefore they support the functions length, seek and tell.


Variable Summary
utf8_file
STD_UTF8_IN
UTF-8 version of the standard input file of the operating system.
utf8_file
STD_UTF8_OUT
UTF-8 version of the standard output file of the operating system.
utf8_file
STD_UTF8_ERR
UTF-8 version of the standard error file of the operating system.

Function Summary
file
openUtf8 (in string: path, in string: mode)
Opens an Unicode file which uses the UTF-8 encoding.
void
write (in utf8_file: outFile, in string: stri)
Write a string to an UTF-8 file.
char
getc (in utf8_file: inFile)
Read a character from an UTF-8 file.
string
gets (in utf8_file: inFile, in integer: maxLength)
Return a string read with a maximum length from an UTF-8 file.
string
getwd (inout utf8_file: inFile)
Read a word from an UTF-8 file.
string
getln (inout utf8_file: inFile)
Read a line from an UTF-8 file.
void
seek (in utf8_file: aFile, in integer: position)
Set the current file position.

Variable Detail

STD_UTF8_IN

var utf8_file: STD_UTF8_IN

UTF-8 version of the standard input file of the operating system. Reading from STD_UTF8_IN can be done with e.g.:

read(STD_UTF8_IN, aVariable);

It is also possible to redirect STD_UTF8_IN to the default input of read with:

IN := STD_UTF8_IN;

Afterwards

read(aVariable);

reads from STD_UTF8_IN.


STD_UTF8_OUT

var utf8_file: STD_UTF8_OUT

UTF-8 version of the standard output file of the operating system. Writing to STD_UTF8_OUT can be done with e.g.:

write(STD_UTF8_OUT, something);

It is also possible to redirect the default output of write to STD_UTF8_OUT with:

OUT := STD_UTF8_OUT;

Afterwards

write(something);

writes to STD_UTF8_OUT.


STD_UTF8_ERR

var utf8_file: STD_UTF8_ERR

UTF-8 version of the standard error file of the operating system. Writing to STD_UTF8_ERR can be done with e.g.:

write(STD_UTF8_ERR, something);

Function Detail

openUtf8

const func file: openUtf8 (in string: path, in string: mode)

Opens an Unicode file which uses the UTF-8 encoding. The file is opened with the specified path and mode. There are text modes and binary modes:

  • Binary modes:
    • "r" Open file for reading.
    • "w" Truncate to zero length or create file for writing.
    • "a" Append; open or create file for writing at end-of-file.
    • "r+" Open file for update (reading and writing).
    • "w+" Truncate to zero length or create file for update.
    • "a+" Append; open or create file for update, writing at end-of-file.
  • Text modes:
    • "rt" Open file for reading.
    • "wt" Truncate to zero length or create file for writing.
    • "at" Append; open or create file for writing at end-of-file.
    • "rt+" Open file for update (reading and writing).
    • "wt+" Truncate to zero length or create file for update.
    • "at+" Append; open or create file for update, writing at end-of-file.

Note that this modes differ from the ones used by the C function fopen().

Parameters:
path - Path of the file to be opened. The path must use the standard path representation.
mode - Mode of the file to be opened.
Returns:
the file opened, or STD_NULL if it could not be opened or when path refers to a directory.
Raises:
MEMORY_ERROR - Not enough memory to convert the path to the system path type.
RANGE_ERROR - The mode is not one of the allowed values or path does not use the standard path representation or path cannot be converted to the system path type.

write

const proc: write (in utf8_file: outFile, in string: stri)

Write a string to an UTF-8 file.

Raises:
FILE_ERROR - A system function returns an error.

getc

const func char: getc (in utf8_file: inFile)

Read a character from an UTF-8 file.

Returns:
the character read, or EOF at the end of the file.
Raises:
RANGE_ERROR - The file contains an illegal encoding.

gets

const func string: gets (in utf8_file: inFile, in integer: maxLength)

Return a string read with a maximum length from an UTF-8 file.

Returns:
the string read.
Raises:
RANGE_ERROR - The length is negative or the file contains an illegal encoding.

getwd

const func string: getwd (inout utf8_file: inFile)

Read a word from an UTF-8 file. Before reading the word it skips spaces and tabs. The function accepts words ending with ' ', '\t', '\n', "\r\n" or EOF. The word ending characters are not copied into the string. That means that the '\r' of a "\r\n" sequence is silently removed. When the function is left inFile.bufferChar contains ' ', '\t', '\n' or EOF.

Returns:
the word read.
Raises:
RANGE_ERROR - The file contains an illegal encoding.
MEMORY_ERROR - Not enough memory to represent the result.
FILE_ERROR - A system function returns an error.

getln

const func string: getln (inout utf8_file: inFile)

Read a line from an UTF-8 file. The function accepts lines ending with '\n', "\r\n" or EOF. The line ending characters are not copied into the string. That means that the '\r' of a "\r\n" sequence is silently removed. When the function is left inFile.bufferChar contains '\n' or EOF.

Returns:
the line read.
Raises:
RANGE_ERROR - The file contains an illegal encoding.
MEMORY_ERROR - Not enough memory to represent the result.
FILE_ERROR - A system function returns an error.

seek

const proc: seek (in utf8_file: aFile, in integer: position)

Set the current file position. The file position is measured in bytes from the start of the file. The first byte in the file has the position 1. When the file position would be in the middle of an UTF-8 encoded character the position is advanced to the beginning of the next UTF-8 character.

Raises:
RANGE_ERROR - The file position is negative or zero or the file position is not representable in the system file position type.
FILE_ERROR - A system function returns an error.


 previous   up   next