Le 09/10/2020 à 10:15, Santiago A. via fpc-pascal a écrit :
Just nitpicking.
Shouldn't "try" be after the "reset" and after the "rewrite"?
Why don't you allow to write an empty string?
Yes, you're right, the Reset/Rewrite should be after the try.
I admit this code is not general, just
> On Oct 9, 2020, at 7:02 AM, Benito van der Zander via fpc-pascal
> wrote:
>
> Writing a file should write the data in a temporary file and then rename the
> temporary file to replace the target file. Otherwise it might destroy the
> target file, without writing the new content, when there
They cannot be used on handles that do not support FileSeek()
(sockets, pipes, stdin/stdout etc.).
Well, it would be better if it could
You can just incrementally resize the return array, when reading
succeeds after seeking fails.
I have a string load function doing that:
El 06/10/2020 a las 01:08, Jean SUZINEAU via fpc-pascal escribió:
In my own code I use BlockRead/BlockWrite, but I'm wondering if I've
not seen this somewhere in RTL.
https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas
> On Oct 8, 2020, at 3:01 PM, Michael Van Canneyt via fpc-pascal
> wrote:
>
> Should be easy enough.
Great, glad this is happening. Let me know if you want some help with these
additions or if it's best for you to just blast through it on you own. Seems
like you know what's best for the
On Thu, 8 Oct 2020, Ryan Joseph via fpc-pascal wrote:
On Oct 6, 2020, at 2:12 AM, Michael Van Canneyt via fpc-pascal
wrote:
// Read raw content as bytes
Function GetFileContents(Const aFileName : RawByteString) : TBytes;
Function GetFileContents(Const aFileName : UnicodeString) :
> On Oct 6, 2020, at 2:12 AM, Michael Van Canneyt via fpc-pascal
> wrote:
>
> // Read raw content as bytes
>
> Function GetFileContents(Const aFileName : RawByteString) : TBytes;
> Function GetFileContents(Const aFileName : UnicodeString) : TBytes;
> Function GetFileContents(Const aHandle :
Here's another interesting option I considered. You can call Scandir which
returns a record with an enumerator. You can then use this to drop right into
the for loop. It doesn't allocate memory and you can break the loop to stop the
iteration. The benefit is you can avoid costly memory
> On Oct 7, 2020, at 2:19 AM, Michael Van Canneyt via fpc-pascal
> wrote:
>
> I see Delphi has something similar, so I will add an implementation. But I
> need to study the options they provide so we can make a reasonably
> compatible version :)
Excellent thanks. It looks like Lazarus has
On Tue, 6 Oct 2020, Ryan Joseph via fpc-pascal wrote:
Since we're on the topic how about another one-liner for reading all the files
in directory into a dynamic array? This has the added benefit of getting
enumeration for free. This is standard stuff for working with files in
scripting
> On Oct 6, 2020, at 1:42 AM, Jer Haan via fpc-pascal
> wrote:
>
> I use this function to read a file into a string:
Not sure how Michael implemented it but we have this in the RTL now, so we can
throw away our ReadFile functions. I have many of those littered around in
various projects so
Since we're on the topic how about another one-liner for reading all the files
in directory into a dynamic array? This has the added benefit of getting
enumeration for free. This is standard stuff for working with files in
scripting languages so I think the FPC RTL should include something like
On Tue, 6 Oct 2020, Bart via fpc-pascal wrote:
On Tue, Oct 6, 2020 at 10:12 AM Michael Van Canneyt via fpc-pascal
wrote:
// Assume TEncoding.SystemEncoding
Function GetFileAsString(Const aFileName : RawByteString) : RawByteString;
// Specify encoding
Function GetFileAsString(Const
On Tue, 6 Oct 2020, Ryan Joseph via fpc-pascal wrote:
On Oct 6, 2020, at 2:12 AM, Michael Van Canneyt via fpc-pascal
wrote:
I added the following functions to the sysutils unit (rev 47056):
Great, thanks Michael.
I've always used AnsiString so why is UnicodeString preferable here?
On Tue, Oct 6, 2020 at 10:12 AM Michael Van Canneyt via fpc-pascal
wrote:
> // Assume TEncoding.SystemEncoding
> Function GetFileAsString(Const aFileName : RawByteString) : RawByteString;
> // Specify encoding
> Function GetFileAsString(Const aFileName : RawByteString; aEncoding :
> TEncoding)
Well, the answer is twofold:
1. IOUtils does not exist yet. Now the OP has a solution.
2. I don't use IOUtils and don't plan to.
Its .NET-like approach has no added value for me.
Just like I don't use rtii unit, but always use the more low-level
typinfo unit.
But once TFile will be
Wouldn't it be better to implement it directly as *IOUtils.TFile* (like
Deplhi)?
*class function ReadAllBytes(const Path: string): TBytes; static;class
function ReadAllLines(const Path: string): TStringDynArray;overload;
static;class function ReadAllLines(const Path: string; const Encoding:
, 2020 12:39:43 PM
To: FPC-Pascal users discussions
Cc: Ryan Joseph
Subject: Re: [fpc-pascal] Adding file to string to the RTL
> On Oct 6, 2020, at 2:12 AM, Michael Van Canneyt via fpc-pascal
> wrote:
>
> I added the following functions to the sysutils unit (rev 47056):
Great, th
> On Oct 6, 2020, at 2:12 AM, Michael Van Canneyt via fpc-pascal
> wrote:
>
> I added the following functions to the sysutils unit (rev 47056):
Great, thanks Michael.
I've always used AnsiString so why is UnicodeString preferable here?
So is the idea we need to specify an UTF-8 encoding
On Mon, 5 Oct 2020, Ryan Joseph via fpc-pascal wrote:
On Oct 5, 2020, at 5:08 PM, Jean SUZINEAU via fpc-pascal
wrote:
In my own code I use BlockRead/BlockWrite, but I'm wondering if I've not seen
this somewhere in RTL.
This looks good to me what about the concerns raised by
Op 2020-10-05 om 20:45 schreef Ryan Joseph via fpc-pascal:
I often need to use a function which reads a file into a string, as is so
common in so many scripting languages. Can it be considered to add something
like this to the RTL? Since we have a refcounted Ansistring type it's natural
for
I use this function to read a file into a string:
function ReadFile(const FileName: TFileName): String;
var
InputFile: THandle;
FileSize, BytesRead: Integer;
Buffer: String='';
begin
try
InputFile := FileOpen(FileName, fmOpenRead);
if InputFile = -1 then
begin
El 6/10/20 a les 9:01, Michael Van Canneyt via fpc-pascal ha escrit:
A simple filecreate, allocate buffer, fileread, fileclose will probably
be easiest.
Lazarus has a ReadFileToString in fileutil.
Bye
--
Luca
___
fpc-pascal maillist -
On Mon, 5 Oct 2020, Ryan Joseph via fpc-pascal wrote:
On Oct 5, 2020, at 3:23 PM, Michael Van Canneyt via fpc-pascal
wrote:
So I think you're looking at 6 or even 8 versions of this hypothetical
function...
Ouch. :)
I'm sure this code already exists in the RTL though, right? I
> On Oct 5, 2020, at 5:08 PM, Jean SUZINEAU via fpc-pascal
> wrote:
>
> In my own code I use BlockRead/BlockWrite, but I'm wondering if I've not seen
> this somewhere in RTL.
>
>
This looks good to me what about the concerns raised by Michael? I don't know
enough about text formats but
Am 06.10.20 um 01:08 schrieb Jean SUZINEAU via fpc-pascal:
In my own code I use BlockRead/BlockWrite, but I'm wondering if I've
not seen this somewhere in RTL.
https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas
function
In my own code I use BlockRead/BlockWrite, but I'm wondering if
I've not seen this somewhere in RTL.
https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas
function String_from_File( _FileName: String): String;
> On Oct 5, 2020, at 3:23 PM, Michael Van Canneyt via fpc-pascal
> wrote:
>
> So I think you're looking at 6 or even 8 versions of this hypothetical
> function...
Ouch. :)
I'm sure this code already exists in the RTL though, right? I assume it's part
of some classes like TStringList and
On Mon, 5 Oct 2020, Ryan Joseph via fpc-pascal wrote:
I often need to use a function which reads a file into a string, as is so
common in so many scripting languages. Can it be considered to add something
like this to the RTL? Since we have a refcounted Ansistring type it's natural
for
I often need to use a function which reads a file into a string, as is so
common in so many scripting languages. Can it be considered to add something
like this to the RTL? Since we have a refcounted Ansistring type it's natural
for this to be a one-liner. Not saying we should use TStringList
30 matches
Mail list logo