This file is indexed.

/usr/lib/lazarus/0.9.30.4/lcl/extendedstrings.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{
 /***************************************************************************
                             extendedstrings.pas
                             -------------------

 ***************************************************************************/

 *****************************************************************************
 *                                                                           *
 *  This file is part of the Lazarus Component Library (LCL)                 *
 *                                                                           *
 *  See the file COPYING.modifiedLGPL.txt, 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.                     *
 *                                                                           *
 *****************************************************************************

  Author: Mattias: Gaertner
  
  TExtendedStrings is a normal TStringList, except that the Objects can hold
  any type of records.
}
unit ExtendedStrings;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;
  
type
  TExtStringsOption = (
    esoClearRecordsOnCreate,
    esoFreeObjectsOnDelete
    );
  TExtStringsOptions = set of TExtStringsOption;

  TExtendedStringList = class(TStringList)
  private
    FOptions: TExtStringsOptions;
    FRecordSize: integer;
    function GetRecords(Index: integer): pointer;
    procedure SetOptions(const AValue: TExtStringsOptions);
    procedure SetRecords(Index: integer; const AValue: pointer);
    procedure SetRecordSize(const AValue: integer);
    procedure DoResizeRecord(Index, OldSize, NewSize: integer);
  protected
    procedure ResizeRecord(var ARecord: Pointer;
                           Index, OldSize, NewSize: integer); virtual;
    function GetObject(Index: Integer): TObject; override;
    procedure PutObject(Index: Integer; AnObject: TObject); override;
  public
    constructor Create(InitialRecordSize: integer);
    destructor Destroy; override;
    procedure Clear; override;
    procedure Delete(Index: Integer); override;
    procedure CreateRecord(Index: integer); virtual;
    procedure FreeRecord(Index: integer); virtual;
    procedure FreeAllRecords; virtual;
    function RecordAllocated(Index: integer): boolean;
    property Records[Index: integer]: pointer read GetRecords write SetRecords;
    property RecordSize: integer read FRecordSize write SetRecordSize;
    property Options: TExtStringsOptions read FOptions write SetOptions;
  end;

implementation

{ TExtendedStringList }

function TExtendedStringList.GetRecords(Index: integer): pointer;
begin
  if not RecordAllocated(Index) then CreateRecord(Index);
  Result:=inherited GetObject(Index);
end;

procedure TExtendedStringList.SetOptions(const AValue: TExtStringsOptions);
begin
  if FOptions=AValue then exit;
  FOptions:=AValue;
end;

procedure TExtendedStringList.SetRecords(Index: integer; const AValue: pointer);
begin
  FreeRecord(Index);
  inherited PutObject(Index,TObject(AValue));
end;

procedure TExtendedStringList.SetRecordSize(const AValue: integer);
var
  i: integer;
begin
  if FRecordSize=AValue then exit;
  for i:=0 to Count-1 do
    DoResizeRecord(i,FRecordSize,AValue);
  FRecordSize:=AValue;
end;

procedure TExtendedStringList.DoResizeRecord(Index, OldSize, NewSize: integer);
var
  CurRecord: Pointer;
begin
  CurRecord:=inherited GetObject(Index);
  if CurRecord=nil then exit;
  ResizeRecord(CurRecord,Index,OldSize,NewSize);
  inherited PutObject(Index,TObject(CurRecord));
end;

procedure TExtendedStringList.CreateRecord(Index: integer);
var
  NewRecord: Pointer;
begin
  GetMem(NewRecord,RecordSize);
  if (esoClearRecordsOnCreate in Options) then
    FillChar(NewRecord^,RecordSize,0);
  inherited PutObject(Index,TObject(NewRecord));
end;

procedure TExtendedStringList.FreeRecord(Index: integer);
var
  OldRecord: pointer;
  OldObject: TObject;
begin
  OldRecord:=inherited GetObject(Index);
  if OldRecord<>nil then begin
    if (esoFreeObjectsOnDelete in Options) then begin
      OldObject:=Objects[Index];
      if OldObject<>nil then begin
        OldObject.Free;
      end;
    end;
    FreeMem(OldRecord);
    inherited PutObject(Index,nil);
  end;
end;

procedure TExtendedStringList.FreeAllRecords;
var
  i: integer;
begin
  for i:=0 to Count-1 do
    FreeRecord(i);
end;

function TExtendedStringList.RecordAllocated(Index: integer): boolean;
begin
  Result:=(inherited GetObject(Index))<>nil;
end;

procedure TExtendedStringList.ResizeRecord(var ARecord: Pointer; Index, OldSize,
  NewSize: integer);
begin
  ReAllocMem(ARecord,NewSize);
end;

function TExtendedStringList.GetObject(Index: Integer): TObject;
var
  ARecord: Pointer;
begin
  ARecord:=inherited GetObject(Index);
  if ARecord<>nil then
    Result:=TObject(ARecord^)
  else
    Result:=nil;
end;

procedure TExtendedStringList.PutObject(Index: Integer; AnObject: TObject);
var
  ARecord: Pointer;
begin
  ARecord:=Records[Index];
  if ARecord=nil then
  begin
    CreateRecord(Index);
    ARecord:=Records[Index];
  end;
  TObject(ARecord^):=AnObject;
end;

constructor TExtendedStringList.Create(InitialRecordSize: integer);
begin
  inherited Create;
  FOptions:=[esoClearRecordsOnCreate];
  FRecordSize:=InitialRecordSize;
end;

destructor TExtendedStringList.Destroy;
begin
  FreeAllRecords;
  inherited Destroy;
end;

procedure TExtendedStringList.Clear;
begin
  FreeAllRecords;
  inherited Clear;
end;

procedure TExtendedStringList.Delete(Index: Integer);
begin
  FreeRecord(Index);
  inherited Delete(Index);
end;

end.