Changeset 447 for trunk/Packages/CevoComponents/StringTables.pas
- Timestamp:
- May 19, 2022, 10:39:34 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/CevoComponents/StringTables.pas
r300 r447 16 16 constructor Create; 17 17 destructor Destroy; override; 18 function LoadFromFile(const FileName: String): boolean;19 function GetHandle(const Item: string): integer;20 function LookupByHandle(Handle: integer; Index: integer = -1): string;18 function LoadFromFile(const FileName: String): Boolean; 19 function GetHandle(const Item: string): Integer; 20 function LookupByHandle(Handle: Integer; Index: Integer = -1): string; 21 21 function Lookup(const Item: string; Index: Integer = -1): string; 22 function Search(const Content: string; var Handle, Index: integer): boolean;22 function Search(const Content: string; var Handle, Index: Integer): Boolean; 23 23 end; 24 24 … … 45 45 end; 46 46 47 function TStringTable.LoadFromFile(const FileName: String): boolean;47 function TStringTable.LoadFromFile(const FileName: String): Boolean; 48 48 begin 49 49 Result := True; … … 56 56 end; 57 57 58 function TStringTable.GetHandle(const Item: string): integer;58 function TStringTable.GetHandle(const Item: string): Integer; 59 59 var 60 60 I: Integer; … … 67 67 end; 68 68 69 function TStringTable.LookupByHandle(Handle: integer; Index: integer): string;69 function TStringTable.LookupByHandle(Handle: Integer; Index: Integer): string; 70 70 var 71 s: string;71 S: string; 72 72 begin 73 73 if Index < 0 then begin … … 77 77 end else begin 78 78 if Pos(' ', Lines[Handle]) = 0 then S := '' 79 else s:= Copy(Lines[Handle], Pos(' ', Lines[Handle]) + 1, MaxInt);79 else S := Copy(Lines[Handle], Pos(' ', Lines[Handle]) + 1, MaxInt); 80 80 while ((Handle + 1) < Lines.Count) and (Copy(Lines[Handle + 1], 1, 1) <> '#') do begin 81 81 Inc(Handle); 82 82 if (Length(Lines[Handle]) > 0) and (Lines[Handle][1] <> '''') then begin 83 if ( s <> '') and (s[Length(s)] <> '\') then84 s := s+ ' ';85 s := s+ Lines[Handle];83 if (S <> '') and (S[Length(S)] <> '\') then 84 S := S + ' '; 85 S := S + Lines[Handle]; 86 86 end; 87 87 end; … … 116 116 { might become necessary for 1.3 117 117 118 function TStringTable.Lookup(const Fallback: TStringTable; const Item: string; Index: integer): string;118 function TStringTable.Lookup(const Fallback: TStringTable; const Item: string; Index: Integer): string; 119 119 var 120 Handle: integer;120 Handle: Integer; 121 121 begin 122 122 Handle:=Gethandle(Item); 123 if Handle>=0 then result:=LookupByHandle(Handle, Index)124 else result:='';125 if result='' then126 result:=Fallback.Lookup(Item, Index);123 if Handle>=0 then Result:=LookupByHandle(Handle, Index) 124 else Result:=''; 125 if Result='' then 126 Result:=Fallback.Lookup(Item, Index); 127 127 end; 128 128 129 function TStringTable.TryLookup(const Item: string; Index: integer): string;129 function TStringTable.TryLookup(const Item: string; Index: Integer): string; 130 130 var 131 Handle: integer;131 Handle: Integer; 132 132 begin 133 133 Handle:=Gethandle(Item); 134 if Handle>=0 then result:=LookupByHandle(Handle, Index)135 else result:='';134 if Handle>=0 then Result:=LookupByHandle(Handle, Index) 135 else Result:=''; 136 136 end; } 137 137 138 138 function TStringTable.Search(const Content: string; 139 var Handle, Index: integer): boolean;139 var Handle, Index: Integer): Boolean; 140 140 var 141 h, i: integer;141 H, I: Integer; 142 142 UContent: string; 143 143 begin 144 144 UContent := UpperCase(Content); 145 h:= Handle;146 if h< 0 then147 i:= 0145 H := Handle; 146 if H < 0 then 147 I := 0 148 148 else 149 i:= Index + 1;149 I := Index + 1; 150 150 repeat 151 if h + i+ 1 >= Lines.Count then151 if H + I + 1 >= Lines.Count then 152 152 begin 153 result := false;154 exit;153 Result := False; 154 Exit; 155 155 end; 156 if Copy(Lines[ h + i+ 1], 1, 1) = '#' then156 if Copy(Lines[H + I + 1], 1, 1) = '#' then 157 157 begin 158 h := h + i+ 1;159 i:= -1;158 H := H + I + 1; 159 I := -1; 160 160 end; 161 if ( h >= 0) and not ((Length(Lines[h + i + 1]) > 0) and (Lines[h + i+ 1][1] in ['#', ':', ';'])) and162 (Pos(UContent, UpperCase(Lines[ h + i+ 1])) > 0) then161 if (H >= 0) and not ((Length(Lines[H + I + 1]) > 0) and (Lines[H + I + 1][1] in ['#', ':', ';'])) and 162 (Pos(UContent, UpperCase(Lines[H + I + 1])) > 0) then 163 163 begin 164 Index := i;165 Handle := h;164 Index := I; 165 Handle := H; 166 166 Result := True; 167 167 Exit;
Note:
See TracChangeset
for help on using the changeset viewer.