View Issue Details

IDProjectCategoryView StatusLast Update
0028075FPCFCLpublic2015-08-30 22:35
ReportersilvioprogAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version4.0.0Fixed in Version3.0.0 
Summary0028075: [PATCH] Add textreader classes in streamex unit
DescriptionHello,

This patch add new classes for text reading in streamex unit (@Michael, many thanks again for your help on it =) ).

Thank you!
Additional Information- Need to add the constant SParamIsNil in RtlConsts unit (new constant available in Delphi).
TagsNo tags attached.
Fixed in Revision31022
FPCOldBugId
FPCTarget
Attached Files
  • 0001-add-SParamIsNil-patch-by-silvioprog.patch (977 bytes)
    From 5affe54cb6a377ee7a19f96896af155e4b24a903 Mon Sep 17 00:00:00 2001
    From: silvioprog <silvioprog@gmail.com>
    Date: Sat, 9 May 2015 12:41:55 -0300
    Subject: [PATCH 1/1] * add SParamIsNil, patch by silvioprog
    
    ---
     rtl/objpas/rtlconst.inc | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/rtl/objpas/rtlconst.inc b/rtl/objpas/rtlconst.inc
    index 44d9096..f812eef 100644
    --- a/rtl/objpas/rtlconst.inc
    +++ b/rtl/objpas/rtlconst.inc
    @@ -139,6 +139,7 @@ ResourceString
       SImageReadFail                = 'The ImageList data could not be read from stream';
       SImageWriteFail               = 'The ImageList data could not be written to stream';
       SIndexOutOfRange              = 'Grid index out of range';
    +  SParamIsNil                   = 'Parameter %s cannot be nil';
       SIniFileWriteError            = 'Unable to write to "%s"';
       SInsertLineError              = 'Line could not be inserted';
       SInvalidActionCreation        = 'Invalid action creation';
    -- 
    1.9.5.msysgit.0
    
    
  • 0001-add-TTextReader-TStreamReader-TStringReader-TFileRea.patch (9,185 bytes)
    From 4e6218f1b0fc1ae368646502d84ef60092b7e7a6 Mon Sep 17 00:00:00 2001
    From: silvioprog <silvioprog@gmail.com>
    Date: Tue, 12 May 2015 01:55:44 -0300
    Subject: [PATCH 1/1] * add TTextReader/TStreamReader/TStringReader/TFileReader
     classes, patch by silvioprog.
    
    ---
     packages/fcl-base/src/streamex.pp | 322 +++++++++++++++++++++++++++++++++++++-
     1 file changed, 321 insertions(+), 1 deletion(-)
    
    diff --git a/packages/fcl-base/src/streamex.pp b/packages/fcl-base/src/streamex.pp
    index bddf1f9..4197763 100644
    --- a/packages/fcl-base/src/streamex.pp
    +++ b/packages/fcl-base/src/streamex.pp
    @@ -1,10 +1,35 @@
    +{
    +    This file is part of the Free Component Library.
    +
    +    Copyright (c) 2015 by:
    +
    +      . Michael Van Canneyt michael@freepascal.org
    +      . Silvio Clecio github.com/silvioprog
    +
    +    Text reader classes.
    +
    +    See the file COPYING.FPC, included in this distribution,
    +    for details about the copyright.
    +
    +    This program is distributed in the hope that it will be useful,
    +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    +
    + **********************************************************************}
    +
     {$mode objfpc}
     {$h+}
     unit streamex;
     
     Interface
     
    -uses Classes;
    +uses
    +  Classes, SysUtils, RtlConsts;
    +
    +const
    +  MIN_BUFFER_SIZE = 128;
    +  BUFFER_SIZE = 4096;
    +  FILE_RIGHTS = 438;
     
     type
     
    @@ -58,6 +83,78 @@ type
           property Position: LongInt read GetPosition write SetPosition;
        end;
     
    +   { TTextReader }
    +
    +   TTextReader = class abstract(TObject)
    +   public
    +     constructor Create; virtual;
    +     procedure Reset; virtual; abstract;
    +     procedure Close; virtual; abstract;
    +     function IsEof: Boolean; virtual; abstract;
    +     procedure ReadLine(out AString: string); virtual; abstract; overload;
    +     function ReadLine: string; virtual; abstract; overload;
    +     property Eof: Boolean read IsEof;
    +   end;
    +
    +   { TStreamReader }
    +
    +   TStreamReader = class(TTextReader)
    +   private
    +     FBufferRead: Integer;
    +     FBufferPosition: Integer;
    +     FOwnsStream: Boolean;
    +     FStream: TStream;
    +     FBuffer: array of Byte;
    +     procedure FillBuffer;
    +   public
    +     constructor Create(AStream: TStream; ABufferSize: Integer;
    +       AOwnsStream: Boolean); virtual;
    +     constructor Create(AStream: TStream); virtual;
    +     destructor Destroy; override;
    +     procedure Reset; override;
    +     procedure Close; override;
    +     function IsEof: Boolean; override;
    +     procedure ReadLine(out AString: string); override; overload;
    +     function ReadLine: string; override; overload;
    +     property BaseStream: TStream read FStream;
    +     property OwnsStream: Boolean read FOwnsStream write FOwnsStream;
    +   end;
    +
    +   { TStringReader }
    +
    +   TStringReader = class(TTextReader)
    +   private
    +     FReader: TTextReader;
    +   public
    +     constructor Create(const AString: string; ABufferSize: Integer); virtual;
    +     constructor Create(const AString: string); virtual;
    +     destructor Destroy; override;
    +     procedure Reset; override;
    +     procedure Close; override;
    +     function IsEof: Boolean; override;
    +     procedure ReadLine(out AString: string); override; overload;
    +     function ReadLine: string; override; overload;
    +   end;
    +
    +   { TFileReader }
    +
    +   TFileReader = class(TTextReader)
    +   private
    +     FReader: TTextReader;
    +   public
    +     constructor Create(const AFileName: TFileName; AMode: Word;
    +       ARights: Cardinal; ABufferSize: Integer); virtual;
    +     constructor Create(const AFileName: TFileName; AMode: Word;
    +       ABufferSize: Integer); virtual;
    +     constructor Create(const AFileName: TFileName; ABufferSize: Integer); virtual;
    +     constructor Create(const AFileName: TFileName); virtual;
    +     destructor Destroy; override;
    +     procedure Reset; override;
    +     procedure Close; override;
    +     function IsEof: Boolean; override;
    +     procedure ReadLine(out AString: string); override; overload;
    +     function ReadLine: string; override; overload;
    +   end;
     
       TStreamHelper = class helper for TStream
                          function  ReadWordLE :word;
    @@ -192,7 +289,230 @@ begin
        GetDriver.WriteValue(Value);
     end;
     
    +{ TTextReader }
    +
    +constructor TTextReader.Create;
    +begin
    +  inherited Create;
    +end;
    +
    +{ TStreamReader }
    +
    +constructor TStreamReader.Create(AStream: TStream; ABufferSize: Integer;
    +  AOwnsStream: Boolean);
    +begin
    +  inherited Create;
    +  if not Assigned(AStream) then
    +    raise EArgumentException.CreateResFmt(@SParamIsNil, ['AStream']);
    +  FStream := AStream;
    +  FOwnsStream := AOwnsStream;
    +  if ABufferSize >= MIN_BUFFER_SIZE then
    +    SetLength(FBuffer, ABufferSize)
    +  else
    +    SetLength(FBuffer, MIN_BUFFER_SIZE);
    +end;
    +
    +constructor TStreamReader.Create(AStream: TStream);
    +begin
    +  Create(AStream, BUFFER_SIZE, False);
    +end;
    +
    +destructor TStreamReader.Destroy;
    +begin
    +  Close;
    +  inherited Destroy;
    +end;
    +
    +procedure TStreamReader.FillBuffer;
    +begin
    +  FBufferRead := FStream.Read(FBuffer[0], Pred(Length(FBuffer)));
    +  FBuffer[FBufferRead] := 0;
    +  FBufferPosition := 0;
    +end;
    +
    +procedure TStreamReader.Reset;
    +begin
    +  FBufferRead := 0;
    +  FBufferPosition := 0;
    +  if Assigned(FStream) then
    +    FStream.Seek(0, 0);
    +end;
    +
    +procedure TStreamReader.Close;
    +begin
    +  if FOwnsStream then
    +  begin
    +    FStream.Free;
    +    FStream := nil;
    +  end;
    +end;
    +
    +function TStreamReader.IsEof: Boolean;
    +begin
    +  if not Assigned(FStream) then
    +    Exit(True);
    +  Result := FBufferPosition >= FBufferRead;
    +  if Result then
    +  begin
    +    FillBuffer;
    +    Result := FBufferRead = 0;
    +  end;
    +end;
    +
    +procedure TStreamReader.ReadLine(out AString: string);
    +var
    +  VPByte: PByte;
    +  VPosition, VStrLength, VLength: Integer;
    +begin
    +  VPosition := FBufferPosition;
    +  SetLength(AString, 0);
    +  repeat
    +    VPByte := @FBuffer[FBufferPosition];
    +    while (FBufferPosition < FBufferRead) and not (VPByte^ in [10, 13]) do
    +    begin
    +      Inc(VPByte);
    +      Inc(FBufferPosition);
    +    end;
    +    if FBufferPosition = FBufferRead then
    +    begin
    +      VLength := FBufferPosition - VPosition;
    +      if VLength > 0 then
    +      begin
    +        VStrLength := Length(AString);
    +        SetLength(AString, VStrLength + VLength);
    +        Move(FBuffer[VPosition], AString[Succ(VStrLength)], VLength);
    +      end;
    +      FillBuffer;
    +      VPosition := FBufferPosition;
    +    end;
    +  until (FBufferPosition = FBufferRead) or (VPByte^ in [10, 13]);
    +  VLength := FBufferPosition - VPosition;
    +  if VLength > 0 then
    +  begin
    +    VStrLength := Length(AString);
    +    SetLength(AString, VStrLength + VLength);
    +    Move(FBuffer[VPosition], AString[Succ(VStrLength)], VLength);
    +  end;
    +  if (VPByte^ in [10, 13]) and (FBufferPosition < FBufferRead) then
    +  begin
    +    Inc(FBufferPosition);
    +    if VPByte^ = 13 then
    +    begin
    +      if FBufferPosition = FBufferRead then
    +        FillBuffer;
    +      if (FBufferPosition < FBufferRead) and (FBuffer[FBufferPosition] = 10) then
    +        Inc(FBufferPosition);
    +    end;
    +  end;
    +end;
    +
    +function TStreamReader.ReadLine: string;
    +begin
    +  ReadLine(Result);
    +end;
    +
    +{ TStringReader }
    +
    +constructor TStringReader.Create(const AString: string; ABufferSize: Integer);
    +begin
    +  inherited Create;
    +  FReader := TStreamReader.Create(TStringStream.Create(AString), ABufferSize, True);
    +end;
    +
    +constructor TStringReader.Create(const AString: string);
    +begin
    +  Create(AString, BUFFER_SIZE);
    +end;
    +
    +destructor TStringReader.Destroy;
    +begin
    +  FReader.Free;
    +  inherited Destroy;
    +end;
    +
    +procedure TStringReader.Reset;
    +begin
    +  FReader.Reset;
    +end;
    +
    +procedure TStringReader.Close;
    +begin
    +  FReader.Close;
    +end;
    +
    +function TStringReader.IsEof: Boolean;
    +begin
    +  Result := FReader.IsEof;
    +end;
    +
    +procedure TStringReader.ReadLine(out AString: string);
    +begin
    +  FReader.ReadLine(AString);
    +end;
    +
    +function TStringReader.ReadLine: string;
    +begin
    +  ReadLine(Result);
    +end;
    +
    +{ TFileReader }
    +
    +constructor TFileReader.Create(const AFileName: TFileName; AMode: Word;
    +  ARights: Cardinal; ABufferSize: Integer);
    +begin
    +  inherited Create;
    +  FReader := TStreamReader.Create(TFileStream.Create(AFileName, AMode, ARights),
    +    ABufferSize, True);
    +end;
    +
    +constructor TFileReader.Create(const AFileName: TFileName; AMode: Word;
    +  ABufferSize: Integer);
    +begin
    +  Create(AFileName, AMode, FILE_RIGHTS, ABufferSize);
    +end;
    +
    +constructor TFileReader.Create(const AFileName: TFileName; ABufferSize: Integer);
    +begin
    +  Create(AFileName, fmOpenRead or fmShareDenyWrite, ABufferSize);
    +end;
    +
    +constructor TFileReader.Create(const AFileName: TFileName);
    +begin
    +  Create(AFileName, BUFFER_SIZE);
    +end;
    +
    +destructor TFileReader.Destroy;
    +begin
    +  FReader.Free;
    +  inherited Destroy;
    +end;
    +
    +procedure TFileReader.Reset;
    +begin
    +  FReader.Reset;
    +end;
    +
    +procedure TFileReader.Close;
    +begin
    +  FReader.Close;
    +end;
    +
    +function TFileReader.IsEof: Boolean;
    +begin
    +  Result := FReader.IsEof;
    +end;
    +
    +procedure TFileReader.ReadLine(out AString: string);
    +begin
    +  FReader.ReadLine(AString);
    +end;
    +
    +function TFileReader.ReadLine: string;
    +begin
    +  ReadLine(Result);
    +end;
     
    +{ TStreamHelper }
     
     function TStreamHelper.readwordLE:word;
     begin
    -- 
    1.9.5.msysgit.0
    
    
  • 0001-Fix-Converting-the-operands-to-Int64-.-hints-patch-b.patch (1,151 bytes)
    From 4973146d650360e70a5f7eb773fbc281cb91077f Mon Sep 17 00:00:00 2001
    From: silvioprog <silvioprog@gmail.com>
    Date: Tue, 12 May 2015 02:00:00 -0300
    Subject: [PATCH 1/1] Fix "Converting the operands to Int64 ..." hints, patch
     by silvioprog.
    
    ---
     packages/fcl-base/src/streamex.pp | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/packages/fcl-base/src/streamex.pp b/packages/fcl-base/src/streamex.pp
    index 4197763..4a48bea 100644
    --- a/packages/fcl-base/src/streamex.pp
    +++ b/packages/fcl-base/src/streamex.pp
    @@ -187,7 +187,7 @@ Implementation
     
     function TBidirBinaryObjectReader.GetPosition: Longint;
     begin
    -   Result := FStream.Position - (FBufEnd - FBufPos);
    +   Result := FStream.Position - (Int64(FBufEnd) - Int64(FBufPos));
     end;
     
     procedure TBidirBinaryObjectReader.SetPosition(const AValue: Longint);
    @@ -201,7 +201,7 @@ end;
     
     function TBidirBinaryObjectWriter.GetPosition: Longint;
     begin
    -   Result := FStream.Position - (FBufEnd - FBufPos);
    +   Result := FStream.Position - (Int64(FBufEnd) - Int64(FBufPos));
     end;
     
     procedure TBidirBinaryObjectWriter.SetPosition(const AValue: Longint);
    -- 
    1.9.5.msysgit.0
    
    
  • ALTERNATIVE-0001-add-TextReader-unit-patch-by-silvioprog.patch (8,784 bytes)
    From 33cc429b5c116603bd3f14e9f896f2f08d435628 Mon Sep 17 00:00:00 2001
    From: silvioprog <silvioprog@gmail.com>
    Date: Sat, 9 May 2015 12:46:48 -0300
    Subject: [PATCH 1/1] * add TextReader unit, patch by silvioprog
    
    ---
     packages/fcl-base/src/textreader.pp | 335 ++++++++++++++++++++++++++++++++++++
     1 file changed, 335 insertions(+)
     create mode 100644 packages/fcl-base/src/textreader.pp
    
    diff --git a/packages/fcl-base/src/textreader.pp b/packages/fcl-base/src/textreader.pp
    new file mode 100644
    index 0000000..123d0c8
    --- /dev/null
    +++ b/packages/fcl-base/src/textreader.pp
    @@ -0,0 +1,335 @@
    +{
    +    This file is part of the Free Component Library.
    +
    +    Copyright (c) 2015 by:
    +
    +      . Michael Van Canneyt michael@freepascal.org
    +      . Silvio Clecio github.com/silvioprog
    +
    +    Text reader classes.
    +
    +    See the file COPYING.FPC, included in this distribution,
    +    for details about the copyright.
    +
    +    This program is distributed in the hope that it will be useful,
    +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    +
    + **********************************************************************}
    +
    +unit TextReader;
    +
    +{$mode objfpc}{$H+}
    +
    +interface
    +
    +uses
    +  Classes, SysUtils, RtlConsts;
    +
    +const
    +  MIN_BUFFER_SIZE = 128;
    +  BUFFER_SIZE = 4096;
    +  FILE_RIGHTS = 438;
    +
    +type
    +
    +  { TTextReader }
    +
    +  TTextReader = class abstract(TObject)
    +  public
    +    constructor Create; virtual;
    +    procedure Reset; virtual; abstract;
    +    procedure Close; virtual; abstract;
    +    function IsEof: Boolean; virtual; abstract;
    +    procedure ReadLine(out AString: string); virtual; abstract; overload;
    +    function ReadLine: string; virtual; abstract; overload;
    +    property Eof: Boolean read IsEof;
    +  end;
    +
    +  { TStreamReader }
    +
    +  TStreamReader = class(TTextReader)
    +  private
    +    FBufferRead: Integer;
    +    FBufferPosition: Integer;
    +    FOwnsStream: Boolean;
    +    FStream: TStream;
    +    FBuffer: array of Byte;
    +    procedure FillBuffer;
    +  public
    +    constructor Create(AStream: TStream; ABufferSize: Integer;
    +      AOwnsStream: Boolean); virtual;
    +    constructor Create(AStream: TStream); virtual;
    +    destructor Destroy; override;
    +    procedure Reset; override;
    +    procedure Close; override;
    +    function IsEof: Boolean; override;
    +    procedure ReadLine(out AString: string); override; overload;
    +    function ReadLine: string; override; overload;
    +    property BaseStream: TStream read FStream;
    +    property OwnsStream: Boolean read FOwnsStream write FOwnsStream;
    +  end;
    +
    +  { TStringReader }
    +
    +  TStringReader = class(TTextReader)
    +  private
    +    FReader: TTextReader;
    +  public
    +    constructor Create(const AString: string; ABufferSize: Integer); virtual;
    +    constructor Create(const AString: string); virtual;
    +    destructor Destroy; override;
    +    procedure Reset; override;
    +    procedure Close; override;
    +    function IsEof: Boolean; override;
    +    procedure ReadLine(out AString: string); override; overload;
    +    function ReadLine: string; override; overload;
    +  end;
    +
    +  { TFileReader }
    +
    +  TFileReader = class(TTextReader)
    +  private
    +    FReader: TTextReader;
    +  public
    +    constructor Create(const AFileName: TFileName; AMode: Word;
    +      ARights: Cardinal; ABufferSize: Integer); virtual;
    +    constructor Create(const AFileName: TFileName; AMode: Word;
    +      ABufferSize: Integer); virtual;
    +    constructor Create(const AFileName: TFileName; ABufferSize: Integer); virtual;
    +    constructor Create(const AFileName: TFileName); virtual;
    +    destructor Destroy; override;
    +    procedure Reset; override;
    +    procedure Close; override;
    +    function IsEof: Boolean; override;
    +    procedure ReadLine(out AString: string); override; overload;
    +    function ReadLine: string; override; overload;
    +  end;
    +
    +implementation
    +
    +{ TTextReader }
    +
    +constructor TTextReader.Create;
    +begin
    +  inherited Create;
    +end;
    +
    +{ TStreamReader }
    +
    +constructor TStreamReader.Create(AStream: TStream; ABufferSize: Integer;
    +  AOwnsStream: Boolean);
    +begin
    +  inherited Create;
    +  if not Assigned(AStream) then
    +    raise EArgumentException.CreateResFmt(@SParamIsNil, ['AStream']);
    +  FStream := AStream;
    +  FOwnsStream := AOwnsStream;
    +  if ABufferSize >= MIN_BUFFER_SIZE then
    +    SetLength(FBuffer, ABufferSize)
    +  else
    +    SetLength(FBuffer, MIN_BUFFER_SIZE);
    +end;
    +
    +constructor TStreamReader.Create(AStream: TStream);
    +begin
    +  Create(AStream, BUFFER_SIZE, False);
    +end;
    +
    +destructor TStreamReader.Destroy;
    +begin
    +  Close;
    +  inherited Destroy;
    +end;
    +
    +procedure TStreamReader.FillBuffer;
    +begin
    +  FBufferRead := FStream.Read(FBuffer[0], Pred(Length(FBuffer)));
    +  FBuffer[FBufferRead] := 0;
    +  FBufferPosition := 0;
    +end;
    +
    +procedure TStreamReader.Reset;
    +begin
    +  FBufferRead := 0;
    +  FBufferPosition := 0;
    +  if Assigned(FStream) then
    +    FStream.Seek(0, 0);
    +end;
    +
    +procedure TStreamReader.Close;
    +begin
    +  if FOwnsStream then
    +  begin
    +    FStream.Free;
    +    FStream := nil;
    +  end;
    +end;
    +
    +function TStreamReader.IsEof: Boolean;
    +begin
    +  if not Assigned(FStream) then
    +    Exit(True);
    +  Result := FBufferPosition >= FBufferRead;
    +  if Result then
    +  begin
    +    FillBuffer;
    +    Result := FBufferRead = 0;
    +  end;
    +end;
    +
    +procedure TStreamReader.ReadLine(out AString: string);
    +var
    +  VPByte: PByte;
    +  VPosition, VStrLength, VLength: Integer;
    +begin
    +  VPosition := FBufferPosition;
    +  SetLength(AString, 0);
    +  repeat
    +    VPByte := @FBuffer[FBufferPosition];
    +    while (FBufferPosition < FBufferRead) and not (VPByte^ in [10, 13]) do
    +    begin
    +      Inc(VPByte);
    +      Inc(FBufferPosition);
    +    end;
    +    if FBufferPosition = FBufferRead then
    +    begin
    +      VLength := FBufferPosition - VPosition;
    +      if VLength > 0 then
    +      begin
    +        VStrLength := Length(AString);
    +        SetLength(AString, VStrLength + VLength);
    +        Move(FBuffer[VPosition], AString[Succ(VStrLength)], VLength);
    +      end;
    +      FillBuffer;
    +      VPosition := FBufferPosition;
    +    end;
    +  until (FBufferPosition = FBufferRead) or (VPByte^ in [10, 13]);
    +  VLength := FBufferPosition - VPosition;
    +  if VLength > 0 then
    +  begin
    +    VStrLength := Length(AString);
    +    SetLength(AString, VStrLength + VLength);
    +    Move(FBuffer[VPosition], AString[Succ(VStrLength)], VLength);
    +  end;
    +  if (VPByte^ in [10, 13]) and (FBufferPosition < FBufferRead) then
    +  begin
    +    Inc(FBufferPosition);
    +    if VPByte^ = 13 then
    +    begin
    +      if FBufferPosition = FBufferRead then
    +        FillBuffer;
    +      if (FBufferPosition < FBufferRead) and (FBuffer[FBufferPosition] = 10) then
    +        Inc(FBufferPosition);
    +    end;
    +  end;
    +end;
    +
    +function TStreamReader.ReadLine: string;
    +begin
    +  ReadLine(Result);
    +end;
    +
    +{ TStringReader }
    +
    +constructor TStringReader.Create(const AString: string; ABufferSize: Integer);
    +begin
    +  inherited Create;
    +  FReader := TStreamReader.Create(TStringStream.Create(AString), ABufferSize, True);
    +end;
    +
    +constructor TStringReader.Create(const AString: string);
    +begin
    +  Create(AString, BUFFER_SIZE);
    +end;
    +
    +destructor TStringReader.Destroy;
    +begin
    +  FReader.Free;
    +  inherited Destroy;
    +end;
    +
    +procedure TStringReader.Reset;
    +begin
    +  FReader.Reset;
    +end;
    +
    +procedure TStringReader.Close;
    +begin
    +  FReader.Close;
    +end;
    +
    +function TStringReader.IsEof: Boolean;
    +begin
    +  Result := FReader.IsEof;
    +end;
    +
    +procedure TStringReader.ReadLine(out AString: string);
    +begin
    +  FReader.ReadLine(AString);
    +end;
    +
    +function TStringReader.ReadLine: string;
    +begin
    +  ReadLine(Result);
    +end;
    +
    +{ TFileReader }
    +
    +constructor TFileReader.Create(const AFileName: TFileName; AMode: Word;
    +  ARights: Cardinal; ABufferSize: Integer);
    +begin
    +  inherited Create;
    +  FReader := TStreamReader.Create(TFileStream.Create(AFileName, AMode, ARights),
    +    ABufferSize, True);
    +end;
    +
    +constructor TFileReader.Create(const AFileName: TFileName; AMode: Word;
    +  ABufferSize: Integer);
    +begin
    +  Create(AFileName, AMode, FILE_RIGHTS, ABufferSize);
    +end;
    +
    +constructor TFileReader.Create(const AFileName: TFileName; ABufferSize: Integer);
    +begin
    +  Create(AFileName, fmOpenRead or fmShareDenyWrite, ABufferSize);
    +end;
    +
    +constructor TFileReader.Create(const AFileName: TFileName);
    +begin
    +  Create(AFileName, BUFFER_SIZE);
    +end;
    +
    +destructor TFileReader.Destroy;
    +begin
    +  FReader.Free;
    +  inherited Destroy;
    +end;
    +
    +procedure TFileReader.Reset;
    +begin
    +  FReader.Reset;
    +end;
    +
    +procedure TFileReader.Close;
    +begin
    +  FReader.Close;
    +end;
    +
    +function TFileReader.IsEof: Boolean;
    +begin
    +  Result := FReader.IsEof;
    +end;
    +
    +procedure TFileReader.ReadLine(out AString: string);
    +begin
    +  FReader.ReadLine(AString);
    +end;
    +
    +function TFileReader.ReadLine: string;
    +begin
    +  ReadLine(Result);
    +end;
    +
    +end.
    +
    -- 
    1.9.5.msysgit.0
    
    

Activities

silvioprog

2015-05-12 07:24

reporter  

0001-add-SParamIsNil-patch-by-silvioprog.patch (977 bytes)
From 5affe54cb6a377ee7a19f96896af155e4b24a903 Mon Sep 17 00:00:00 2001
From: silvioprog <silvioprog@gmail.com>
Date: Sat, 9 May 2015 12:41:55 -0300
Subject: [PATCH 1/1] * add SParamIsNil, patch by silvioprog

---
 rtl/objpas/rtlconst.inc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rtl/objpas/rtlconst.inc b/rtl/objpas/rtlconst.inc
index 44d9096..f812eef 100644
--- a/rtl/objpas/rtlconst.inc
+++ b/rtl/objpas/rtlconst.inc
@@ -139,6 +139,7 @@ ResourceString
   SImageReadFail                = 'The ImageList data could not be read from stream';
   SImageWriteFail               = 'The ImageList data could not be written to stream';
   SIndexOutOfRange              = 'Grid index out of range';
+  SParamIsNil                   = 'Parameter %s cannot be nil';
   SIniFileWriteError            = 'Unable to write to "%s"';
   SInsertLineError              = 'Line could not be inserted';
   SInvalidActionCreation        = 'Invalid action creation';
-- 
1.9.5.msysgit.0

silvioprog

2015-05-12 07:24

reporter  

0001-add-TTextReader-TStreamReader-TStringReader-TFileRea.patch (9,185 bytes)
From 4e6218f1b0fc1ae368646502d84ef60092b7e7a6 Mon Sep 17 00:00:00 2001
From: silvioprog <silvioprog@gmail.com>
Date: Tue, 12 May 2015 01:55:44 -0300
Subject: [PATCH 1/1] * add TTextReader/TStreamReader/TStringReader/TFileReader
 classes, patch by silvioprog.

---
 packages/fcl-base/src/streamex.pp | 322 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 321 insertions(+), 1 deletion(-)

diff --git a/packages/fcl-base/src/streamex.pp b/packages/fcl-base/src/streamex.pp
index bddf1f9..4197763 100644
--- a/packages/fcl-base/src/streamex.pp
+++ b/packages/fcl-base/src/streamex.pp
@@ -1,10 +1,35 @@
+{
+    This file is part of the Free Component Library.
+
+    Copyright (c) 2015 by:
+
+      . Michael Van Canneyt michael@freepascal.org
+      . Silvio Clecio github.com/silvioprog
+
+    Text reader classes.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
 {$mode objfpc}
 {$h+}
 unit streamex;
 
 Interface
 
-uses Classes;
+uses
+  Classes, SysUtils, RtlConsts;
+
+const
+  MIN_BUFFER_SIZE = 128;
+  BUFFER_SIZE = 4096;
+  FILE_RIGHTS = 438;
 
 type
 
@@ -58,6 +83,78 @@ type
       property Position: LongInt read GetPosition write SetPosition;
    end;
 
+   { TTextReader }
+
+   TTextReader = class abstract(TObject)
+   public
+     constructor Create; virtual;
+     procedure Reset; virtual; abstract;
+     procedure Close; virtual; abstract;
+     function IsEof: Boolean; virtual; abstract;
+     procedure ReadLine(out AString: string); virtual; abstract; overload;
+     function ReadLine: string; virtual; abstract; overload;
+     property Eof: Boolean read IsEof;
+   end;
+
+   { TStreamReader }
+
+   TStreamReader = class(TTextReader)
+   private
+     FBufferRead: Integer;
+     FBufferPosition: Integer;
+     FOwnsStream: Boolean;
+     FStream: TStream;
+     FBuffer: array of Byte;
+     procedure FillBuffer;
+   public
+     constructor Create(AStream: TStream; ABufferSize: Integer;
+       AOwnsStream: Boolean); virtual;
+     constructor Create(AStream: TStream); virtual;
+     destructor Destroy; override;
+     procedure Reset; override;
+     procedure Close; override;
+     function IsEof: Boolean; override;
+     procedure ReadLine(out AString: string); override; overload;
+     function ReadLine: string; override; overload;
+     property BaseStream: TStream read FStream;
+     property OwnsStream: Boolean read FOwnsStream write FOwnsStream;
+   end;
+
+   { TStringReader }
+
+   TStringReader = class(TTextReader)
+   private
+     FReader: TTextReader;
+   public
+     constructor Create(const AString: string; ABufferSize: Integer); virtual;
+     constructor Create(const AString: string); virtual;
+     destructor Destroy; override;
+     procedure Reset; override;
+     procedure Close; override;
+     function IsEof: Boolean; override;
+     procedure ReadLine(out AString: string); override; overload;
+     function ReadLine: string; override; overload;
+   end;
+
+   { TFileReader }
+
+   TFileReader = class(TTextReader)
+   private
+     FReader: TTextReader;
+   public
+     constructor Create(const AFileName: TFileName; AMode: Word;
+       ARights: Cardinal; ABufferSize: Integer); virtual;
+     constructor Create(const AFileName: TFileName; AMode: Word;
+       ABufferSize: Integer); virtual;
+     constructor Create(const AFileName: TFileName; ABufferSize: Integer); virtual;
+     constructor Create(const AFileName: TFileName); virtual;
+     destructor Destroy; override;
+     procedure Reset; override;
+     procedure Close; override;
+     function IsEof: Boolean; override;
+     procedure ReadLine(out AString: string); override; overload;
+     function ReadLine: string; override; overload;
+   end;
 
   TStreamHelper = class helper for TStream
                      function  ReadWordLE :word;
@@ -192,7 +289,230 @@ begin
    GetDriver.WriteValue(Value);
 end;
 
+{ TTextReader }
+
+constructor TTextReader.Create;
+begin
+  inherited Create;
+end;
+
+{ TStreamReader }
+
+constructor TStreamReader.Create(AStream: TStream; ABufferSize: Integer;
+  AOwnsStream: Boolean);
+begin
+  inherited Create;
+  if not Assigned(AStream) then
+    raise EArgumentException.CreateResFmt(@SParamIsNil, ['AStream']);
+  FStream := AStream;
+  FOwnsStream := AOwnsStream;
+  if ABufferSize >= MIN_BUFFER_SIZE then
+    SetLength(FBuffer, ABufferSize)
+  else
+    SetLength(FBuffer, MIN_BUFFER_SIZE);
+end;
+
+constructor TStreamReader.Create(AStream: TStream);
+begin
+  Create(AStream, BUFFER_SIZE, False);
+end;
+
+destructor TStreamReader.Destroy;
+begin
+  Close;
+  inherited Destroy;
+end;
+
+procedure TStreamReader.FillBuffer;
+begin
+  FBufferRead := FStream.Read(FBuffer[0], Pred(Length(FBuffer)));
+  FBuffer[FBufferRead] := 0;
+  FBufferPosition := 0;
+end;
+
+procedure TStreamReader.Reset;
+begin
+  FBufferRead := 0;
+  FBufferPosition := 0;
+  if Assigned(FStream) then
+    FStream.Seek(0, 0);
+end;
+
+procedure TStreamReader.Close;
+begin
+  if FOwnsStream then
+  begin
+    FStream.Free;
+    FStream := nil;
+  end;
+end;
+
+function TStreamReader.IsEof: Boolean;
+begin
+  if not Assigned(FStream) then
+    Exit(True);
+  Result := FBufferPosition >= FBufferRead;
+  if Result then
+  begin
+    FillBuffer;
+    Result := FBufferRead = 0;
+  end;
+end;
+
+procedure TStreamReader.ReadLine(out AString: string);
+var
+  VPByte: PByte;
+  VPosition, VStrLength, VLength: Integer;
+begin
+  VPosition := FBufferPosition;
+  SetLength(AString, 0);
+  repeat
+    VPByte := @FBuffer[FBufferPosition];
+    while (FBufferPosition < FBufferRead) and not (VPByte^ in [10, 13]) do
+    begin
+      Inc(VPByte);
+      Inc(FBufferPosition);
+    end;
+    if FBufferPosition = FBufferRead then
+    begin
+      VLength := FBufferPosition - VPosition;
+      if VLength > 0 then
+      begin
+        VStrLength := Length(AString);
+        SetLength(AString, VStrLength + VLength);
+        Move(FBuffer[VPosition], AString[Succ(VStrLength)], VLength);
+      end;
+      FillBuffer;
+      VPosition := FBufferPosition;
+    end;
+  until (FBufferPosition = FBufferRead) or (VPByte^ in [10, 13]);
+  VLength := FBufferPosition - VPosition;
+  if VLength > 0 then
+  begin
+    VStrLength := Length(AString);
+    SetLength(AString, VStrLength + VLength);
+    Move(FBuffer[VPosition], AString[Succ(VStrLength)], VLength);
+  end;
+  if (VPByte^ in [10, 13]) and (FBufferPosition < FBufferRead) then
+  begin
+    Inc(FBufferPosition);
+    if VPByte^ = 13 then
+    begin
+      if FBufferPosition = FBufferRead then
+        FillBuffer;
+      if (FBufferPosition < FBufferRead) and (FBuffer[FBufferPosition] = 10) then
+        Inc(FBufferPosition);
+    end;
+  end;
+end;
+
+function TStreamReader.ReadLine: string;
+begin
+  ReadLine(Result);
+end;
+
+{ TStringReader }
+
+constructor TStringReader.Create(const AString: string; ABufferSize: Integer);
+begin
+  inherited Create;
+  FReader := TStreamReader.Create(TStringStream.Create(AString), ABufferSize, True);
+end;
+
+constructor TStringReader.Create(const AString: string);
+begin
+  Create(AString, BUFFER_SIZE);
+end;
+
+destructor TStringReader.Destroy;
+begin
+  FReader.Free;
+  inherited Destroy;
+end;
+
+procedure TStringReader.Reset;
+begin
+  FReader.Reset;
+end;
+
+procedure TStringReader.Close;
+begin
+  FReader.Close;
+end;
+
+function TStringReader.IsEof: Boolean;
+begin
+  Result := FReader.IsEof;
+end;
+
+procedure TStringReader.ReadLine(out AString: string);
+begin
+  FReader.ReadLine(AString);
+end;
+
+function TStringReader.ReadLine: string;
+begin
+  ReadLine(Result);
+end;
+
+{ TFileReader }
+
+constructor TFileReader.Create(const AFileName: TFileName; AMode: Word;
+  ARights: Cardinal; ABufferSize: Integer);
+begin
+  inherited Create;
+  FReader := TStreamReader.Create(TFileStream.Create(AFileName, AMode, ARights),
+    ABufferSize, True);
+end;
+
+constructor TFileReader.Create(const AFileName: TFileName; AMode: Word;
+  ABufferSize: Integer);
+begin
+  Create(AFileName, AMode, FILE_RIGHTS, ABufferSize);
+end;
+
+constructor TFileReader.Create(const AFileName: TFileName; ABufferSize: Integer);
+begin
+  Create(AFileName, fmOpenRead or fmShareDenyWrite, ABufferSize);
+end;
+
+constructor TFileReader.Create(const AFileName: TFileName);
+begin
+  Create(AFileName, BUFFER_SIZE);
+end;
+
+destructor TFileReader.Destroy;
+begin
+  FReader.Free;
+  inherited Destroy;
+end;
+
+procedure TFileReader.Reset;
+begin
+  FReader.Reset;
+end;
+
+procedure TFileReader.Close;
+begin
+  FReader.Close;
+end;
+
+function TFileReader.IsEof: Boolean;
+begin
+  Result := FReader.IsEof;
+end;
+
+procedure TFileReader.ReadLine(out AString: string);
+begin
+  FReader.ReadLine(AString);
+end;
+
+function TFileReader.ReadLine: string;
+begin
+  ReadLine(Result);
+end;
 
+{ TStreamHelper }
 
 function TStreamHelper.readwordLE:word;
 begin
-- 
1.9.5.msysgit.0

silvioprog

2015-05-12 07:25

reporter   ~0083571

Additional fix in path "0001-Fix-Converting-the-operands-to-Int64-.-hints-patch-b.patch".

silvioprog

2015-05-12 07:25

reporter  

0001-Fix-Converting-the-operands-to-Int64-.-hints-patch-b.patch (1,151 bytes)
From 4973146d650360e70a5f7eb773fbc281cb91077f Mon Sep 17 00:00:00 2001
From: silvioprog <silvioprog@gmail.com>
Date: Tue, 12 May 2015 02:00:00 -0300
Subject: [PATCH 1/1] Fix "Converting the operands to Int64 ..." hints, patch
 by silvioprog.

---
 packages/fcl-base/src/streamex.pp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/packages/fcl-base/src/streamex.pp b/packages/fcl-base/src/streamex.pp
index 4197763..4a48bea 100644
--- a/packages/fcl-base/src/streamex.pp
+++ b/packages/fcl-base/src/streamex.pp
@@ -187,7 +187,7 @@ Implementation
 
 function TBidirBinaryObjectReader.GetPosition: Longint;
 begin
-   Result := FStream.Position - (FBufEnd - FBufPos);
+   Result := FStream.Position - (Int64(FBufEnd) - Int64(FBufPos));
 end;
 
 procedure TBidirBinaryObjectReader.SetPosition(const AValue: Longint);
@@ -201,7 +201,7 @@ end;
 
 function TBidirBinaryObjectWriter.GetPosition: Longint;
 begin
-   Result := FStream.Position - (FBufEnd - FBufPos);
+   Result := FStream.Position - (Int64(FBufEnd) - Int64(FBufPos));
 end;
 
 procedure TBidirBinaryObjectWriter.SetPosition(const AValue: Longint);
-- 
1.9.5.msysgit.0

silvioprog

2015-05-12 07:28

reporter   ~0083572

Alternative path: "ALTERNATIVE-0001-add-TextReader-unit-patch-by-silvioprog.patch". If you prefer not change streamex. =)

silvioprog

2015-05-12 07:28

reporter  

ALTERNATIVE-0001-add-TextReader-unit-patch-by-silvioprog.patch (8,784 bytes)
From 33cc429b5c116603bd3f14e9f896f2f08d435628 Mon Sep 17 00:00:00 2001
From: silvioprog <silvioprog@gmail.com>
Date: Sat, 9 May 2015 12:46:48 -0300
Subject: [PATCH 1/1] * add TextReader unit, patch by silvioprog

---
 packages/fcl-base/src/textreader.pp | 335 ++++++++++++++++++++++++++++++++++++
 1 file changed, 335 insertions(+)
 create mode 100644 packages/fcl-base/src/textreader.pp

diff --git a/packages/fcl-base/src/textreader.pp b/packages/fcl-base/src/textreader.pp
new file mode 100644
index 0000000..123d0c8
--- /dev/null
+++ b/packages/fcl-base/src/textreader.pp
@@ -0,0 +1,335 @@
+{
+    This file is part of the Free Component Library.
+
+    Copyright (c) 2015 by:
+
+      . Michael Van Canneyt michael@freepascal.org
+      . Silvio Clecio github.com/silvioprog
+
+    Text reader classes.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+unit TextReader;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, RtlConsts;
+
+const
+  MIN_BUFFER_SIZE = 128;
+  BUFFER_SIZE = 4096;
+  FILE_RIGHTS = 438;
+
+type
+
+  { TTextReader }
+
+  TTextReader = class abstract(TObject)
+  public
+    constructor Create; virtual;
+    procedure Reset; virtual; abstract;
+    procedure Close; virtual; abstract;
+    function IsEof: Boolean; virtual; abstract;
+    procedure ReadLine(out AString: string); virtual; abstract; overload;
+    function ReadLine: string; virtual; abstract; overload;
+    property Eof: Boolean read IsEof;
+  end;
+
+  { TStreamReader }
+
+  TStreamReader = class(TTextReader)
+  private
+    FBufferRead: Integer;
+    FBufferPosition: Integer;
+    FOwnsStream: Boolean;
+    FStream: TStream;
+    FBuffer: array of Byte;
+    procedure FillBuffer;
+  public
+    constructor Create(AStream: TStream; ABufferSize: Integer;
+      AOwnsStream: Boolean); virtual;
+    constructor Create(AStream: TStream); virtual;
+    destructor Destroy; override;
+    procedure Reset; override;
+    procedure Close; override;
+    function IsEof: Boolean; override;
+    procedure ReadLine(out AString: string); override; overload;
+    function ReadLine: string; override; overload;
+    property BaseStream: TStream read FStream;
+    property OwnsStream: Boolean read FOwnsStream write FOwnsStream;
+  end;
+
+  { TStringReader }
+
+  TStringReader = class(TTextReader)
+  private
+    FReader: TTextReader;
+  public
+    constructor Create(const AString: string; ABufferSize: Integer); virtual;
+    constructor Create(const AString: string); virtual;
+    destructor Destroy; override;
+    procedure Reset; override;
+    procedure Close; override;
+    function IsEof: Boolean; override;
+    procedure ReadLine(out AString: string); override; overload;
+    function ReadLine: string; override; overload;
+  end;
+
+  { TFileReader }
+
+  TFileReader = class(TTextReader)
+  private
+    FReader: TTextReader;
+  public
+    constructor Create(const AFileName: TFileName; AMode: Word;
+      ARights: Cardinal; ABufferSize: Integer); virtual;
+    constructor Create(const AFileName: TFileName; AMode: Word;
+      ABufferSize: Integer); virtual;
+    constructor Create(const AFileName: TFileName; ABufferSize: Integer); virtual;
+    constructor Create(const AFileName: TFileName); virtual;
+    destructor Destroy; override;
+    procedure Reset; override;
+    procedure Close; override;
+    function IsEof: Boolean; override;
+    procedure ReadLine(out AString: string); override; overload;
+    function ReadLine: string; override; overload;
+  end;
+
+implementation
+
+{ TTextReader }
+
+constructor TTextReader.Create;
+begin
+  inherited Create;
+end;
+
+{ TStreamReader }
+
+constructor TStreamReader.Create(AStream: TStream; ABufferSize: Integer;
+  AOwnsStream: Boolean);
+begin
+  inherited Create;
+  if not Assigned(AStream) then
+    raise EArgumentException.CreateResFmt(@SParamIsNil, ['AStream']);
+  FStream := AStream;
+  FOwnsStream := AOwnsStream;
+  if ABufferSize >= MIN_BUFFER_SIZE then
+    SetLength(FBuffer, ABufferSize)
+  else
+    SetLength(FBuffer, MIN_BUFFER_SIZE);
+end;
+
+constructor TStreamReader.Create(AStream: TStream);
+begin
+  Create(AStream, BUFFER_SIZE, False);
+end;
+
+destructor TStreamReader.Destroy;
+begin
+  Close;
+  inherited Destroy;
+end;
+
+procedure TStreamReader.FillBuffer;
+begin
+  FBufferRead := FStream.Read(FBuffer[0], Pred(Length(FBuffer)));
+  FBuffer[FBufferRead] := 0;
+  FBufferPosition := 0;
+end;
+
+procedure TStreamReader.Reset;
+begin
+  FBufferRead := 0;
+  FBufferPosition := 0;
+  if Assigned(FStream) then
+    FStream.Seek(0, 0);
+end;
+
+procedure TStreamReader.Close;
+begin
+  if FOwnsStream then
+  begin
+    FStream.Free;
+    FStream := nil;
+  end;
+end;
+
+function TStreamReader.IsEof: Boolean;
+begin
+  if not Assigned(FStream) then
+    Exit(True);
+  Result := FBufferPosition >= FBufferRead;
+  if Result then
+  begin
+    FillBuffer;
+    Result := FBufferRead = 0;
+  end;
+end;
+
+procedure TStreamReader.ReadLine(out AString: string);
+var
+  VPByte: PByte;
+  VPosition, VStrLength, VLength: Integer;
+begin
+  VPosition := FBufferPosition;
+  SetLength(AString, 0);
+  repeat
+    VPByte := @FBuffer[FBufferPosition];
+    while (FBufferPosition < FBufferRead) and not (VPByte^ in [10, 13]) do
+    begin
+      Inc(VPByte);
+      Inc(FBufferPosition);
+    end;
+    if FBufferPosition = FBufferRead then
+    begin
+      VLength := FBufferPosition - VPosition;
+      if VLength > 0 then
+      begin
+        VStrLength := Length(AString);
+        SetLength(AString, VStrLength + VLength);
+        Move(FBuffer[VPosition], AString[Succ(VStrLength)], VLength);
+      end;
+      FillBuffer;
+      VPosition := FBufferPosition;
+    end;
+  until (FBufferPosition = FBufferRead) or (VPByte^ in [10, 13]);
+  VLength := FBufferPosition - VPosition;
+  if VLength > 0 then
+  begin
+    VStrLength := Length(AString);
+    SetLength(AString, VStrLength + VLength);
+    Move(FBuffer[VPosition], AString[Succ(VStrLength)], VLength);
+  end;
+  if (VPByte^ in [10, 13]) and (FBufferPosition < FBufferRead) then
+  begin
+    Inc(FBufferPosition);
+    if VPByte^ = 13 then
+    begin
+      if FBufferPosition = FBufferRead then
+        FillBuffer;
+      if (FBufferPosition < FBufferRead) and (FBuffer[FBufferPosition] = 10) then
+        Inc(FBufferPosition);
+    end;
+  end;
+end;
+
+function TStreamReader.ReadLine: string;
+begin
+  ReadLine(Result);
+end;
+
+{ TStringReader }
+
+constructor TStringReader.Create(const AString: string; ABufferSize: Integer);
+begin
+  inherited Create;
+  FReader := TStreamReader.Create(TStringStream.Create(AString), ABufferSize, True);
+end;
+
+constructor TStringReader.Create(const AString: string);
+begin
+  Create(AString, BUFFER_SIZE);
+end;
+
+destructor TStringReader.Destroy;
+begin
+  FReader.Free;
+  inherited Destroy;
+end;
+
+procedure TStringReader.Reset;
+begin
+  FReader.Reset;
+end;
+
+procedure TStringReader.Close;
+begin
+  FReader.Close;
+end;
+
+function TStringReader.IsEof: Boolean;
+begin
+  Result := FReader.IsEof;
+end;
+
+procedure TStringReader.ReadLine(out AString: string);
+begin
+  FReader.ReadLine(AString);
+end;
+
+function TStringReader.ReadLine: string;
+begin
+  ReadLine(Result);
+end;
+
+{ TFileReader }
+
+constructor TFileReader.Create(const AFileName: TFileName; AMode: Word;
+  ARights: Cardinal; ABufferSize: Integer);
+begin
+  inherited Create;
+  FReader := TStreamReader.Create(TFileStream.Create(AFileName, AMode, ARights),
+    ABufferSize, True);
+end;
+
+constructor TFileReader.Create(const AFileName: TFileName; AMode: Word;
+  ABufferSize: Integer);
+begin
+  Create(AFileName, AMode, FILE_RIGHTS, ABufferSize);
+end;
+
+constructor TFileReader.Create(const AFileName: TFileName; ABufferSize: Integer);
+begin
+  Create(AFileName, fmOpenRead or fmShareDenyWrite, ABufferSize);
+end;
+
+constructor TFileReader.Create(const AFileName: TFileName);
+begin
+  Create(AFileName, BUFFER_SIZE);
+end;
+
+destructor TFileReader.Destroy;
+begin
+  FReader.Free;
+  inherited Destroy;
+end;
+
+procedure TFileReader.Reset;
+begin
+  FReader.Reset;
+end;
+
+procedure TFileReader.Close;
+begin
+  FReader.Close;
+end;
+
+function TFileReader.IsEof: Boolean;
+begin
+  Result := FReader.IsEof;
+end;
+
+procedure TFileReader.ReadLine(out AString: string);
+begin
+  FReader.ReadLine(AString);
+end;
+
+function TFileReader.ReadLine: string;
+begin
+  ReadLine(Result);
+end;
+
+end.
+
-- 
1.9.5.msysgit.0

Zeljan Rikalo

2015-05-12 08:41

reporter   ~0083573

Someone should change project to fpc.

silvioprog

2015-05-12 16:34

reporter   ~0083580

Oops, sorry Zeljan! ^^'

Thanks Maxim!

Marco van de Voort

2015-05-12 18:49

manager   ~0083581

I would give TStreamReader a different name. It is a too general name for a text specific class.

silvioprog

2015-05-14 17:08

reporter   ~0083604

It is just for Delphi compatibility, that uses this same name: http://picpaste.com/pics/sr-2hgqvYSu.1431615815.png.

Marco van de Voort

2015-05-14 17:38

manager   ~0083605

Then of course I said nothing :-)

silvioprog

2015-05-15 16:35

reporter   ~0083621

Hehehe =D

Michael Van Canneyt

2015-06-10 23:39

administrator   ~0084357

Applied, thank you very much!

silvioprog

2015-06-11 18:12

reporter   ~0084368

Thanks buddies! (y)

Issue History

Date Modified Username Field Change
2015-05-12 07:24 silvioprog New Issue
2015-05-12 07:24 silvioprog File Added: 0001-add-SParamIsNil-patch-by-silvioprog.patch
2015-05-12 07:24 silvioprog File Added: 0001-add-TTextReader-TStreamReader-TStringReader-TFileRea.patch
2015-05-12 07:25 silvioprog Note Added: 0083571
2015-05-12 07:25 silvioprog File Added: 0001-Fix-Converting-the-operands-to-Int64-.-hints-patch-b.patch
2015-05-12 07:28 silvioprog Note Added: 0083572
2015-05-12 07:28 silvioprog File Added: ALTERNATIVE-0001-add-TextReader-unit-patch-by-silvioprog.patch
2015-05-12 08:41 Zeljan Rikalo Note Added: 0083573
2015-05-12 13:44 Maxim Ganetsky Project Lazarus => FPC
2015-05-12 16:34 silvioprog Note Added: 0083580
2015-05-12 18:49 Marco van de Voort Note Added: 0083581
2015-05-14 17:08 silvioprog Note Added: 0083604
2015-05-14 17:38 Marco van de Voort Note Added: 0083605
2015-05-15 16:35 silvioprog Note Added: 0083621
2015-05-22 15:54 Michael Van Canneyt Assigned To => Michael Van Canneyt
2015-05-22 15:54 Michael Van Canneyt Status new => assigned
2015-06-10 23:39 Michael Van Canneyt Fixed in Revision => 31022
2015-06-10 23:39 Michael Van Canneyt Note Added: 0084357
2015-06-10 23:39 Michael Van Canneyt Status assigned => resolved
2015-06-10 23:39 Michael Van Canneyt Fixed in Version => 3.1.1
2015-06-10 23:39 Michael Van Canneyt Resolution open => fixed
2015-06-10 23:39 Michael Van Canneyt Target Version => 4.0.0
2015-06-11 18:12 silvioprog Note Added: 0084368
2015-06-11 18:12 silvioprog Status resolved => closed
2015-08-30 22:35 Joost van der Sluis Fixed in Version 3.1.1 => 3.0.1